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)
73 PRINTF(
"Could not open flash to read!\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");
100 uint8_t tmp_buf[XMEM_BUFF_LENGHT];
105 PRINTF(
"Could not open flash to write!\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");
119 return size - remain;
132 if(size % EXT_ERASE_UNIT_SIZE != 0) {
133 PRINTF(
"xmem_erase: bad size\n");
137 if(
addr % EXT_ERASE_UNIT_SIZE != 0) {
138 PRINTF(
"xmem_erase: bad offset\n");
145 PRINTF(
"Could not open flash to erase\n");
160 PRINTF(
"Could not erase flash memory\n");
Header file for the external SPI flash API.
void watchdog_periodic(void)
Writes the WDT clear sequence.
bool ext_flash_read(const spi_device_t *conf, uint32_t offset, uint32_t length, uint8_t *buf)
Read storage content.
bool ext_flash_close(const spi_device_t *conf)
Close the storage driver.
bool ext_flash_init(const spi_device_t *conf)
Initialise the external flash.
bool ext_flash_open(const spi_device_t *conf)
Initialize storage driver.
bool ext_flash_write(const spi_device_t *conf, uint32_t offset, uint32_t length, const uint8_t *buf)
Write to storage sectors.
bool ext_flash_erase(const spi_device_t *conf, uint32_t offset, uint32_t length)
Erase storage sectors corresponding to the range.
void xmem_init(void)
Initialize the external memory.
int xmem_erase(long size, unsigned long addr)
Erase a sector in the flash memory.
int xmem_pwrite(const void *_buf, int size, unsigned long addr)
int xmem_pread(void *_p, int size, unsigned long addr)
Read a number of bytes from an offset in the external memory.
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Header file to the external flash memory (XMem) API.