clean up
This commit is contained in:
1 parent
03b56f16c4
commit
8dc3bbed50
4 files changed
+14
-12
No files matched your search
@@ -43,12 +43,12 @@
|
||||
//--------------------------------------------------------------------+
|
||||
static inline uint32_t page_addr_of (uint32_t addr)
|
||||
{
|
||||
return addr & ~(FLASH_CACHE_PAGE_SIZE - 1);
|
||||
return addr & ~(FLASH_CACHE_SIZE - 1);
|
||||
}
|
||||
|
||||
static inline uint32_t page_offset_of (uint32_t addr)
|
||||
{
|
||||
return addr & (FLASH_CACHE_PAGE_SIZE - 1);
|
||||
return addr & (FLASH_CACHE_SIZE - 1);
|
||||
}
|
||||
|
||||
uint32_t flash_cache_write (flash_cache_t* fc, uint32_t dst, void const * src, uint32_t len)
|
||||
@@ -62,7 +62,7 @@ uint32_t flash_cache_write (flash_cache_t* fc, uint32_t dst, void const * src, u
|
||||
uint32_t const page_addr = page_addr_of(dst);
|
||||
uint32_t const offset = page_offset_of(dst);
|
||||
|
||||
uint32_t wr_bytes = FLASH_CACHE_PAGE_SIZE - offset;
|
||||
uint32_t wr_bytes = FLASH_CACHE_SIZE - offset;
|
||||
wr_bytes = min32(remain, wr_bytes);
|
||||
|
||||
// Page changes, flush old and update new cache
|
||||
@@ -78,9 +78,9 @@ uint32_t flash_cache_write (flash_cache_t* fc, uint32_t dst, void const * src, u
|
||||
}
|
||||
|
||||
uint32_t const last_byte = offset + wr_bytes;
|
||||
if ( last_byte < FLASH_CACHE_PAGE_SIZE )
|
||||
if ( last_byte < FLASH_CACHE_SIZE )
|
||||
{
|
||||
fc->read(fc->cache_buf + last_byte, page_addr + last_byte, FLASH_CACHE_PAGE_SIZE - last_byte);
|
||||
fc->read(fc->cache_buf + last_byte, page_addr + last_byte, FLASH_CACHE_SIZE - last_byte);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,10 +99,10 @@ void flash_cache_flush (flash_cache_t* fc)
|
||||
if ( fc->cache_addr == FLASH_CACHE_INVALID_ADDR ) return;
|
||||
|
||||
// skip erase & program if verify() exists, and memory matches
|
||||
if ( !(fc->verify && fc->verify(fc->cache_addr, fc->cache_buf, FLASH_CACHE_PAGE_SIZE)) )
|
||||
if ( !(fc->verify && fc->verify(fc->cache_addr, fc->cache_buf, FLASH_CACHE_SIZE)) )
|
||||
{
|
||||
fc->erase(fc->cache_addr);
|
||||
fc->program(fc->cache_addr, fc->cache_buf, FLASH_CACHE_PAGE_SIZE);
|
||||
fc->program(fc->cache_addr, fc->cache_buf, FLASH_CACHE_SIZE);
|
||||
}
|
||||
|
||||
fc->cache_addr = FLASH_CACHE_INVALID_ADDR;
|
||||
@@ -113,7 +113,7 @@ void flash_cache_read (flash_cache_t* fc, void* dst, uint32_t addr, uint32_t cou
|
||||
// overwrite with cache value if available
|
||||
if ( (fc->cache_addr != FLASH_CACHE_INVALID_ADDR) &&
|
||||
!(addr < fc->cache_addr && addr + count <= fc->cache_addr) &&
|
||||
!(addr >= fc->cache_addr + FLASH_CACHE_PAGE_SIZE) )
|
||||
!(addr >= fc->cache_addr + FLASH_CACHE_SIZE) )
|
||||
{
|
||||
int dst_off = fc->cache_addr - addr;
|
||||
int src_off = 0;
|
||||
@@ -124,7 +124,7 @@ void flash_cache_read (flash_cache_t* fc, void* dst, uint32_t addr, uint32_t cou
|
||||
dst_off = 0;
|
||||
}
|
||||
|
||||
int cache_bytes = minof(FLASH_CACHE_PAGE_SIZE-src_off, count - dst_off);
|
||||
int cache_bytes = minof(FLASH_CACHE_SIZE-src_off, count - dst_off);
|
||||
|
||||
// start to cached
|
||||
if ( dst_off ) fc->read(dst, addr, dst_off);
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define FLASH_CACHE_PAGE_SIZE 4096
|
||||
#define FLASH_CACHE_SIZE 4096 // must be a erasable page size
|
||||
#define FLASH_CACHE_INVALID_ADDR 0xffffffff
|
||||
|
||||
typedef struct
|
||||
@@ -51,7 +51,7 @@ typedef struct
|
||||
bool (*verify) (uint32_t addr, void const * buf, uint32_t len);
|
||||
|
||||
uint32_t cache_addr;
|
||||
uint8_t cache_buf[FLASH_CACHE_PAGE_SIZE] __attribute__((aligned(4)));
|
||||
uint8_t cache_buf[FLASH_CACHE_SIZE] __attribute__((aligned(4)));
|
||||
} flash_cache_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -106,7 +106,7 @@ bool fal_erase (uint32_t addr)
|
||||
|
||||
// delay and retry if busy
|
||||
uint32_t err;
|
||||
while ( NRF_ERROR_BUSY == (err = sd_flash_page_erase(addr / FLASH_CACHE_PAGE_SIZE)) )
|
||||
while ( NRF_ERROR_BUSY == (err = sd_flash_page_erase(addr / FLASH_NRF52_PAGE_SIZE)) )
|
||||
{
|
||||
delay(1);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
|
||||
#include "common_inc.h"
|
||||
|
||||
#define FLASH_NRF52_PAGE_SIZE 4096
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user