|
@ -56,18 +56,11 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui |
|
|
while (size--) { |
|
|
while (size--) { |
|
|
uint8_t * const p = (uint8_t * const)pos; |
|
|
uint8_t * const p = (uint8_t * const)pos; |
|
|
uint8_t v = *value; |
|
|
uint8_t v = *value; |
|
|
uint8_t r_val; |
|
|
// EEPROM has only ~100,000 write cycles,
|
|
|
|
|
|
// so only write bytes that have changed!
|
|
|
DEBUG("Write to : %d val: %0X",pos,v); |
|
|
if (v != eeprom_read_byte(p)) { |
|
|
r_val=eeprom_read_byte((uint16_t *)p); |
|
|
eeprom_write_byte(p, v); |
|
|
|
|
|
if (eeprom_read_byte(p) != v) { |
|
|
if (v != r_val) { |
|
|
|
|
|
DEBUG("Read val: %0X To write val: %0X",r_val,v); |
|
|
|
|
|
eeprom_write_byte((uint16_t *)p, v); |
|
|
|
|
|
r_val=eeprom_read_byte((uint16_t *)p); |
|
|
|
|
|
DEBUG("Read back val: %0X",r_val); |
|
|
|
|
|
if (r_val != v) { |
|
|
|
|
|
ERROR("Write error"); |
|
|
|
|
|
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); |
|
|
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
@ -81,8 +74,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui |
|
|
|
|
|
|
|
|
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { |
|
|
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { |
|
|
do { |
|
|
do { |
|
|
DEBUG("Read form: %d",pos); |
|
|
uint8_t c = eeprom_read_byte((uint8_t*)pos); |
|
|
uint8_t c = eeprom_read_byte((uint16_t*)pos); |
|
|
|
|
|
if (writing && value) *value = c; |
|
|
if (writing && value) *value = c; |
|
|
crc16(crc, &c, 1); |
|
|
crc16(crc, &c, 1); |
|
|
pos++; |
|
|
pos++; |
|
|