diff --git a/src/BuildOpt.h b/src/BuildOpt.h index de1a3630..9b7950f4 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -434,7 +434,7 @@ // the amount of space allocated to the persistent storage #if !defined(RADIOLIB_HAL_PERSISTENT_STORAGE_SIZE) - #define RADIOLIB_HAL_PERSISTENT_STORAGE_SIZE (32) + #define RADIOLIB_HAL_PERSISTENT_STORAGE_SIZE (0x60) #endif // This only compiles on STM32 boards with SUBGHZ module, but also diff --git a/src/Hal.cpp b/src/Hal.cpp index bd65819f..6ba08bb7 100644 --- a/src/Hal.cpp +++ b/src/Hal.cpp @@ -34,6 +34,20 @@ uint32_t RadioLibHal::pinToInterrupt(uint32_t 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() { uint8_t dummy = 0; 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 void RadioLibHal::setPersistentParameter(uint32_t id, T val) { uint8_t *ptr = (uint8_t*)&val; diff --git a/src/Hal.h b/src/Hal.h index 1be814e3..ef8c0ee0 100644 --- a/src/Hal.h +++ b/src/Hal.h @@ -10,19 +10,24 @@ #define RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_NONCE_ID (0) #define RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_ADDR_ID (1) #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[] = { 0x00, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_NONCE_ID - 0x02, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_ADDR_ID - 0x06, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_FCNT_UP_ID - 0x0A, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_FCNT_DOWN_ID + 0x04, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_ADDR_ID + 0x08, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_FCNT_UP_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 \brief Hardware abstraction library base interface. @@ -231,7 +236,7 @@ class RadioLibHal { \param buff Buffer to read into. \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). @@ -239,7 +244,7 @@ class RadioLibHal { \param buff Buffer 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. @@ -247,6 +252,8 @@ class RadioLibHal { */ void wipePersistentStorage(); + uint32_t getPersistentAddr(uint32_t id); + /*! \brief Method to set arbitrary parameter to persistent storage. This method DOES NOT perform any endianness conversion, so the value