Skip to content

Commit c756d94

Browse files
Daniel Jaecklemluis1
Daniel Jaeckle
authored andcommitted
Refactored Non Volatile Memory management (Big update)
1 parent 492ee5d commit c756d94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+3706
-4553
lines changed

src/apps/LoRaMac/CMakeLists.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ if(SUB_PROJECT STREQUAL periodic-uplink-lpp)
4949
#---------------------------------------------------------------------------------------
5050
list(APPEND ${PROJECT_NAME}_COMMON
5151
"${CMAKE_CURRENT_LIST_DIR}/common/CayenneLpp.c"
52+
"${CMAKE_CURRENT_LIST_DIR}/common/cli.c"
5253
"${CMAKE_CURRENT_LIST_DIR}/common/LmHandlerMsgDisplay.c"
53-
"${CMAKE_CURRENT_LIST_DIR}/common/NvmCtxMgmt.c"
54+
"${CMAKE_CURRENT_LIST_DIR}/common/NvmDataMgmt.c"
5455
)
5556

5657
#---------------------------------------------------------------------------------------
@@ -78,7 +79,7 @@ elseif(SUB_PROJECT STREQUAL fuota-test-01)
7879
#---------------------------------------------------------------------------------------
7980
list(APPEND ${PROJECT_NAME}_COMMON
8081
"${CMAKE_CURRENT_LIST_DIR}/common/LmHandlerMsgDisplay.c"
81-
"${CMAKE_CURRENT_LIST_DIR}/common/NvmCtxMgmt.c"
82+
"${CMAKE_CURRENT_LIST_DIR}/common/NvmDataMgmt.c"
8283
)
8384

