summaryrefslogtreecommitdiff
path: root/stm/storage.c
diff options
context:
space:
mode:
authorJohn R. Lenton <jlenton@gmail.com>2014-01-05 01:57:54 +0000
committerJohn R. Lenton <jlenton@gmail.com>2014-01-05 01:57:54 +0000
commit7e73a8fd09a8070a3bbb90d2ddc4f04af4e2828a (patch)
tree606e074a1955f381c68d1689946066e9eb1a5a47 /stm/storage.c
parent5d4a8213395b1e27d303379772c90b3b0adc82d5 (diff)
parent45b43c21c4f8e30dcff00c2429eddba20ca002aa (diff)
Merge remote-tracking branch 'upstream/master' into list_index
Diffstat (limited to 'stm/storage.c')
-rw-r--r--stm/storage.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/stm/storage.c b/stm/storage.c
index 6878de22e..daee4adb5 100644
--- a/stm/storage.c
+++ b/stm/storage.c
@@ -49,6 +49,18 @@ static uint8_t *cache_get_addr_for_write(uint32_t flash_addr) {
return (uint8_t*)CACHE_MEM_START_ADDR + flash_addr - flash_sector_start;
}
+static uint8_t *cache_get_addr_for_read(uint32_t flash_addr) {
+ uint32_t flash_sector_start;
+ uint32_t flash_sector_size;
+ uint32_t flash_sector_id = flash_get_sector_info(flash_addr, &flash_sector_start, &flash_sector_size);
+ if (cache_flash_sector_id == flash_sector_id) {
+ // in cache, copy from there
+ return (uint8_t*)CACHE_MEM_START_ADDR + flash_addr - flash_sector_start;
+ }
+ // not in cache, copy straight from flash
+ return (uint8_t*)flash_addr;
+}
+
void storage_init(void) {
if (!is_initialised) {
cache_flash_sector_id = 0;
@@ -131,8 +143,9 @@ bool storage_read_block(uint8_t *dest, uint32_t block) {
return true;
} else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS) {
- // non-MBR block, just copy straight from flash
- uint8_t *src = (uint8_t*)FLASH_MEM_START_ADDR + (block - FLASH_PART1_START_BLOCK) * BLOCK_SIZE;
+ // non-MBR block, get data from flash memory, possibly via cache
+ uint32_t flash_addr = FLASH_MEM_START_ADDR + (block - FLASH_PART1_START_BLOCK) * BLOCK_SIZE;
+ uint8_t *src = cache_get_addr_for_read(flash_addr);
memcpy(dest, src, BLOCK_SIZE);
return true;