altos: Clear out eeprom erase records when writing entry 0
authorKeith Packard <keithp@keithp.com>
Sat, 7 Jun 2014 17:54:14 +0000 (10:54 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 7 Jun 2014 17:54:14 +0000 (10:54 -0700)
When writing config/erase to eeprom, there's no 'erase' operation as
on-chip eeprom is writable at a byte level. As such, we can't tell
when the erase blocks get reset when the config gets written. When
this happens, erase block 0 gets written explicitly, so just use that
call to trigger explicit erasing of the data.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/kernel/ao_log.c

index 76e0e68c56c89a3286a5f53500210f709b4ef497..3cf85a334f704b00375d6adac45410c972645642 100644 (file)
@@ -67,6 +67,18 @@ ao_log_write_erase(uint8_t pos)
        erase.mark = LOG_ERASE_MARK;
        erase.flight = ao_flight_number;
        ao_config_write(ao_log_erase_pos(pos),  &erase, sizeof (erase));
+
+#if USE_EEPROM_CONFIG
+       if (pos == 0) {
+               uint8_t i;
+               for (i = 1; i < LOG_MAX_ERASE; i++) {
+                       erase.mark = ~LOG_ERASE_MARK;
+                       erase.flight = 0;
+                       ao_config_write(ao_log_erase_pos(i), &erase, sizeof (erase));
+               }
+       }
+#endif
+
        ao_config_flush();
 }