diff --git a/.vscode/extensions.json b/.vscode/extensions.json index e80666b..080e70d 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -3,5 +3,8 @@ // for the documentation about the extensions.json format "recommendations": [ "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" ] } diff --git a/src/cc1310_platform.cpp b/src/cc1310_platform.cpp index 18e1289..2994b54 100644 --- a/src/cc1310_platform.cpp +++ b/src/cc1310_platform.cpp @@ -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) { diff --git a/src/cc1310_platform.h b/src/cc1310_platform.h index 17086ab..1014f0f 100644 --- a/src/cc1310_platform.h +++ b/src/cc1310_platform.h @@ -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; }; diff --git a/src/esp32_platform.cpp b/src/esp32_platform.cpp index f6c4812..ada8fd3 100644 --- a/src/esp32_platform.cpp +++ b/src/esp32_platform.cpp @@ -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) { diff --git a/src/esp32_platform.h b/src/esp32_platform.h index 07b0d75..0193efe 100644 --- a/src/esp32_platform.h +++ b/src/esp32_platform.h @@ -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; diff --git a/src/esp_platform.cpp b/src/esp_platform.cpp index b74dedd..f155d52 100644 --- a/src/esp_platform.cpp +++ b/src/esp_platform.cpp @@ -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) { diff --git a/src/esp_platform.h b/src/esp_platform.h index c535bae..ce55d13 100644 --- a/src/esp_platform.h +++ b/src/esp_platform.h @@ -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; diff --git a/src/knx/platform.cpp b/src/knx/platform.cpp index 3c2a74e..2b77893 100644 --- a/src/knx/platform.cpp +++ b/src/knx/platform.cpp @@ -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); diff --git a/src/knx/platform.h b/src/knx/platform.h index 21a2867..b8fafff 100644 --- a/src/knx/platform.h +++ b/src/knx/platform.h @@ -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); diff --git a/src/linux_platform.cpp b/src/linux_platform.cpp index 4ad15b3..8ebac4a 100644 --- a/src/linux_platform.cpp +++ b/src/linux_platform.cpp @@ -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(); diff --git a/src/linux_platform.h b/src/linux_platform.h index 0ec9bb9..d691e63 100644 --- a/src/linux_platform.h +++ b/src/linux_platform.h @@ -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); diff --git a/src/rp2040_arduino_platform.cpp b/src/rp2040_arduino_platform.cpp index 0374e85..44eb8c4 100644 --- a/src/rp2040_arduino_platform.cpp +++ b/src/rp2040_arduino_platform.cpp @@ -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) { diff --git a/src/rp2040_arduino_platform.h b/src/rp2040_arduino_platform.h index 77a8736..15e6dcb 100644 --- a/src/rp2040_arduino_platform.h +++ b/src/rp2040_arduino_platform.h @@ -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 diff --git a/src/samd_platform.cpp b/src/samd_platform.cpp index fc85645..a1eb786 100644 --- a/src/samd_platform.cpp +++ b/src/samd_platform.cpp @@ -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) diff --git a/src/samd_platform.h b/src/samd_platform.h index fb22dc6..948a5d8 100644 --- a/src/samd_platform.h +++ b/src/samd_platform.h @@ -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 diff --git a/src/stm32_platform.cpp b/src/stm32_platform.cpp index fd6ea37..f5e5b28 100644 --- a/src/stm32_platform.cpp +++ b/src/stm32_platform.cpp @@ -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 diff --git a/src/stm32_platform.h b/src/stm32_platform.h index 056a327..7545ca0 100644 --- a/src/stm32_platform.h +++ b/src/stm32_platform.h @@ -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;