mirror of
https://github.com/thelsing/knx.git
synced 2024-12-18 19:08:18 +01:00
add support for external flash system by using callbacks
This commit is contained in:
parent
15bf1c0a9d
commit
3202b33fcb
@ -140,6 +140,10 @@ uint8_t* Platform::getNonVolatileMemoryStart()
|
||||
{
|
||||
if(_memoryType == Flash)
|
||||
return userFlashStart();
|
||||
#ifdef KNX_FLASH_CALLBACK
|
||||
else if(_memoryType == Callback)
|
||||
return _callbackFlashRead();
|
||||
#endif
|
||||
else
|
||||
return getEepromBuffer(KNX_FLASH_SIZE);
|
||||
}
|
||||
@ -148,6 +152,10 @@ size_t Platform::getNonVolatileMemorySize()
|
||||
{
|
||||
if(_memoryType == Flash)
|
||||
return userFlashSizeEraseBlocks() * flashEraseBlockSize() * flashPageSize();
|
||||
#ifdef KNX_FLASH_CALLBACK
|
||||
else if(_memoryType == Callback)
|
||||
return _callbackFlashSize();
|
||||
#endif
|
||||
else
|
||||
return KNX_FLASH_SIZE;
|
||||
}
|
||||
@ -165,6 +173,10 @@ void Platform::commitNonVolatileMemory()
|
||||
_bufferedEraseblockNumber = -1; // does that make sense?
|
||||
}
|
||||
}
|
||||
#ifdef KNX_FLASH_CALLBACK
|
||||
else if(_memoryType == Callback)
|
||||
return _callbackFlashCommit();
|
||||
#endif
|
||||
else
|
||||
{
|
||||
commitToEeprom();
|
||||
@ -194,6 +206,10 @@ uint32_t Platform::writeNonVolatileMemory(uint32_t relativeAddress, uint8_t* buf
|
||||
}
|
||||
return relativeAddress;
|
||||
}
|
||||
#ifdef KNX_FLASH_CALLBACK
|
||||
else if(_memoryType == Callback)
|
||||
return _callbackFlashWrite(relativeAddress, buffer, size);
|
||||
#endif
|
||||
else
|
||||
{
|
||||
memcpy(getEepromBuffer(KNX_FLASH_SIZE)+relativeAddress, buffer, size);
|
||||
@ -283,3 +299,38 @@ void Platform::bufferEraseBlock(int32_t eraseBlockNumber)
|
||||
_bufferedEraseblockNumber = eraseBlockNumber;
|
||||
_bufferedEraseblockDirty = false;
|
||||
}
|
||||
|
||||
|
||||
#ifdef KNX_FLASH_CALLBACK
|
||||
void Platform::registerFlashCallbacks(
|
||||
FlashCallbackSize callbackFlashSize,
|
||||
FlashCallbackRead callbackFlashRead,
|
||||
FlashCallbackWrite callbackFlashWrite,
|
||||
FlashCallbackCommit callbackFlashCommit)
|
||||
{
|
||||
println("Set Callback");
|
||||
_memoryType = Callback;
|
||||
_callbackFlashSize = callbackFlashSize;
|
||||
_callbackFlashRead = callbackFlashRead;
|
||||
_callbackFlashWrite = callbackFlashWrite;
|
||||
_callbackFlashCommit = callbackFlashCommit;
|
||||
_callbackFlashSize();
|
||||
}
|
||||
|
||||
FlashCallbackSize Platform::callbackFlashSize()
|
||||
{
|
||||
return _callbackFlashSize;
|
||||
}
|
||||
FlashCallbackRead Platform::callbackFlashRead()
|
||||
{
|
||||
return _callbackFlashRead;
|
||||
}
|
||||
FlashCallbackWrite Platform::callbackFlashWrite()
|
||||
{
|
||||
return _callbackFlashWrite;
|
||||
}
|
||||
FlashCallbackCommit Platform::callbackFlashCommit()
|
||||
{
|
||||
return _callbackFlashCommit;
|
||||
}
|
||||
#endif
|
||||
|
@ -4,15 +4,28 @@
|
||||
#include <stddef.h>
|
||||
#include "save_restore.h"
|
||||
|
||||
#ifndef KNX_FLASH_CALLBACK
|
||||
#ifndef KNX_FLASH_SIZE
|
||||
#define KNX_FLASH_SIZE 1024
|
||||
#pragma warning "KNX_FLASH_SIZE not defined, using 1024"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef KNX_FLASH_CALLBACK
|
||||
#ifndef KNX_FLASH_SIZE
|
||||
#define KNX_FLASH_SIZE 0
|
||||
#endif
|
||||
typedef uint32_t (*FlashCallbackSize)();
|
||||
typedef uint8_t* (*FlashCallbackRead)();
|
||||
typedef uint32_t (*FlashCallbackWrite)(uint32_t relativeAddress, uint8_t* buffer, size_t len);
|
||||
typedef void (*FlashCallbackCommit)();
|
||||
#endif
|
||||
|
||||
enum NvMemoryType
|
||||
{
|
||||
Eeprom,
|
||||
Flash
|
||||
Flash,
|
||||
Callback
|
||||
};
|
||||
|
||||
class Platform
|
||||
@ -82,6 +95,19 @@ class Platform
|
||||
// size of one flash page in bytes
|
||||
virtual size_t flashPageSize();
|
||||
|
||||
#ifdef KNX_FLASH_CALLBACK
|
||||
void registerFlashCallbacks(
|
||||
FlashCallbackSize callbackFlashSize,
|
||||
FlashCallbackRead callbackFlashRead,
|
||||
FlashCallbackWrite callbackFlashWrite,
|
||||
FlashCallbackCommit callbackFlashCommit);
|
||||
|
||||
FlashCallbackSize callbackFlashSize();
|
||||
FlashCallbackRead callbackFlashRead();
|
||||
FlashCallbackWrite callbackFlashWrite();
|
||||
FlashCallbackCommit callbackFlashCommit();
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// size of one EraseBlock in pages
|
||||
virtual size_t flashEraseBlockSize();
|
||||
@ -97,7 +123,6 @@ class Platform
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
NvMemoryType _memoryType = Eeprom;
|
||||
|
||||
void loadEraseblockContaining(uint32_t relativeAddress);
|
||||
@ -113,4 +138,11 @@ class Platform
|
||||
uint8_t* _eraseblockBuffer = nullptr;
|
||||
int32_t _bufferedEraseblockNumber = -1;
|
||||
bool _bufferedEraseblockDirty = false;
|
||||
|
||||
#ifdef KNX_FLASH_CALLBACK
|
||||
FlashCallbackSize _callbackFlashSize = nullptr;
|
||||
FlashCallbackRead _callbackFlashRead = nullptr;
|
||||
FlashCallbackWrite _callbackFlashWrite = nullptr;
|
||||
FlashCallbackCommit _callbackFlashCommit = nullptr;
|
||||
#endif
|
||||
};
|
Loading…
Reference in New Issue
Block a user