EEPROM simplification. Needs tests. (#3713)

This commit is contained in:
Bertrand Songis
2016-08-23 07:14:44 +02:00
committed by GitHub
parent c16ad94e3a
commit 0ff601a3fa
28 changed files with 485 additions and 480 deletions
+9 -2
View File
@@ -427,9 +427,16 @@ void usbSerialPutc(uint8_t c);
#endif
// I2C driver: EEPROM + Audio Volume
#if defined(REV4a)
#define EEPROM_SIZE (64*1024)
#else
#define EEPROM_SIZE (32*1024)
#endif
void i2cInit(void);
void eepromReadBlock(uint8_t * buffer, uint32_t address, uint32_t size);
void eepromWriteBlock(uint8_t * buffer, uint32_t address, uint32_t size);
void eepromReadBlock(uint8_t * buffer, size_t address, size_t size);
void eepromStartWrite(uint8_t * buffer, size_t address, size_t size);
uint8_t eepromIsTransferComplete();
// Debug driver
void debugPutc(const char c);
@@ -594,7 +594,7 @@ int main()
else {
writeEepromBlock();
eepromWritten += sizeof(Block_buffer);
progress = (200*eepromWritten) / EESIZE;
progress = (200*eepromWritten) / EEPROM_SIZE;
}
lcdDrawRect( 3, 6*FH+4, 204, 7);
@@ -609,7 +609,7 @@ int main()
if (firmwareWritten >= FLASHSIZE - BOOTLOADER_SIZE) {
state = ST_FLASH_DONE; // Backstop
}
if (eepromWritten >= EESIZE) {
if (eepromWritten >= EEPROM_SIZE) {
state = ST_FLASH_DONE; // Backstop
}
}
+20 -15
View File
@@ -130,41 +130,46 @@ bool I2C_EE_ReadBlock(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRea
return true;
}
void eepromReadBlock(uint8_t* pBuffer, uint32_t ReadAddr, uint32_t NumByteToRead)
void eepromReadBlock(uint8_t * buffer, size_t address, size_t size)
{
while (!I2C_EE_ReadBlock(pBuffer, ReadAddr, NumByteToRead)) {
while (!I2C_EE_ReadBlock(buffer, address, size)) {
i2cInit();
}
}
/**
* @brief Writes buffer of data to the I2C EEPROM.
* @param pBuffer : pointer to the buffer containing the data to be
* @param buffer : pointer to the buffer containing the data to be
* written to the EEPROM.
* @param WriteAddr : EEPROM's internal address to write to.
* @param NumByteToWrite : number of bytes to write to the EEPROM.
* @param address : EEPROM's internal address to write to.
* @param size : number of bytes to write to the EEPROM.
* @retval None
*/
void eepromWriteBlock(uint8_t* pBuffer, uint32_t WriteAddr, uint32_t NumByteToWrite)
void eepromWriteBlock(uint8_t * buffer, size_t address, size_t size)
{
uint8_t offset = WriteAddr % I2C_FLASH_PAGESIZE;
uint8_t offset = address % I2C_FLASH_PAGESIZE;
uint8_t count = I2C_FLASH_PAGESIZE - offset;
if (NumByteToWrite < count) {
count = NumByteToWrite;
if (size < count) {
count = size;
}
while (count > 0) {
eepromPageWrite(pBuffer, WriteAddr, count);
eepromPageWrite(buffer, address, count);
eepromWaitEepromStandbyState();
WriteAddr += count;
pBuffer += count;
NumByteToWrite -= count;
address += count;
buffer += count;
size -= count;
count = I2C_FLASH_PAGESIZE;
if (NumByteToWrite < I2C_FLASH_PAGESIZE) {
count = NumByteToWrite;
if (size < I2C_FLASH_PAGESIZE) {
count = size;
}
}
}
uint8_t eepromIsTransferComplete()
{
return 1;
}
/**
* @brief Writes more than one byte to the EEPROM with a single WRITE cycle.
* @note The number of byte can't exceed the EEPROM page size.