35#define SUPPORT_SL_R1_API
41#include "simplelink.h"
47void eeprom_updated_notification();
51 const char *name,
size_t file_size_bytes)
52 :
EEPROM(name, file_size_bytes)
54 data_ = (uint8_t *)malloc(file_size_bytes);
56 memset(
data_, 0xff, file_size_bytes);
61 bool have_rot =
false;
63 for (
unsigned sector = 0; sector <
SECTOR_COUNT; ++sector)
65 int handle =
open_file(sector, SL_FS_READ,
true);
68 LOG(
VERBOSE,
"EEPROM: sector %u: could not open.", sector);
71 unsigned b = 0xaa55aaaa;
73 sl_FsClose(handle,
nullptr,
nullptr, 0);
74 LOG(
VERBOSE,
"EEPROM: sector %u: version %u.", sector, b);
118 SL_FS_CREATE | SL_FS_CREATE_MAX_SIZE(
file_size() + 4));
127 unsigned sector, uint32_t open_mode,
bool ignore_error)
129 string filename(
name);
130 filename.push_back(
'.');
131 filename.push_back(
'0' + sector);
132 int ret = sl_FsOpen((uint8_t *)filename.c_str(), open_mode, NULL);
133 if (!ignore_error && ret < 0)
141 unsigned int index,
const void *buf,
size_t len)
144 if (memcmp(
data_ + index, buf, len) == 0) {
147 memcpy(
data_ + index, buf, len);
149 eeprom_updated_notification();
155 memcpy(buf,
data_ + index, len);
void SlCheckResult(int result, int expected)
Tests that a SimpleLink request has succeeded.
uint8_t isDirty_
non-zero if we have unflushed writes.
void mount()
Must be called exactly once after creation, after the simplelink stack has been started.
uint8_t * data_
Holds the file payload in memory.
int open_file(unsigned sector, uint32_t open_mode, bool ignore_error=false)
Opens a SL file.
~CC32xxEEPROMEmulation()
Destructor.
void flush()
Instructs the driver to write all changed data to disk.
void flush_buffers() OVERRIDE
REQUIRED: lock_ is held.
void write(unsigned int index, const void *buf, size_t len) override
Write to the EEPROM.
void read(unsigned int index, void *buf, size_t len) override
Read from the EEPROM.
CC32xxEEPROMEmulation(const char *name, size_t file_size_bytes)
Constructor.
static const uint8_t SECTOR_COUNT
The total number of files which we are round-robining.
uint8_t readSector_
The sector number of the last sector we used for reading.
unsigned fileVersion_
This number is increased by one every time the contents are flushed to a file.
Common base class for all EEPROM access.
size_t file_size()
Get the maximum file size of the EEPROM file.
const char * name
device name
#define LOG(level, message...)
Conditionally write a message to the logging output.
static const int VERBOSE
Loglevel that is usually not printed, reporting debugging information.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.