diff options
Diffstat (limited to 'drivers/eeprom/eeprom_i2c.c')
-rw-r--r-- | drivers/eeprom/eeprom_i2c.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/drivers/eeprom/eeprom_i2c.c b/drivers/eeprom/eeprom_i2c.c index 03dbc5e516..88be2be06f 100644 --- a/drivers/eeprom/eeprom_i2c.c +++ b/drivers/eeprom/eeprom_i2c.c @@ -50,7 +50,7 @@ static inline void init_i2c_if_required(void) { } static inline void fill_target_address(uint8_t *buffer, const void *addr) { - intptr_t p = (intptr_t)addr; + uintptr_t p = (uintptr_t)addr; for (int i = 0; i < EXTERNAL_EEPROM_ADDRESS_SIZE; ++i) { buffer[EXTERNAL_EEPROM_ADDRESS_SIZE - 1 - i] = p & 0xFF; p >>= 8; @@ -60,11 +60,19 @@ static inline void fill_target_address(uint8_t *buffer, const void *addr) { void eeprom_driver_init(void) {} void eeprom_driver_erase(void) { +#ifdef CONSOLE_ENABLE + uint32_t start = timer_read32(); +#endif + uint8_t buf[EXTERNAL_EEPROM_PAGE_SIZE]; memset(buf, 0x00, EXTERNAL_EEPROM_PAGE_SIZE); - for (intptr_t addr = 0; addr < EXTERNAL_EEPROM_BYTE_COUNT; addr += EXTERNAL_EEPROM_PAGE_SIZE) { - eeprom_write_block(buf, (void *)addr, EXTERNAL_EEPROM_PAGE_SIZE); + for (uint32_t addr = 0; addr < EXTERNAL_EEPROM_BYTE_COUNT; addr += EXTERNAL_EEPROM_PAGE_SIZE) { + eeprom_write_block(buf, (void *)(uintptr_t)addr, EXTERNAL_EEPROM_PAGE_SIZE); } + +#ifdef CONSOLE_ENABLE + dprintf("EEPROM erase took %ldms to complete\n", ((long)(timer_read32() - start))); +#endif } void eeprom_read_block(void *buf, const void *addr, size_t len) { @@ -72,8 +80,8 @@ void eeprom_read_block(void *buf, const void *addr, size_t len) { fill_target_address(complete_packet, addr); init_i2c_if_required(); - i2c_transmit(EXTERNAL_EEPROM_I2C_ADDRESS((intptr_t)addr), complete_packet, EXTERNAL_EEPROM_ADDRESS_SIZE, 100); - i2c_receive(EXTERNAL_EEPROM_I2C_ADDRESS((intptr_t)addr), buf, len, 100); + i2c_transmit(EXTERNAL_EEPROM_I2C_ADDRESS((uintptr_t)addr), complete_packet, EXTERNAL_EEPROM_ADDRESS_SIZE, 100); + i2c_receive(EXTERNAL_EEPROM_I2C_ADDRESS((uintptr_t)addr), buf, len, 100); #ifdef DEBUG_EEPROM_OUTPUT dprintf("[EEPROM R] 0x%04X: ", ((int)addr)); @@ -85,14 +93,14 @@ void eeprom_read_block(void *buf, const void *addr, size_t len) { } void eeprom_write_block(const void *buf, void *addr, size_t len) { - uint8_t complete_packet[EXTERNAL_EEPROM_ADDRESS_SIZE + EXTERNAL_EEPROM_PAGE_SIZE]; - uint8_t *read_buf = (uint8_t *)buf; - intptr_t target_addr = (intptr_t)addr; + uint8_t complete_packet[EXTERNAL_EEPROM_ADDRESS_SIZE + EXTERNAL_EEPROM_PAGE_SIZE]; + uint8_t * read_buf = (uint8_t *)buf; + uintptr_t target_addr = (uintptr_t)addr; init_i2c_if_required(); while (len > 0) { - intptr_t page_offset = target_addr % EXTERNAL_EEPROM_PAGE_SIZE; - int write_length = EXTERNAL_EEPROM_PAGE_SIZE - page_offset; + uintptr_t page_offset = target_addr % EXTERNAL_EEPROM_PAGE_SIZE; + int write_length = EXTERNAL_EEPROM_PAGE_SIZE - page_offset; if (write_length > len) { write_length = len; } @@ -110,7 +118,7 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) { dprintf("\n"); #endif // DEBUG_EEPROM_OUTPUT - i2c_transmit(EXTERNAL_EEPROM_I2C_ADDRESS((intptr_t)addr), complete_packet, EXTERNAL_EEPROM_ADDRESS_SIZE + write_length, 100); + i2c_transmit(EXTERNAL_EEPROM_I2C_ADDRESS((uintptr_t)addr), complete_packet, EXTERNAL_EEPROM_ADDRESS_SIZE + write_length, 100); wait_ms(EXTERNAL_EEPROM_WRITE_TIME); read_buf += write_length; |