[HAL] Updated persistent management
This commit is contained in:
parent
d725215e20
commit
df691db0a5
3 changed files with 36 additions and 11 deletions
|
@ -434,7 +434,7 @@
|
||||||
|
|
||||||
// the amount of space allocated to the persistent storage
|
// the amount of space allocated to the persistent storage
|
||||||
#if !defined(RADIOLIB_HAL_PERSISTENT_STORAGE_SIZE)
|
#if !defined(RADIOLIB_HAL_PERSISTENT_STORAGE_SIZE)
|
||||||
#define RADIOLIB_HAL_PERSISTENT_STORAGE_SIZE (32)
|
#define RADIOLIB_HAL_PERSISTENT_STORAGE_SIZE (0x60)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// This only compiles on STM32 boards with SUBGHZ module, but also
|
// This only compiles on STM32 boards with SUBGHZ module, but also
|
||||||
|
|
18
src/Hal.cpp
18
src/Hal.cpp
|
@ -34,6 +34,20 @@ uint32_t RadioLibHal::pinToInterrupt(uint32_t pin) {
|
||||||
return(pin);
|
return(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RadioLibHal::readPersistentStorage(uint32_t addr, uint8_t* buff, size_t len) {
|
||||||
|
// these are only needed for some protocols, so it's not needed to have them by default
|
||||||
|
(void)addr;
|
||||||
|
(void)buff;
|
||||||
|
(void)len;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RadioLibHal::writePersistentStorage(uint32_t addr, uint8_t* buff, size_t len) {
|
||||||
|
// these are only needed for some protocols, so it's not needed to have them by default
|
||||||
|
(void)addr;
|
||||||
|
(void)buff;
|
||||||
|
(void)len;
|
||||||
|
}
|
||||||
|
|
||||||
void RadioLibHal::wipePersistentStorage() {
|
void RadioLibHal::wipePersistentStorage() {
|
||||||
uint8_t dummy = 0;
|
uint8_t dummy = 0;
|
||||||
for(size_t i = 0; i < RADIOLIB_HAL_PERSISTENT_STORAGE_SIZE; i++) {
|
for(size_t i = 0; i < RADIOLIB_HAL_PERSISTENT_STORAGE_SIZE; i++) {
|
||||||
|
@ -41,6 +55,10 @@ void RadioLibHal::wipePersistentStorage() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t RadioLibHal::getPersistentAddr(uint32_t id) {
|
||||||
|
return(RadioLibPersistentParamTable[id]);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void RadioLibHal::setPersistentParameter(uint32_t id, T val) {
|
void RadioLibHal::setPersistentParameter(uint32_t id, T val) {
|
||||||
uint8_t *ptr = (uint8_t*)&val;
|
uint8_t *ptr = (uint8_t*)&val;
|
||||||
|
|
27
src/Hal.h
27
src/Hal.h
|
@ -10,19 +10,24 @@
|
||||||
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_NONCE_ID (0)
|
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_NONCE_ID (0)
|
||||||
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_ADDR_ID (1)
|
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_ADDR_ID (1)
|
||||||
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_FCNT_UP_ID (2)
|
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_FCNT_UP_ID (2)
|
||||||
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_FCNT_DOWN_ID (3)
|
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_MAGIC_ID (3)
|
||||||
|
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_APP_S_KEY_ID (4)
|
||||||
|
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_FNWK_SINT_KEY_ID (5)
|
||||||
|
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_SNWK_SINT_KEY_ID (6)
|
||||||
|
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_NWK_SENC_KEY_ID (7)
|
||||||
|
|
||||||
static const uint32_t RadioLibPersistentParamTable[] = {
|
static const uint32_t RadioLibPersistentParamTable[] = {
|
||||||
0x00, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_NONCE_ID
|
0x00, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_NONCE_ID
|
||||||
0x02, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_ADDR_ID
|
0x04, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_ADDR_ID
|
||||||
0x06, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_FCNT_UP_ID
|
0x08, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_FCNT_UP_ID
|
||||||
0x0A, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_FCNT_DOWN_ID
|
0x0C, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_MAGIC_ID
|
||||||
|
0x10, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_APP_S_KEY_ID
|
||||||
|
0x20, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_FNWK_SINT_KEY_ID
|
||||||
|
0x30, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_SNWK_SINT_KEY_ID
|
||||||
|
0x40, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_NWK_SENC_KEY_ID
|
||||||
|
0x50, // end
|
||||||
};
|
};
|
||||||
|
|
||||||
// static assert to make sure that the persistent parameter table will fit to the allocated storage space
|
|
||||||
#define RADIOLIB_STATIC_ASSERT(test) typedef char radiolib_static_assert[( !!(test) )*2-1 ]
|
|
||||||
RADIOLIB_STATIC_ASSERT( sizeof(RadioLibPersistentParamTable) <= RADIOLIB_HAL_PERSISTENT_STORAGE_SIZE );
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class RadioLibHal
|
\class RadioLibHal
|
||||||
\brief Hardware abstraction library base interface.
|
\brief Hardware abstraction library base interface.
|
||||||
|
@ -231,7 +236,7 @@ class RadioLibHal {
|
||||||
\param buff Buffer to read into.
|
\param buff Buffer to read into.
|
||||||
\param len Number of bytes to read.
|
\param len Number of bytes to read.
|
||||||
*/
|
*/
|
||||||
virtual void readPersistentStorage(uint32_t addr, uint8_t* buff, size_t len) = 0;
|
virtual void readPersistentStorage(uint32_t addr, uint8_t* buff, size_t len);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Method to write to persistent storage (e.g. EEPROM).
|
\brief Method to write to persistent storage (e.g. EEPROM).
|
||||||
|
@ -239,7 +244,7 @@ class RadioLibHal {
|
||||||
\param buff Buffer to write.
|
\param buff Buffer to write.
|
||||||
\param len Number of bytes to write.
|
\param len Number of bytes to write.
|
||||||
*/
|
*/
|
||||||
virtual void writePersistentStorage(uint32_t addr, uint8_t* buff, size_t len) = 0;
|
virtual void writePersistentStorage(uint32_t addr, uint8_t* buff, size_t len);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Method to wipe the persistent storage by writing to 0.
|
\brief Method to wipe the persistent storage by writing to 0.
|
||||||
|
@ -247,6 +252,8 @@ class RadioLibHal {
|
||||||
*/
|
*/
|
||||||
void wipePersistentStorage();
|
void wipePersistentStorage();
|
||||||
|
|
||||||
|
uint32_t getPersistentAddr(uint32_t id);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Method to set arbitrary parameter to persistent storage.
|
\brief Method to set arbitrary parameter to persistent storage.
|
||||||
This method DOES NOT perform any endianness conversion, so the value
|
This method DOES NOT perform any endianness conversion, so the value
|
||||||
|
|
Loading…
Add table
Reference in a new issue