32bit eeprom size (#230)

* add commitNonVolatileMemory overload to batch write chars n times to flash

* changed uint8_t getEepromBuffer(uint16_t size) to uint8_t getEepromBuffer(uint32_t size) to allow eeprom > 65k

* reworked PR #230
This commit is contained in:
Dom 2023-02-13 21:39:30 +01:00 committed by GitHub
parent 9894a8c8b8
commit dce92403e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 52 additions and 17 deletions

View File

@ -3,5 +3,8 @@
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

View File

@ -495,7 +495,7 @@ void CC1310Platform::init()
setupNVS();
}
uint8_t* CC1310Platform::getEepromBuffer(uint16_t size)
uint8_t* CC1310Platform::getEepromBuffer(uint32_t size)
{
if(size > KNX_FLASH_SIZE)
{

View File

@ -20,7 +20,7 @@ class CC1310Platform : public Platform
void restart() final;
void fatalError() final;
uint8_t* getEepromBuffer(uint16_t size) final;
uint8_t* getEepromBuffer(uint32_t size) final;
void commitToEeprom() final;
};

View File

@ -108,7 +108,7 @@ bool Esp32Platform::sendBytesUniCast(uint32_t addr, uint16_t port, uint8_t* buff
return true;
}
uint8_t * Esp32Platform::getEepromBuffer(uint16_t size)
uint8_t * Esp32Platform::getEepromBuffer(uint32_t size)
{
uint8_t * eepromptr = EEPROM.getDataPtr();
if(eepromptr == nullptr) {

View File

@ -32,7 +32,7 @@ public:
bool sendBytesUniCast(uint32_t addr, uint16_t port, uint8_t* buffer, uint16_t len) override;
//memory
uint8_t* getEepromBuffer(uint16_t size);
uint8_t* getEepromBuffer(uint32_t size);
void commitToEeprom();
private:
WiFiUDP _udp;

View File

@ -108,7 +108,7 @@ bool EspPlatform::sendBytesUniCast(uint32_t addr, uint16_t port, uint8_t* buffer
return true;
}
uint8_t * EspPlatform::getEepromBuffer(uint16_t size)
uint8_t * EspPlatform::getEepromBuffer(uint32_t size)
{
uint8_t * eepromptr = EEPROM.getDataPtr();
if(eepromptr == nullptr) {

View File

@ -32,7 +32,7 @@ class EspPlatform : public ArduinoPlatform
bool sendBytesUniCast(uint32_t addr, uint16_t port, uint8_t* buffer, uint16_t len) override;
//memory
uint8_t* getEepromBuffer(uint16_t size);
uint8_t* getEepromBuffer(uint32_t size);
void commitToEeprom();
private:
WiFiUDP _udp;

View File

@ -128,7 +128,7 @@ void Platform::flashErase(uint16_t eraseBlockNum)
void Platform::flashWritePage(uint16_t pageNumber, uint8_t* data)
{}
uint8_t * Platform::getEepromBuffer(uint16_t size)
uint8_t * Platform::getEepromBuffer(uint32_t size)
{
return nullptr;
}
@ -201,6 +201,37 @@ uint32_t Platform::writeNonVolatileMemory(uint32_t relativeAddress, uint8_t* buf
}
}
// writes value repeat times into flash starting at relativeAddress
// returns next free relativeAddress
uint32_t Platform::writeNonVolatileMemory(uint32_t relativeAddress, uint8_t value, size_t repeat)
{
if(_memoryType == Flash)
{
while (repeat > 0)
{
loadEraseblockContaining(relativeAddress);
uint32_t start = _bufferedEraseblockNumber * (flashEraseBlockSize() * flashPageSize());
uint32_t end = start + (flashEraseBlockSize() * flashPageSize());
uint32_t offset = relativeAddress - start;
uint32_t length = end - relativeAddress;
if(length > repeat)
length = repeat;
memset(_eraseblockBuffer + offset, value, length);
_bufferedEraseblockDirty = true;
relativeAddress += length;
repeat -= length;
}
return relativeAddress;
}
else
{
memset(getEepromBuffer(KNX_FLASH_SIZE)+relativeAddress, value, repeat);
return relativeAddress+repeat;
}
}
void Platform::loadEraseblockContaining(uint32_t relativeAddress)
{
int32_t blockNum = getEraseBlockNumberOf(relativeAddress);

View File

@ -61,7 +61,7 @@ class Platform
//
// --- changes to the UserMemory are written directly into the address space starting at getEepromBuffer
// --- commitToEeprom must save this to a non-volatile area if neccessary
virtual uint8_t* getEepromBuffer(uint16_t size);
virtual uint8_t* getEepromBuffer(uint32_t size);
virtual void commitToEeprom();
// -------------------------------------------------------------------------------------------------------
@ -70,6 +70,7 @@ class Platform
virtual void commitNonVolatileMemory();
// address is relative to start of nonvolatile memory
virtual uint32_t writeNonVolatileMemory(uint32_t relativeAddress, uint8_t* buffer, size_t size);
virtual uint32_t writeNonVolatileMemory(uint32_t relativeAddress, uint8_t value, size_t repeat);
NvMemoryType NonVolatileMemoryType();
void NonVolatileMemoryType(NvMemoryType type);

View File

@ -265,7 +265,7 @@ int LinuxPlatform::readBytesMultiCast(uint8_t* buffer, uint16_t maxLen)
return len;
}
uint8_t* LinuxPlatform::getEepromBuffer(uint16_t size)
uint8_t* LinuxPlatform::getEepromBuffer(uint32_t size)
{
if (_fd < 0)
doMemoryMapping();

View File

@ -55,7 +55,7 @@ public:
int readWriteSpi (uint8_t *data, size_t len) override;
//memory
uint8_t* getEepromBuffer(uint16_t size) override;
uint8_t* getEepromBuffer(uint32_t size) override;
void commitToEeprom() override;
void cmdlineArgs(int argc, char** argv);

View File

@ -109,7 +109,7 @@ void RP2040ArduinoPlatform::restart()
#ifdef USE_RP2040_LARGE_EEPROM_EMULATION
uint8_t * RP2040ArduinoPlatform::getEepromBuffer(uint16_t size)
uint8_t * RP2040ArduinoPlatform::getEepromBuffer(uint32_t size)
{
if(size%4096)
{
@ -144,7 +144,7 @@ void RP2040ArduinoPlatform::commitToEeprom()
#else
uint8_t * RP2040ArduinoPlatform::getEepromBuffer(uint16_t size)
uint8_t * RP2040ArduinoPlatform::getEepromBuffer(uint32_t size)
{
if(size > 4096)
{

View File

@ -30,7 +30,7 @@ public:
void restart();
#ifdef USE_RP2040_EEPROM_EMULATION
uint8_t* getEepromBuffer(uint16_t size);
uint8_t* getEepromBuffer(uint32_t size);
void commitToEeprom();
#ifdef USE_RP2040_LARGE_EEPROM_EMULATION

View File

@ -61,7 +61,7 @@ void SamdPlatform::restart()
#ifdef USE_SAMD_EEPROM_EMULATION
#pragma warning "Using EEPROM Simulation"
uint8_t* SamdPlatform::getEepromBuffer(uint16_t size)
uint8_t* SamdPlatform::getEepromBuffer(uint32_t size)
{
//EEPROM.begin(size);
if(size > EEPROM_EMULATION_SIZE)

View File

@ -17,7 +17,7 @@ public:
void restart();
#ifdef USE_SAMD_EEPROM_EMULATION
uint8_t* getEepromBuffer(uint16_t size);
uint8_t* getEepromBuffer(uint32_t size);
void commitToEeprom();
#else
// size of one EraseBlock in pages

View File

@ -34,7 +34,7 @@ void Stm32Platform::restart()
NVIC_SystemReset();
}
uint8_t * Stm32Platform::getEepromBuffer(uint16_t size)
uint8_t * Stm32Platform::getEepromBuffer(uint32_t size)
{
// check if the buffer already exists
if (_eepromPtr == nullptr) // we need to initialize the buffer first

View File

@ -15,7 +15,7 @@ public:
void restart();
//memory
uint8_t* getEepromBuffer(uint16_t size);
uint8_t* getEepromBuffer(uint32_t size);
void commitToEeprom();
private:
uint8_t *_eepromPtr = nullptr;