49static uint8_t get_first_sector() {
51 if (estart < 0x10000) {
52 return estart / 0x1000;
54 return 16 - 2 + estart / 0x8000;
70 if (eend <= 0x10000) {
72 }
else if (estart >= 0x10000) {
75 DIE(
"LPC17xx cannot have the EEPROM range cross the boundary of "
76 "address of 0x10000");
84inline const uint32_t *LpcEEPROMEmulation::get_block(
85 unsigned sector,
unsigned offset)
97 return get_block(sector, offset);
108 portENTER_CRITICAL();
109 Chip_IAP_PreSectorForReadWrite(s, s);
110 Chip_IAP_EraseSector(s, s);
123 unsigned relative_sector,
unsigned start_block, uint32_t *data, uint32_t byte_count)
128 auto* address = get_block(relative_sector, start_block);
131 SystemCoreClockUpdate();
133 uint32_t start_address = (uintptr_t)address & ~(
WRITE_SIZE - 1);
139 memcpy(
scratch + ((uintptr_t)address - start_address), data, byte_count);
141 portENTER_CRITICAL();
142 Chip_IAP_PreSectorForReadWrite(sector, sector);
const char __eeprom_end
Linker-defined symbol where in the memory space (flash) the eeprom emulation data ends.
const char __eeprom_start
Linker-defined symbol where in the memory space (flash) the eeprom emulation data starts.
Emulates EEPROM in FLASH for the Tiva, LPC17xx and LPC40xx platforms.
static const size_t BLOCK_SIZE
block size in bytes
const uint16_t rawBlockCount_
How many blocks are there in a sector.
static const size_t SECTOR_SIZE
Sector size in bytes.
void mount()
Mount the EEPROM file.
static const size_t BYTES_PER_BLOCK
useful data bytes size in bytes
const uint8_t sectorCount_
Total number of sectors available.
LpcEEPROMEmulation()
Default constructor.
static constexpr unsigned WRITE_SIZE
write size in bytes, must be used as an array size
void flash_erase(unsigned sector) override
Simple hardware abstraction for FLASH erase API.
const uint32_t * block(unsigned sector, unsigned offset) override
Computes the pointer to load the data stored in a specific block from.
const uint8_t firstSector_
Stores the IAP sector code for the first sector starting at __eeprom_start.
uint8_t scratch[WRITE_SIZE]
scratchpad for performing write operations
void flash_program(unsigned sector, unsigned start_block, uint32_t *data, uint32_t byte_count) override
Simple hardware abstraction for FLASH program API.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define DIE(MSG)
Unconditionally terminates the current process with a message.