diff options
author | Damien <damien.p.george@gmail.com> | 2013-12-11 00:38:40 +0000 |
---|---|---|
committer | Damien <damien.p.george@gmail.com> | 2013-12-11 00:38:40 +0000 |
commit | ec643130d0c49ee4b510f9a909da75d9fdb5454b (patch) | |
tree | 2cce84a3578b5bbafe8394e4490147fa2075598c | |
parent | 318aec6ba984e6c559401fd99fef4f1a9c327417 (diff) | |
download | micropython-ec643130d0c49ee4b510f9a909da75d9fdb5454b.tar.gz micropython-ec643130d0c49ee4b510f9a909da75d9fdb5454b.zip |
stm: add timer to storage cache so it can be flushed.
-rw-r--r-- | stm/storage.c | 9 | ||||
-rw-r--r-- | stm/storage.h | 1 |
2 files changed, 10 insertions, 0 deletions
diff --git a/stm/storage.c b/stm/storage.c index 769abde69f..ac0458d136 100644 --- a/stm/storage.c +++ b/stm/storage.c @@ -2,6 +2,7 @@ #include "std.h" #include "misc.h" +#include "systick.h" #include "led.h" #include "flash.h" #include "storage.h" @@ -17,6 +18,7 @@ static uint32_t cache_flash_sector_id; static uint32_t cache_flash_sector_start; static uint32_t cache_flash_sector_size; static bool cache_dirty; +static uint32_t sys_tick_counter_last_write; static void cache_flush(void) { if (cache_dirty) { @@ -50,6 +52,7 @@ void storage_init(void) { cache_flash_sector_id = 0; cache_dirty = false; is_initialised = true; + sys_tick_counter_last_write = 0; } } @@ -61,6 +64,11 @@ uint32_t storage_get_block_count(void) { return FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS; } +bool storage_needs_flush(void) { + // wait 2 seconds after last write to flush + return cache_dirty && sys_tick_has_passed(sys_tick_counter_last_write, 2000); +} + void storage_flush(void) { cache_flush(); } @@ -143,6 +151,7 @@ bool storage_write_block(const uint8_t *src, uint32_t block) { uint32_t flash_addr = FLASH_MEM_START_ADDR + (block - FLASH_PART1_START_BLOCK) * BLOCK_SIZE; uint8_t *dest = cache_get_addr_for_write(flash_addr); memcpy(dest, src, BLOCK_SIZE); + sys_tick_counter_last_write = sys_tick_counter; return true; } else { diff --git a/stm/storage.h b/stm/storage.h index 8a8459c9ee..fe37e8b27c 100644 --- a/stm/storage.h +++ b/stm/storage.h @@ -1,6 +1,7 @@ void storage_init(void); uint32_t storage_get_block_size(void); uint32_t storage_get_block_count(void); +bool storage_needs_flush(void); void storage_flush(void); bool storage_read_block(uint8_t *dest, uint32_t block); bool storage_write_block(const uint8_t *src, uint32_t block); |