44 #include "dev/watchdog.h" 45 #include "cfs-coffee-arch.h" 48 #define EXT_ERASE_UNIT_SIZE 4096UL 50 #define XMEM_BUFF_LENGHT 128 53 #define PRINTF(...) printf(__VA_ARGS__) 55 #define PRINTF(...) do {} while(0) 64 xmem_pread(
void *_p,
int size,
unsigned long addr)
73 PRINTF(
"Could not open flash to save config\n");
79 for(i = 0; i < size; i++) {
80 x = ~*((uint8_t *)_p + i);
81 *((uint8_t *)_p + i) = x;
90 PRINTF(
"Could not read flash memory!\n");
94 xmem_pwrite(
const void *_buf,
int size,
unsigned long addr)
100 uint8_t tmp_buf[XMEM_BUFF_LENGHT];
105 PRINTF(
"Could not open flash to save config!\n");
110 for(remain = size, j = 0; remain > 0; remain -= XMEM_BUFF_LENGHT, j += XMEM_BUFF_LENGHT) {
111 int to_write = MIN(XMEM_BUFF_LENGHT, remain);
112 for(i = 0; i < to_write; i++) {
113 tmp_buf[i] = ~*((uint8_t *)_buf + j + i);
117 PRINTF(
"Could not write flash memory!\n");
118 return size - remain;
127 xmem_erase(
long size,
unsigned long addr)
134 PRINTF(
"Could not open flash to save config\n");
139 if(size % EXT_ERASE_UNIT_SIZE != 0) {
140 PRINTF(
"xmem_erase: bad size\n");
144 if(addr % EXT_ERASE_UNIT_SIZE != 0) {
145 PRINTF(
"xmem_erase: bad offset\n");
159 PRINTF(
"Could not erase flash memory\n");
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
bool ext_flash_read(const spi_device_t *conf, uint32_t offset, uint32_t length, uint8_t *buf)
Read storage content.
bool ext_flash_open(const spi_device_t *conf)
Initialize storage driver.
bool ext_flash_erase(const spi_device_t *conf, uint32_t offset, uint32_t length)
Erase storage sectors corresponding to the range.
bool ext_flash_close(const spi_device_t *conf)
Close the storage driver.
Header file for the external SPI flash API.
void watchdog_periodic(void)
Writes the WDT clear sequence.
bool ext_flash_write(const spi_device_t *conf, uint32_t offset, uint32_t length, const uint8_t *buf)
Write to storage sectors.