We have to erase the log before the flight starts, so this seems like
the latest possible moment.
Signed-off-by: Keith Packard <keithp@keithp.com>
return 330 * stm_cal.vrefint_cal / vrefint;
}
return 330 * stm_cal.vrefint_cal / vrefint;
}
+static void
+ao_log_erase(void)
+{
+ uint32_t pos;
+ for (pos = 0; pos < ao_storage_log_max; pos += ao_storage_block)
+ ao_storage_erase(pos);
+}
#if BOOST_DELAY
ao_delay(BOOST_DELAY);
#endif
#if BOOST_DELAY
ao_delay(BOOST_DELAY);
#endif
/* Look for the flight log matching the requested flight */
if (cmd_flight == 1 && ao_log_present()) {
/* Look for the flight log matching the requested flight */
if (cmd_flight == 1 && ao_log_present()) {
- uint32_t pos;
- for (pos = 0; pos < ao_storage_log_max; pos += ao_storage_block)
- ao_storage_erase(pos);
puts("Erased");
return;
}
puts("Erased");
return;
}
stm_flash.cr &= ~(1 << STM_FLASH_CR_PG);
}
stm_flash.cr &= ~(1 << STM_FLASH_CR_PG);
}
+static bool
+ao_storage_is_erased(uint32_t pos)
+{
+ uint16_t *flash = _ao_flash_addr(pos);
+ uint32_t i = ao_storage_block >> 1;
+
+ while (i--)
+ if (*flash++ != 0xffff)
+ return false;
+ return true;
+}
+
uint8_t
ao_storage_erase(uint32_t pos)
{
uint8_t
ao_storage_erase(uint32_t pos)
{
+ if (ao_storage_is_erased(pos))
+ return 1;
+
ao_arch_block_interrupts();
ao_flash_unlock();
ao_arch_block_interrupts();
ao_flash_unlock();