8485
#---------------------------------------------------------------------------------------
@@ -125,6 +126,9 @@ target_compile_definitions(${PROJECT_NAME}-${SUB_PROJECT} PRIVATE ACTIVE_REGION=
125126
if(${SECURE_ELEMENT_PRE_PROVISIONED} MATCHES ON)
126127
target_compile_definitions(${PROJECT_NAME}-${SUB_PROJECT} PRIVATE -DSECURE_ELEMENT_PRE_PROVISIONED)
127128
endif()
129+
if(${SECURE_ELEMENT} MATCHES SOFT_SE)
130+
target_compile_definitions(${PROJECT_NAME}-${SUB_PROJECT} PRIVATE -DSOFT_SE)
131+
endif()
128132
target_compile_definitions(${PROJECT_NAME}-${SUB_PROJECT} PUBLIC
129133
$<BUILD_INTERFACE:$<TARGET_PROPERTY:mac,INTERFACE_COMPILE_DEFINITIONS>>
130134
)

src/apps/LoRaMac/common/LmHandler/LmHandler.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
#include "utilities.h"
2929
#include "timer.h"
3030
#include "Commissioning.h"
31-
#include "NvmCtxMgmt.h"
31+
#include "NvmDataMgmt.h"
32+
#include "radio.h"
3233
#include "LmHandler.h"
3334
#include "LmhPackage.h"
3435
#include "LmhpCompliance.h"
@@ -214,6 +215,7 @@ LmHandlerErrorStatus_t LmHandlerInit( LmHandlerCallbacks_t *handlerCallbacks,
214215
LmHandlerParams_t *handlerParams )
215216
{
216217
//
218+
uint16_t nbNvmData = 0;
217219
MibRequestConfirm_t mibReq;
218220
LmHandlerParams = handlerParams;
219221
LmHandlerCallbacks = handlerCallbacks;
@@ -224,7 +226,7 @@ LmHandlerErrorStatus_t LmHandlerInit( LmHandlerCallbacks_t *handlerCallbacks,
224226
LoRaMacPrimitives.MacMlmeIndication = MlmeIndication;
225227
LoRaMacCallbacks.GetBatteryLevel = LmHandlerCallbacks->GetBatteryLevel;
226228
LoRaMacCallbacks.GetTemperatureLevel = LmHandlerCallbacks->GetTemperature;
227-
LoRaMacCallbacks.NvmContextChange = NvmCtxMgmtEvent;
229+
LoRaMacCallbacks.NvmDataChange = NvmDataMgmtEvent;
228230
LoRaMacCallbacks.MacProcessNotify = LmHandlerCallbacks->OnMacProcess;
229231

230232
IsClassBSwitchPending = false;
@@ -234,10 +236,13 @@ LmHandlerErrorStatus_t LmHandlerInit( LmHandlerCallbacks_t *handlerCallbacks,
234236
return LORAMAC_HANDLER_ERROR;
235237
}
236238

239+
// Restore data if required
240+
nbNvmData = NvmDataMgmtRestore( );
241+
237242
// Try to restore from NVM and query the mac if possible.
238-
if( NvmCtxMgmtRestore( ) == NVMCTXMGMT_STATUS_SUCCESS )
243+
if( nbNvmData > 0 )
239244
{
240-
LmHandlerCallbacks->OnNvmContextChange( LORAMAC_HANDLER_NVM_RESTORE );
245+
LmHandlerCallbacks->OnNvmDataChange( LORAMAC_HANDLER_NVM_RESTORE, nbNvmData );
241246
}
242247
else
243248
{
@@ -321,6 +326,8 @@ bool LmHandlerIsBusy( void )
321326

322327
void LmHandlerProcess( void )
323328
{
329+
uint16_t size = 0;
330+
324331
// Process Radio IRQ
325332
if( Radio.IrqProcess != NULL )
326333
{
@@ -333,9 +340,12 @@ void LmHandlerProcess( void )
333340
// Call all packages process functions
334341
LmHandlerPackagesProcess( );
335342

336-
if( NvmCtxMgmtStore( ) == NVMCTXMGMT_STATUS_SUCCESS )
343+
// Store to NVM if required
344+
size = NvmDataMgmtStore( );
345+
346+
if( size > 0 )
337347
{
338-
LmHandlerCallbacks->OnNvmContextChange( LORAMAC_HANDLER_NVM_STORE );
348+
LmHandlerCallbacks->OnNvmDataChange( LORAMAC_HANDLER_NVM_STORE, size );
339349
}
340350
}
341351

src/apps/LoRaMac/common/LmHandler/LmHandler.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,19 @@ typedef struct LmHandlerCallbacks_s
131131
/*!
132132
*\brief Will be called each time a Radio IRQ is handled by the MAC
133133
* layer.
134-
*
134+
*
135135
*\warning Runs in a IRQ context. Should only change variables state.
136136
*/
137137
void ( *OnMacProcess )( void );
138138
/*!
139139
* Notifies the upper layer that the NVM context has changed
140140
*
141-
* \param [IN] stored Indicates if we are storing (true) or
142-
* restoring (false) the NVM context
141+
* \param [IN] state Indicates if we are storing (true) or
142+
* restoring (false) the NVM context
143+
*
144+
* \param [IN] size Number of data bytes which were stored or restored.
143145
*/
144-
void ( *OnNvmContextChange )( LmHandlerNvmContextStates_t state );
146+
void ( *OnNvmDataChange )( LmHandlerNvmContextStates_t state, uint16_t size );
145147
/*!
146148
* Notifies the upper layer that a network parameters have been set
147149
*

src/apps/LoRaMac/common/LmHandlerMsgDisplay.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,18 @@ void PrintHexBuffer( uint8_t *buffer, uint8_t size )
111111
printf( "\n" );
112112
}
113113

114-
void DisplayNvmContextChange( LmHandlerNvmContextStates_t state )
114+
void DisplayNvmDataChange( LmHandlerNvmContextStates_t state, uint16_t size )
115115
{
116116
if( state == LORAMAC_HANDLER_NVM_STORE )
117117
{
118-
printf( "\n###### ============ CTXS STORED ============ ######\n\n" );
118+
printf( "\n###### ============ CTXS STORED ============ ######\n" );
119+
119120
}
120121
else
121122
{
122-
printf( "\n###### =========== CTXS RESTORED =========== ######\n\n" );
123+
printf( "\n###### =========== CTXS RESTORED =========== ######\n" );
123124
}
125+
printf( "Size : %i\n\n", size );
124126
}
125127

126128
void DisplayNetworkParametersUpdate( CommissioningParams_t *commissioningParams )

src/apps/LoRaMac/common/LmHandlerMsgDisplay.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
*
3131
* \param [IN] state Indicates if we are storing (true) or
3232
* restoring (false) the NVM context
33+
*
34+
* \param [IN] size Number of data bytes which were stored or restored.
3335
*/
34-
void DisplayNvmContextChange( LmHandlerNvmContextStates_t state );
36+
void DisplayNvmDataChange( LmHandlerNvmContextStates_t state, uint16_t size );
3537

3638
/*!
3739
* \brief Displays updated network parameters

0 commit comments

Comments
 (0)