This commit is contained in:
hathach committed 2019-10-10 18:51:39 +07:00
1 parent b9d586b56c
commit d8099f484d
5 files changed
+43 -31

No files matched your search

@@ -41,7 +41,7 @@ static inline uint32_t page_offset_of (uint32_t addr)
return addr & (FLASH_CACHE_SIZE - 1);
}
uint32_t flash_cache_write (flash_cache_t* fc, uint32_t dst, void const * src, uint32_t len)
int flash_cache_write (flash_cache_t* fc, uint32_t dst, void const * src, uint32_t len)
{
uint8_t const * src8 = (uint8_t const *) src;
uint32_t remain = len;
@@ -95,7 +95,7 @@ void flash_cache_flush (flash_cache_t* fc)
fc->cache_addr = FLASH_CACHE_INVALID_ADDR;
}
void flash_cache_read (flash_cache_t* fc, void* dst, uint32_t addr, uint32_t count)
int flash_cache_read (flash_cache_t* fc, void* dst, uint32_t addr, uint32_t count)
{
// there is no check for overflow / wraparound for dst + count, addr + count.
// this might be a useful thing to add for at least debug builds.
@@ -198,4 +198,6 @@ void flash_cache_read (flash_cache_t* fc, void* dst, uint32_t addr, uint32_t cou
// not using the cache, so just forward to read from flash
fc->read(dst, addr, count);
}
return (int) count;
}
@@ -46,9 +46,9 @@ typedef struct
extern "C" {
#endif
uint32_t flash_cache_write (flash_cache_t* fc, uint32_t dst, void const *src, uint32_t count);
int flash_cache_write (flash_cache_t* fc, uint32_t dst, void const *src, uint32_t count);
void flash_cache_flush (flash_cache_t* fc);
void flash_cache_read (flash_cache_t* fc, void* dst, uint32_t addr, uint32_t count);
int flash_cache_read (flash_cache_t* fc, void* dst, uint32_t addr, uint32_t count);
#ifdef __cplusplus
}
@@ -29,6 +29,17 @@
#include "delay.h"
#include "rtos.h"
#ifdef NRF52840_XXAA
#define BOOTLOADER_ADDR 0xF4000
#else
#define BOOTLOADER_ADDR 0x74000
#endif
// defined in linker script
extern uint32_t __flash_arduino_start[];
//extern uint32_t __flash_arduino_end[];
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
@@ -65,17 +76,20 @@ void flash_nrf5x_flush (void)
flash_cache_flush(&_cache);
}
uint32_t flash_nrf5x_write (uint32_t dst, void const * src, uint32_t len)
int flash_nrf5x_write (uint32_t dst, void const * src, uint32_t len)
{
// TODO prevent write SD + bootloader region
// Softdevice region
VERIFY(dst >= ((uint32_t) __flash_arduino_start), -1);
// Bootloader region
VERIFY(dst < BOOTLOADER_ADDR, -1);
return flash_cache_write(&_cache, dst, src, len);
}
uint32_t flash_nrf5x_read (void* dst, uint32_t src, uint32_t len)
int flash_nrf5x_read (void* dst, uint32_t src, uint32_t len)
{
// return cache value if available
flash_cache_read(&_cache, dst, src, len);
return len;
return flash_cache_read(&_cache, dst, src, len);
}
bool flash_nrf5x_erase(uint32_t addr)
@@ -36,27 +36,24 @@
void flash_nrf5x_flush (void);
bool flash_nrf5x_erase(uint32_t addr);
uint32_t flash_nrf5x_write (uint32_t dst, void const * src, uint32_t len);
uint32_t flash_nrf5x_read (void* dst, uint32_t src, uint32_t len);
int flash_nrf5x_write (uint32_t dst, void const * src, uint32_t len);
int flash_nrf5x_read (void* dst, uint32_t src, uint32_t len);
//--------------------------------------------------------------------+
// Write helper
//--------------------------------------------------------------------+
static inline uint32_t flash_nrf5x_write8 (uint32_t dst, uint8_t num)
static inline int flash_nrf5x_write8 (uint32_t dst, uint8_t num)
{
flash_nrf5x_write(dst, &num, sizeof(num));
return sizeof(num);
return flash_nrf5x_write(dst, &num, sizeof(num));
}
static inline uint32_t flash_nrf5x_write16 (uint32_t dst, uint8_t num)
static inline int flash_nrf5x_write16 (uint32_t dst, uint8_t num)
{
flash_nrf5x_write(dst, &num, sizeof(num));
return sizeof(num);
return flash_nrf5x_write(dst, &num, sizeof(num));
}
static inline uint32_t flash_nrf5x_write32 (uint32_t dst, uint8_t num)
static inline int flash_nrf5x_write32 (uint32_t dst, uint8_t num)
{
flash_nrf5x_write(dst, &num, sizeof(num));
return sizeof(num);
return flash_nrf5x_write(dst, &num, sizeof(num));
}
//--------------------------------------------------------------------+