mirror of
https://github.com/thelsing/knx.git
synced 2025-08-13 13:46:20 +02:00
added support for both Eeprom and Flash (NvMemoryType) plattforms.
This commit is contained in:
parent
b5b228c417
commit
5bef967ed3
@ -107,7 +107,8 @@ size_t Platform::flashEraseBlockSize()
|
|||||||
|
|
||||||
size_t Platform::flashPageSize()
|
size_t Platform::flashPageSize()
|
||||||
{
|
{
|
||||||
return 0;
|
// align to 32bit as default for Eeprom Emulation plattforms
|
||||||
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *Platform::userFlashStart()
|
uint8_t *Platform::userFlashStart()
|
||||||
@ -126,17 +127,34 @@ void Platform::flashErase(uint16_t eraseBlockNum)
|
|||||||
void Platform::flashWritePage(uint16_t pageNumber, uint8_t* data)
|
void Platform::flashWritePage(uint16_t pageNumber, uint8_t* data)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
uint8_t * Platform::getEepromBuffer(uint16_t size)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Platform::commitToEeprom()
|
||||||
|
{}
|
||||||
|
|
||||||
uint8_t* Platform::getNonVolatileMemoryStart()
|
uint8_t* Platform::getNonVolatileMemoryStart()
|
||||||
{
|
{
|
||||||
|
if(_memoryType == Flash)
|
||||||
return userFlashStart();
|
return userFlashStart();
|
||||||
|
else
|
||||||
|
return getEepromBuffer(KNX_FLASH_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Platform::getNonVolatileMemorySize()
|
size_t Platform::getNonVolatileMemorySize()
|
||||||
{
|
{
|
||||||
|
if(_memoryType == Flash)
|
||||||
return userFlashSizeEraseBlocks() * flashEraseBlockSize() * flashPageSize();
|
return userFlashSizeEraseBlocks() * flashEraseBlockSize() * flashPageSize();
|
||||||
|
else
|
||||||
|
return KNX_FLASH_SIZE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::commitNonVolatileMemory()
|
void Platform::commitNonVolatileMemory()
|
||||||
|
{
|
||||||
|
if(_memoryType == Flash)
|
||||||
{
|
{
|
||||||
if(_bufferedEraseblockNumber > -1 && _bufferedEraseblockDirty)
|
if(_bufferedEraseblockNumber > -1 && _bufferedEraseblockDirty)
|
||||||
{
|
{
|
||||||
@ -147,8 +165,15 @@ void Platform::commitNonVolatileMemory()
|
|||||||
_bufferedEraseblockNumber = -1; // does that make sense?
|
_bufferedEraseblockNumber = -1; // does that make sense?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
commitToEeprom();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t Platform::writeNonVolatileMemory(uint32_t relativeAddress, uint8_t* buffer, size_t size)
|
uint32_t Platform::writeNonVolatileMemory(uint32_t relativeAddress, uint8_t* buffer, size_t size)
|
||||||
|
{
|
||||||
|
if(_memoryType == Flash)
|
||||||
{
|
{
|
||||||
while (size > 0)
|
while (size > 0)
|
||||||
{
|
{
|
||||||
@ -167,6 +192,12 @@ uint32_t Platform::writeNonVolatileMemory(uint32_t relativeAddress, uint8_t* buf
|
|||||||
}
|
}
|
||||||
return relativeAddress;
|
return relativeAddress;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(getEepromBuffer(KNX_FLASH_SIZE)+relativeAddress, buffer, size);
|
||||||
|
return relativeAddress+size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Platform::loadEraseblockContaining(uint32_t relativeAddress)
|
void Platform::loadEraseblockContaining(uint32_t relativeAddress)
|
||||||
{
|
{
|
||||||
|
@ -50,6 +50,11 @@ class Platform
|
|||||||
virtual void closeSpi();
|
virtual void closeSpi();
|
||||||
virtual int readWriteSpi(uint8_t *data, size_t len);
|
virtual int readWriteSpi(uint8_t *data, size_t len);
|
||||||
|
|
||||||
|
//Memory
|
||||||
|
|
||||||
|
virtual uint8_t* getEepromBuffer(uint16_t size);
|
||||||
|
virtual void commitToEeprom();
|
||||||
|
|
||||||
virtual uint8_t* getNonVolatileMemoryStart();
|
virtual uint8_t* getNonVolatileMemoryStart();
|
||||||
virtual size_t getNonVolatileMemorySize();
|
virtual size_t getNonVolatileMemorySize();
|
||||||
virtual void commitNonVolatileMemory();
|
virtual void commitNonVolatileMemory();
|
||||||
@ -58,7 +63,6 @@ class Platform
|
|||||||
// size of one flash page in bytes
|
// size of one flash page in bytes
|
||||||
virtual size_t flashPageSize();
|
virtual size_t flashPageSize();
|
||||||
|
|
||||||
|
|
||||||
NvMemoryType NonVolatileMemoryType();
|
NvMemoryType NonVolatileMemoryType();
|
||||||
void NonVolatileMemoryType(NvMemoryType type);
|
void NonVolatileMemoryType(NvMemoryType type);
|
||||||
|
|
||||||
|
@ -6,10 +6,12 @@ made to work with arduino-pico - "Raspberry Pi Pico Arduino core, for all RP2040
|
|||||||
by Earl E. Philhower III https://github.com/earlephilhower/arduino-pico
|
by Earl E. Philhower III https://github.com/earlephilhower/arduino-pico
|
||||||
tested with V1.9.1
|
tested with V1.9.1
|
||||||
|
|
||||||
by SirSydom <com@sirsydom.de> 2021
|
by SirSydom <com@sirsydom.de> 2021-2022
|
||||||
|
|
||||||
A maximum of 4kB emulated EEPROM is supported.
|
Uses direct flash reading/writing.
|
||||||
For more, use or own emulation (maybe with littlefs)
|
Size ist defined by KNX_FLASH_SIZE (default 4k).
|
||||||
|
Offset in Flash is defined by KNX_FLASH_OFFSET (default 1,5MiB / 0x180000).
|
||||||
|
EEPROM Emulation from arduino-pico core (max 4k) can be use by defining USE_RP2040_EEPROM_EMULATION
|
||||||
|
|
||||||
----------------------------------------------------*/
|
----------------------------------------------------*/
|
||||||
|
|
||||||
@ -32,10 +34,16 @@ RP2040ArduinoPlatform::RP2040ArduinoPlatform()
|
|||||||
: ArduinoPlatform(&Serial1)
|
: ArduinoPlatform(&Serial1)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
#ifndef USE_RP2040_EEPROM_EMULATION
|
||||||
|
_memoryType = Flash;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
RP2040ArduinoPlatform::RP2040ArduinoPlatform( HardwareSerial* s) : ArduinoPlatform(s)
|
RP2040ArduinoPlatform::RP2040ArduinoPlatform( HardwareSerial* s) : ArduinoPlatform(s)
|
||||||
{
|
{
|
||||||
|
#ifndef USE_RP2040_EEPROM_EMULATION
|
||||||
|
_memoryType = Flash;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RP2040ArduinoPlatform::uniqueSerialNumber()
|
uint32_t RP2040ArduinoPlatform::uniqueSerialNumber()
|
||||||
@ -55,6 +63,10 @@ void RP2040ArduinoPlatform::restart()
|
|||||||
watchdog_reboot(0,0,0);
|
watchdog_reboot(0,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_RP2040_EEPROM_EMULATION
|
||||||
|
|
||||||
|
#pragma warning "Using EEPROM Simulation"
|
||||||
|
|
||||||
uint8_t * RP2040ArduinoPlatform::getEepromBuffer(uint16_t size)
|
uint8_t * RP2040ArduinoPlatform::getEepromBuffer(uint16_t size)
|
||||||
{
|
{
|
||||||
if(size > 4096)
|
if(size > 4096)
|
||||||
@ -79,6 +91,7 @@ void RP2040ArduinoPlatform::commitToEeprom()
|
|||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
size_t RP2040ArduinoPlatform::flashEraseBlockSize()
|
size_t RP2040ArduinoPlatform::flashEraseBlockSize()
|
||||||
{
|
{
|
||||||
@ -142,5 +155,6 @@ void RP2040ArduinoPlatform::writeBufferedEraseBlock()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#define KNX_FLASH_SIZE 1024
|
#define KNX_FLASH_SIZE 1024
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class RP2040ArduinoPlatform : public ArduinoPlatform
|
class RP2040ArduinoPlatform : public ArduinoPlatform
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -22,9 +23,11 @@ public:
|
|||||||
uint32_t uniqueSerialNumber(); //override;
|
uint32_t uniqueSerialNumber(); //override;
|
||||||
|
|
||||||
void restart();
|
void restart();
|
||||||
|
|
||||||
|
#ifdef USE_RP2040_EEPROM_EMULATION
|
||||||
uint8_t* getEepromBuffer(uint16_t size);
|
uint8_t* getEepromBuffer(uint16_t size);
|
||||||
void commitToEeprom();
|
void commitToEeprom();
|
||||||
|
#else
|
||||||
|
|
||||||
// size of one EraseBlock in pages
|
// size of one EraseBlock in pages
|
||||||
virtual size_t flashEraseBlockSize();
|
virtual size_t flashEraseBlockSize();
|
||||||
@ -41,6 +44,7 @@ public:
|
|||||||
|
|
||||||
// writes _eraseblockBuffer to flash - overrides Plattform::writeBufferedEraseBlock()
|
// writes _eraseblockBuffer to flash - overrides Plattform::writeBufferedEraseBlock()
|
||||||
void writeBufferedEraseBlock();
|
void writeBufferedEraseBlock();
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user