File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change 2
2
#include "std.h"
3
3
4
4
#include "misc.h"
5
+ #include "systick.h"
5
6
#include "led.h"
6
7
#include "flash.h"
7
8
#include "storage.h"
@@ -17,6 +18,7 @@ static uint32_t cache_flash_sector_id;
17
18
static uint32_t cache_flash_sector_start ;
18
19
static uint32_t cache_flash_sector_size ;
19
20
static bool cache_dirty ;
21
+ static uint32_t sys_tick_counter_last_write ;
20
22
21
23
static void cache_flush (void ) {
22
24
if (cache_dirty ) {
@@ -50,6 +52,7 @@ void storage_init(void) {
50
52
cache_flash_sector_id = 0 ;
51
53
cache_dirty = false;
52
54
is_initialised = true;
55
+ sys_tick_counter_last_write = 0 ;
53
56
}
54
57
}
55
58
@@ -61,6 +64,11 @@ uint32_t storage_get_block_count(void) {
61
64
return FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS ;
62
65
}
63
66
67
+ bool storage_needs_flush (void ) {
68
+ // wait 2 seconds after last write to flush
69
+ return cache_dirty && sys_tick_has_passed (sys_tick_counter_last_write , 2000 );
70
+ }
71
+
64
72
void storage_flush (void ) {
65
73
cache_flush ();
66
74
}
@@ -143,6 +151,7 @@ bool storage_write_block(const uint8_t *src, uint32_t block) {
143
151
uint32_t flash_addr = FLASH_MEM_START_ADDR + (block - FLASH_PART1_START_BLOCK ) * BLOCK_SIZE ;
144
152
uint8_t * dest = cache_get_addr_for_write (flash_addr );
145
153
memcpy (dest , src , BLOCK_SIZE );
154
+ sys_tick_counter_last_write = sys_tick_counter ;
146
155
return true;
147
156
148
157
} else {
Original file line number Diff line number Diff line change 1
1
void storage_init (void );
2
2
uint32_t storage_get_block_size (void );
3
3
uint32_t storage_get_block_count (void );
4
+ bool storage_needs_flush (void );
4
5
void storage_flush (void );
5
6
bool storage_read_block (uint8_t * dest , uint32_t block );
6
7
bool storage_write_block (const uint8_t * src , uint32_t block );
You can’t perform that action at this time.
0 commit comments