summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/micropeak-v2.0/ao_micropeak.c12
-rw-r--r--src/stmf0/ao_storage_stm.c15
2 files changed, 24 insertions, 3 deletions
diff --git a/src/micropeak-v2.0/ao_micropeak.c b/src/micropeak-v2.0/ao_micropeak.c
index dd86ba1c..0b9972e9 100644
--- a/src/micropeak-v2.0/ao_micropeak.c
+++ b/src/micropeak-v2.0/ao_micropeak.c
@@ -164,6 +164,13 @@ ao_battery_voltage(void)
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);
+}
uint8_t ao_on_battery;
@@ -186,6 +193,7 @@ ao_micropeak(void)
#if BOOST_DELAY
ao_delay(BOOST_DELAY);
#endif
+ ao_log_erase();
ao_microflight();
@@ -239,9 +247,7 @@ ao_log_delete(void)
/* 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);
+ ao_log_erase();
puts("Erased");
return;
}
diff --git a/src/stmf0/ao_storage_stm.c b/src/stmf0/ao_storage_stm.c
index 17c934a5..c6f1defe 100644
--- a/src/stmf0/ao_storage_stm.c
+++ b/src/stmf0/ao_storage_stm.c
@@ -127,9 +127,24 @@ _ao_flash_write(uint32_t pos, void *sv, uint16_t len)
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)
{
+ if (ao_storage_is_erased(pos))
+ return 1;
+
ao_arch_block_interrupts();
ao_flash_unlock();