From 3c9d45d7d0310c07b0767bc33adba2bc78bc805f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Jun 2013 13:33:41 +1000 Subject: [PATCH] HAL_AVR: avoid writing bytes to EEPROM that are already correct this speeds up writing of waypoint data, reducing latency --- libraries/AP_HAL_AVR/Storage.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libraries/AP_HAL_AVR/Storage.cpp b/libraries/AP_HAL_AVR/Storage.cpp index 8f630ddff8..1670c4ff8b 100644 --- a/libraries/AP_HAL_AVR/Storage.cpp +++ b/libraries/AP_HAL_AVR/Storage.cpp @@ -23,19 +23,25 @@ void AVREEPROMStorage::read_block(void *dst, uint16_t src, size_t n) { } void AVREEPROMStorage::write_byte(uint16_t loc, uint8_t value) { - eeprom_write_byte((uint8_t*)loc,value); + uint8_t b = eeprom_read_byte((uint8_t*)loc); + if (b != value) { + eeprom_write_byte((uint8_t*)loc, value); + } } void AVREEPROMStorage::write_word(uint16_t loc, uint16_t value) { - eeprom_write_word((uint16_t*)loc,value); + write_block(loc, &value, sizeof(value)); } void AVREEPROMStorage::write_dword(uint16_t loc, uint32_t value) { - eeprom_write_dword((uint32_t*)loc,value); + write_block(loc, &value, sizeof(value)); } void AVREEPROMStorage::write_block(uint16_t dst, void *src, size_t n) { - eeprom_write_block(src,(void*)dst,n); + uint8_t *p = (uint8_t *)src; + while (n--) { + write_byte(dst++, *p++); + } } #endif