altos/micropeak-v2: Erase log space at end of BOOST_DELAY
[fw/altos] / src / stmf0 / ao_storage_stm.c
index 1a6198a79308cd66808629ec999521113ed3c2b6..c6f1defe8e67b3f8efe97a3424804e9eac470126 100644 (file)
@@ -127,9 +127,24 @@ _ao_flash_write(uint32_t pos, void *sv, uint16_t len)
        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();
 
@@ -157,7 +172,7 @@ ao_storage_device_write(uint32_t pos, void *v, uint16_t len)
 }
 
 uint8_t
 }
 
 uint8_t
-ao_storage_device_read(uint32_t pos, __xdata void *d, uint16_t len) __reentrant
+ao_storage_device_read(uint32_t pos, void *d, uint16_t len) 
 {
        if (pos >= ao_storage_total || pos + len > ao_storage_total)
                return 0;
 {
        if (pos >= ao_storage_total || pos + len > ao_storage_total)
                return 0;
@@ -166,7 +181,7 @@ ao_storage_device_read(uint32_t pos, __xdata void *d, uint16_t len) __reentrant
 }
 
 void
 }
 
 void
-ao_storage_flush(void) __reentrant
+ao_storage_flush(void) 
 {
 }
 
 {
 }
 
@@ -179,7 +194,7 @@ ao_storage_setup(void)
 }
 
 void
 }
 
 void
-ao_storage_device_info(void) __reentrant
+ao_storage_device_info(void) 
 {
        printf ("Using internal flash, page %d bytes, total %d bytes\n",
                ao_storage_block, ao_storage_total);
 {
        printf ("Using internal flash, page %d bytes, total %d bytes\n",
                ao_storage_block, ao_storage_total);