34 static inline uint32_t toAddress(
unsigned int block) {
38 #define _CHK_ERROR -1 // There was an error
39 #define _CHK_EQUAL 0 // Data to be written equals data, no write required
40 #define _CHK_ERASE 1 // Block must be erased prior to writing
41 #define _CHK_WRITE 2 // Block is already empty and can be written
46 bool bsSave(
unsigned int block,
void * data,
size_t len)
48 uint32_t addr = toAddress(block);
56 if (!
sfErase(addr))
return false;
57 if (!
sfProg(addr, (
void *)&hdr,
sizeof(BlockHeader)))
return false;
58 if (!
sfProgXPage(addr +
sizeof(BlockHeader), data, len))
return false;
63 bool bsCheck(
unsigned int block,
size_t len,
bool * hasValidData)
65 uint32_t addr = toAddress(block);
67 if (!
sfRead(addr, (
void *)&hdr,
sizeof(hdr)))
return errRebase(_logModInfo.name);
69 if (hdr.magic != _MAGIC || (len > 0 && hdr.len != len))
71 *hasValidData =
false;
79 bool bsLoad(
unsigned int block,
void * data,
size_t len)
81 uint32_t addr = toAddress(block);
83 if (!
sfRead(addr,(
void *) &hdr,
sizeof(hdr)))
return errRebase(_logModInfo.name);
93 uint32_t addr = toAddress(block);
Defines the configuration of the LM32 SOC for the CLBv2.
Allows for storage of persistent information in flash.
#define E_BS_INVALID
Block storage is not valid. Must erase.
bool bsCheck(unsigned int block, size_t len, bool *hasValidData)
Checks the contents of a block.
static bool errCondRebase(bool err, const char *name)
Transparent conditional error rebase.
bool bsLoad(unsigned int block, void *data, size_t len)
Loads a block of data from the flash.
Manages the global system error.
bool sfErase(uint32_t address)
Erase a sector in flash.
bool bsSave(unsigned int block, void *data, size_t len)
Saves a block of data on the internal flash.
#define BLOCKS_OFFSET
The block space offset.
bool bsErase(unsigned int block)
Erases all data.
bool sfProgXPage(uint32_t address, uint8_t *data, uint32_t count)
Program cross pages.
#define LOG_DEF(NAME,...)
Define a logger for a module.
static bool errRebase(const char *name)
Rebases the cause of the error message.
bool sfRead(uint32_t address, uint8_t *data, uint32_t count)
Read from a specific address in flash.
bool errSet(uint32_t code, const char *error, const char *name)
Sets an error.
This driver implements access to the Serial Flash.
Implements a generic logger facility.
bool sfProg(uint32_t address, uint8_t *data, uint32_t count)
Program an page in flash.
#define E_BS_LEN_MISMATCH
Buffer does not match the size of the allocated area.