51#include "dev/watchdog.h"
57#define FLASH_WORD_SIZE 4
60#if !COFFEE_SECTOR_SIZE || COFFEE_SECTOR_SIZE % FLASH_PAGE_SIZE
61#error COFFEE_SECTOR_SIZE must be a non-zero multiple of the flash page size
63#if !COFFEE_PAGE_SIZE || COFFEE_SECTOR_SIZE % COFFEE_PAGE_SIZE
64#error COFFEE_PAGE_SIZE must be a divisor of COFFEE_SECTOR_SIZE
66#if COFFEE_PAGE_SIZE % FLASH_WORD_SIZE
67#error COFFEE_PAGE_SIZE must be a multiple of the flash word size
69#if COFFEE_SIZE % FLASH_PAGE_SIZE
70#error COFFEE_SIZE must be aligned with a flash page boundary
72#if COFFEE_SIZE % COFFEE_SECTOR_SIZE
73#error COFFEE_SIZE must be a multiple of COFFEE_SECTOR_SIZE
75#if COFFEE_SIZE / COFFEE_PAGE_SIZE > INT16_MAX
76#error Too many Coffee pages for coffee_page_t
79extern char linker_nvm_begin;
80__attribute__((used)) uint8_t
82__attribute__ ((section(
".simee")));
83#define NVM_BASE (&linker_nvm_begin)
90 flash_addr = (uint32_t)NVM_BASE +
94 MSC_ErasePage((uint32_t *)flash_addr);
101 const uint32_t *src = buf;
102 uint32_t flash_addr = (uint32_t)NVM_BASE + offset;
108 MSC_Status_TypeDef retVal = mscReturnOk;
110 if(size && (align = flash_addr & (FLASH_WORD_SIZE - 1))) {
111 len = MIN(FLASH_WORD_SIZE - align, size);
112 word = ~((*src & ((1 << (len << 3)) - 1)) << (align << 3));
114 retVal = MSC_WriteWord((uint32_t *)(flash_addr & ~(FLASH_WORD_SIZE - 1)),
115 &word, FLASH_WORD_SIZE);
117 if(retVal != mscReturnOk) {
120 *(
const uint8_t **)&src += len;
125 while(size >= FLASH_WORD_SIZE) {
127 for(i = 0; i < len / FLASH_WORD_SIZE; i++) {
128 page_buf[i] = ~*src++;
131 retVal = MSC_WriteWord((uint32_t *)flash_addr, page_buf, len);
133 if(retVal != mscReturnOk) {
141 word = ~(*src & ((1 << (size << 3)) - 1));
143 retVal = MSC_WriteWord((uint32_t *)flash_addr, &word, FLASH_WORD_SIZE);
145 if(retVal != mscReturnOk) {
157 for(src = (
const void *)(NVM_BASE + offset), dst = buf; size; size--) {
Default definitions of C compiler quirk work-arounds.
Header for the Coffee file system.
void cfs_coffee_arch_write(const void *buf, unsigned int size, cfs_offset_t offset)
Writes a buffer to the device.
#define COFFEE_SIZE
Total size in bytes of the file system.
void cfs_coffee_arch_read(void *buf, unsigned int size, cfs_offset_t offset)
Reads from the device to a buffer.
void cfs_coffee_arch_erase(uint16_t sector)
Erases a device sector.
#define COFFEE_SECTOR_SIZE
Logical sector size.
#define COFFEE_PAGE_SIZE
Logical page size.
int cfs_offset_t
CFS directory entry name length.