From 27efec949a32a78e005f9b5577a1a7a895bd677e Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 25 Oct 2018 17:42:06 +0700 Subject: [PATCH] refactor flash_cache a bit --- cores/nRF5/flash/flash_cache.h | 12 ++++++------ cores/nRF5/flash/flash_nrf5x.c | 5 ++++- cores/nRF5/flash/flash_qspi.c | 5 ++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cores/nRF5/flash/flash_cache.h b/cores/nRF5/flash/flash_cache.h index 6e52b685..792fe834 100644 --- a/cores/nRF5/flash/flash_cache.h +++ b/cores/nRF5/flash/flash_cache.h @@ -45,13 +45,13 @@ typedef struct { - bool (*erase) (uint32_t addr); - uint32_t (*program) (uint32_t dst, void const * src, uint32_t len); - uint32_t (*read) (void* dst, uint32_t src, uint32_t len); - bool (*verify) (uint32_t addr, void const * buf, uint32_t len); + bool (*erase) (uint32_t addr); + uint32_t (*program) (uint32_t dst, void const * src, uint32_t len); + uint32_t (*read) (void* dst, uint32_t src, uint32_t len); + bool (*verify) (uint32_t addr, void const * buf, uint32_t len); - uint32_t cache_addr; - uint8_t cache_buf[FLASH_CACHE_SIZE] __attribute__((aligned(4))); + uint32_t cache_addr; + uint8_t* cache_buf; } flash_cache_t; #ifdef __cplusplus diff --git a/cores/nRF5/flash/flash_nrf5x.c b/cores/nRF5/flash/flash_nrf5x.c index 8c8db041..57b85267 100644 --- a/cores/nRF5/flash/flash_nrf5x.c +++ b/cores/nRF5/flash/flash_nrf5x.c @@ -58,12 +58,15 @@ static uint32_t fal_program (uint32_t dst, void const * src, uint32_t len); static uint32_t fal_read (void* dst, uint32_t src, uint32_t len); static bool fal_verify (uint32_t addr, void const * buf, uint32_t len); +uint8_t _cache_buffer[FLASH_CACHE_SIZE] __attribute__((aligned(4))); + static flash_cache_t _cache = { .erase = fal_erase, .program = fal_program, .read = fal_read, .verify = fal_verify, - .cache_addr = FLASH_CACHE_INVALID_ADDR + .cache_addr = FLASH_CACHE_INVALID_ADDR, + .cache_buf = _cache_buffer }; //--------------------------------------------------------------------+ diff --git a/cores/nRF5/flash/flash_qspi.c b/cores/nRF5/flash/flash_qspi.c index be9a4de7..c69f7569 100644 --- a/cores/nRF5/flash/flash_qspi.c +++ b/cores/nRF5/flash/flash_qspi.c @@ -82,12 +82,15 @@ static uint32_t fal_qspi_program (uint32_t dst, void const * src, uint32_t len); static uint32_t fal_qspi_read (void* dst, uint32_t src, uint32_t len); static bool fal_qspi_verify (uint32_t addr, void const * buf, uint32_t len); +uint8_t _cache_buffer[FLASH_CACHE_SIZE] __attribute__((aligned(4))); + static flash_cache_t _cache = { .erase = fal_qspi_erase, .program = fal_qspi_program, .read = fal_qspi_read, .verify = fal_qspi_verify, - .cache_addr = FLASH_CACHE_INVALID_ADDR + .cache_addr = FLASH_CACHE_INVALID_ADDR, + .cache_buf = _cache_buffer };