Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[fw/altos] / src / stm32l0 / ao_flash_stm32l0.c
index 68c21c825c9abbcc985dafed7fb1a813731c61f8..521c5c0cfbb95d56317440c6c7be6bb55a0c5cde 100644 (file)
@@ -132,11 +132,6 @@ ao_flash_page(uint32_t *page, uint32_t *src)
 }
 #endif
 
-void
-ao_storage_setup(void)
-{
-}
-
 static ao_pos_t        write_pos;
 static uint8_t write_pending;
 static union {
@@ -191,7 +186,7 @@ ao_storage_device_write(ao_pos_t pos, void *buf, uint16_t len)
                flash_write_select(this_pos);
 
                /* Update write buffer with new contents */
-               int this_word = 4 - (pos & 3);
+               uint16_t this_word = 4 - (pos & 3);
                if (this_word > len)
                        this_word = len;
                memcpy(&write_buf.u8[pos & 3], b8, this_word);
@@ -210,23 +205,22 @@ ao_storage_device_write(ao_pos_t pos, void *buf, uint16_t len)
        return 1;
 }
 
-/* Erase device from pos through pos + ao_storage_block */
-uint8_t
-ao_storage_device_erase(uint32_t pos)
+bool
+ao_storage_device_is_erased(uint32_t pos)
 {
-       ao_flash_erase_page(__storage + pos);
-       return 1;
-}
+       uint8_t *m = ((uint8_t *) __storage) + pos;
+       uint32_t i;
 
-/* Initialize low-level device bits */
-void
-ao_storage_device_init(void)
-{
+       for (i = 0; i < STM_FLASH_PAGE_SIZE; i++)
+               if (*m++ != AO_STORAGE_ERASED_BYTE)
+                       return false;
+       return true;
 }
 
-/* Print out information about flash chips */
-void
-ao_storage_device_info(void)
+/* Erase device from pos through pos + ao_storage_block */
+uint8_t
+ao_storage_device_erase(uint32_t pos)
 {
-       printf("Detected chips 1 size %d\n", ao_storage_total);
+       ao_flash_erase_page(__storage + (pos >> 2));
+       return 1;
 }