8typedef struct { uint8_t *
b; uint32_t size; }
ram_t;
11static int rd(
void *c, uint32_t a,
void *buf, uint32_t
n)
14 if (a +
n > r->
size)
return -1;
15 memcpy(buf, r->
b + a,
n);
19static int pg(
void *c, uint32_t a,
const void *buf, uint32_t
n)
23 const uint8_t *p = (
const uint8_t *)buf;
24 for (uint32_t k = 0; k <
n; ++k) r->
b[a + k] &= p[k];
28static int er(
void *c, uint32_t a)
static int pg(void *c, uint32_t a, const void *buf, uint32_t n)
static int rd(void *c, uint32_t a, void *buf, uint32_t n)
void log_flash_ram_init(log_flash_t *f, uint8_t *buf, uint32_t size)
buf: size bytes (rounded down to whole sectors)
static int er(void *c, uint32_t a)
log_flash_t on a RAM buffer with NOR semantics (erase sets 0xFF, program can only clear bits).
flash backend; addresses in bytes from the start of the log area
int(* erase)(void *ctx, uint32_t addr)
one 4 KB sector, blocking
uint32_t size
multiple of LOG_SECTOR
int(* read)(void *ctx, uint32_t addr, void *buf, uint32_t n)
int(* prog)(void *ctx, uint32_t addr, const void *buf, uint32_t n)
inside one 256-byte page