Skip to content

Commit 8cd5721

Browse files
committed
Added MAC NVM context management.
Finalized secure-element support addition.
1 parent a96bb9f commit 8cd5721

File tree

23 files changed

+1486
-70
lines changed

23 files changed

+1486
-70
lines changed

src/apps/LoRaMac/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,19 @@ if((CLASS STREQUAL classB) AND NOT CLASSB_ENABLED )
3939
message(FATAL_ERROR "Please turn on Class B support of LoRaMac ( CLASSB_ENABLED=ON ) to use Class B application")
4040
endif()
4141

42+
#---------------------------------------------------------------------------------------
43+
# Applications
44+
#---------------------------------------------------------------------------------------
45+
file(GLOB ${PROJECT_NAME}_APPS "${CMAKE_CURRENT_LIST_DIR}/common/*.c")
46+
4247
#---------------------------------------------------------------------------------------
4348
# Target
4449
#---------------------------------------------------------------------------------------
4550

4651
file(GLOB ${PROJECT_NAME}_SOURCES "${CMAKE_CURRENT_LIST_DIR}/${CLASS}/${BOARD}/*.c")
4752

4853
add_executable(${PROJECT_NAME}-${CLASS}
54+
${${PROJECT_NAME}_APPS}
4955
${${PROJECT_NAME}_SOURCES}
5056
$<TARGET_OBJECTS:mac>
5157
$<TARGET_OBJECTS:system>
@@ -61,6 +67,7 @@ target_compile_definitions(${PROJECT_NAME}-${CLASS} PUBLIC
6167
)
6268

6369
target_include_directories(${PROJECT_NAME}-${CLASS} PUBLIC
70+
${CMAKE_CURRENT_SOURCE_DIR}/common
6471
$<BUILD_INTERFACE:$<TARGET_PROPERTY:mac,INTERFACE_INCLUDE_DIRECTORIES>>
6572
$<BUILD_INTERFACE:$<TARGET_PROPERTY:system,INTERFACE_INCLUDE_DIRECTORIES>>
6673
$<BUILD_INTERFACE:$<TARGET_PROPERTY:radio,INTERFACE_INCLUDE_DIRECTORIES>>

src/apps/LoRaMac/classA/NAMote72/main.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "mpl3115.h"
3333
#include "LoRaMac.h"
3434
#include "Commissioning.h"
35+
#include "NvmCtxMgmt.h"
3536

3637
#ifndef ACTIVE_REGION
3738

@@ -167,7 +168,7 @@ static bool NextTx = true;
167168
*/
168169
static enum eDeviceState
169170
{
170-
DEVICE_STATE_INIT,
171+
DEVICE_STATE_RESTORE,
171172
DEVICE_STATE_START,
172173
DEVICE_STATE_JOIN,
173174
DEVICE_STATE_SEND,
@@ -1007,10 +1008,11 @@ int main( void )
10071008
macPrimitives.MacMlmeIndication = MlmeIndication;
10081009
macCallbacks.GetBatteryLevel = BoardGetBatteryLevel;
10091010
macCallbacks.GetTemperatureLevel = MPL3115ReadTemperature;
1011+
macCallbacks.NvmContextChange = NvmCtxMgmtEvent;
10101012

10111013
LoRaMacInitialization( &macPrimitives, &macCallbacks, ACTIVE_REGION );
10121014

1013-
DeviceState = DEVICE_STATE_INIT;
1015+
DeviceState = DEVICE_STATE_RESTORE;
10141016

10151017
printf( "###### ===== ClassA demo application v1.0.RC1 ==== ######\r\n\r\n" );
10161018

@@ -1021,8 +1023,15 @@ int main( void )
10211023

10221024
switch( DeviceState )
10231025
{
1024-
case DEVICE_STATE_INIT:
1026+
case DEVICE_STATE_RESTORE:
10251027
{
1028+
// Try to restore from NVM and query the mac if possible.
1029+
if( NvmCtxMgmtRestore( ) == NVMCTXMGMT_STATUS_SUCCESS )
1030+
{
1031+
printf( "\r\n###### ===== CTXS RESTORED ==== ######\r\n\r\n" );
1032+
}
1033+
else
1034+
{
10261035
mibReq.Type = MIB_APP_KEY;
10271036
mibReq.Param.AppKey = AppKey;
10281037
LoRaMacMibSetRequestConfirm( &mibReq );
@@ -1075,6 +1084,7 @@ int main( void )
10751084
mibReq.Param.AppSKey = AppSKey;
10761085
LoRaMacMibSetRequestConfirm( &mibReq );
10771086
#endif
1087+
}
10781088
DeviceState = DEVICE_STATE_START;
10791089
break;
10801090
}
@@ -1207,13 +1217,18 @@ int main( void )
12071217
}
12081218
case DEVICE_STATE_SLEEP:
12091219
{
1220+
if( NvmCtxMgmtStore( ) == NVMCTXMGMT_STATUS_SUCCESS )
1221+
{
1222+
printf( "\r\n###### ===== CTXS STORED ==== ######\r\n" );
1223+
}
1224+
12101225
// Wake up through events
12111226
BoardLowPowerHandler( );
12121227
break;
12131228
}
12141229
default:
12151230
{
1216-
DeviceState = DEVICE_STATE_INIT;
1231+
DeviceState = DEVICE_STATE_START;
12171232
break;
12181233
}
12191234
}

src/apps/LoRaMac/classA/NucleoL073/main.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "gpio.h"
3030
#include "LoRaMac.h"
3131
#include "Commissioning.h"
32+
#include "NvmCtxMgmt.h"
3233

3334
#ifndef ACTIVE_REGION
3435

@@ -164,7 +165,7 @@ static bool NextTx = true;
164165
*/
165166
static enum eDeviceState
166167
{
167-
DEVICE_STATE_INIT,
168+
DEVICE_STATE_RESTORE,
168169
DEVICE_STATE_START,
169170
DEVICE_STATE_JOIN,
170171
DEVICE_STATE_SEND,
@@ -911,10 +912,11 @@ int main( void )
911912
macPrimitives.MacMlmeIndication = MlmeIndication;
912913
macCallbacks.GetBatteryLevel = BoardGetBatteryLevel;
913914
macCallbacks.GetTemperatureLevel = NULL;
915+
macCallbacks.NvmContextChange = NvmCtxMgmtEvent;
914916

915917
LoRaMacInitialization( &macPrimitives, &macCallbacks, ACTIVE_REGION );
916918

917-
DeviceState = DEVICE_STATE_INIT;
919+
DeviceState = DEVICE_STATE_RESTORE;
918920

919921
printf( "###### ===== ClassA demo application v1.0.RC1 ==== ######\r\n\r\n" );
920922

@@ -930,8 +932,15 @@ int main( void )
930932

931933
switch( DeviceState )
932934
{
933-
case DEVICE_STATE_INIT:
935+
case DEVICE_STATE_RESTORE:
934936
{
937+
// Try to restore from NVM and query the mac if possible.
938+
if( NvmCtxMgmtRestore( ) == NVMCTXMGMT_STATUS_SUCCESS )
939+
{
940+
printf( "\r\n###### ===== CTXS RESTORED ==== ######\r\n\r\n" );
941+
}
942+
else
943+
{
935944
mibReq.Type = MIB_APP_KEY;
936945
mibReq.Param.AppKey = AppKey;
937946
LoRaMacMibSetRequestConfirm( &mibReq );
@@ -984,6 +993,7 @@ int main( void )
984993
mibReq.Param.AppSKey = AppSKey;
985994
LoRaMacMibSetRequestConfirm( &mibReq );
986995
#endif
996+
}
987997
DeviceState = DEVICE_STATE_START;
988998
break;
989999
}
@@ -1116,13 +1126,18 @@ int main( void )
11161126
}
11171127
case DEVICE_STATE_SLEEP:
11181128
{
1129+
if( NvmCtxMgmtStore( ) == NVMCTXMGMT_STATUS_SUCCESS )
1130+
{
1131+
printf( "\r\n###### ===== CTXS STORED ==== ######\r\n" );
1132+
}
1133+
11191134
// Wake up through events
11201135
BoardLowPowerHandler( );
11211136
break;
11221137
}
11231138
default:
11241139
{
1125-
DeviceState = DEVICE_STATE_INIT;
1140+
DeviceState = DEVICE_STATE_START;
11261141
break;
11271142
}
11281143
}

src/apps/LoRaMac/classA/NucleoL152/main.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "gpio.h"
3030
#include "LoRaMac.h"
3131
#include "Commissioning.h"
32+
#include "NvmCtxMgmt.h"
3233

3334
#ifndef ACTIVE_REGION
3435

@@ -164,7 +165,7 @@ static bool NextTx = true;
164165
*/
165166
static enum eDeviceState
166167
{
167-
DEVICE_STATE_INIT,
168+
DEVICE_STATE_RESTORE,
168169
DEVICE_STATE_START,
169170
DEVICE_STATE_JOIN,
170171
DEVICE_STATE_SEND,
@@ -540,8 +541,7 @@ static void McpsConfirm( McpsConfirm_t *mcpsConfirm )
540541
printf("CHANNEL MASK: ");
541542
#if defined( REGION_AS923 ) || defined( REGION_CN779 ) || \
542543
defined( REGION_EU868 ) || defined( REGION_IN865 ) || \
543-
defined( REGION_KR920 ) || defined( REGION_EU433 ) || \
544-
defined( REGION_RU864 )
544+
defined( REGION_KR920 ) || defined( REGION_EU433 )
545545

546546
for( uint8_t i = 0; i < 1; i++)
547547

@@ -912,10 +912,11 @@ int main( void )
912912
macPrimitives.MacMlmeIndication = MlmeIndication;
913913
macCallbacks.GetBatteryLevel = BoardGetBatteryLevel;
914914
macCallbacks.GetTemperatureLevel = NULL;
915+
macCallbacks.NvmContextChange = NvmCtxMgmtEvent;
915916

916917
LoRaMacInitialization( &macPrimitives, &macCallbacks, ACTIVE_REGION );
917918

918-
DeviceState = DEVICE_STATE_INIT;
919+
DeviceState = DEVICE_STATE_RESTORE;
919920

920921
printf( "###### ===== ClassA demo application v1.0.RC1 ==== ######\r\n\r\n" );
921922

@@ -931,8 +932,15 @@ int main( void )
931932

932933
switch( DeviceState )
933934
{
934-
case DEVICE_STATE_INIT:
935+
case DEVICE_STATE_RESTORE:
935936
{
937+
// Try to restore from NVM and query the mac if possible.
938+
if( NvmCtxMgmtRestore( ) == NVMCTXMGMT_STATUS_SUCCESS )
939+
{
940+
printf( "\r\n###### ===== CTXS RESTORED ==== ######\r\n\r\n" );
941+
}
942+
else
943+
{
936944
mibReq.Type = MIB_APP_KEY;
937945
mibReq.Param.AppKey = AppKey;
938946
LoRaMacMibSetRequestConfirm( &mibReq );
@@ -985,6 +993,7 @@ int main( void )
985993
mibReq.Param.AppSKey = AppSKey;
986994
LoRaMacMibSetRequestConfirm( &mibReq );
987995
#endif
996+
}
988997
DeviceState = DEVICE_STATE_START;
989998
break;
990999
}
@@ -1117,13 +1126,18 @@ int main( void )
11171126
}
11181127
case DEVICE_STATE_SLEEP:
11191128
{
1129+
if( NvmCtxMgmtStore( ) == NVMCTXMGMT_STATUS_SUCCESS )
1130+
{
1131+
printf( "\r\n###### ===== CTXS STORED ==== ######\r\n" );
1132+
}
1133+
11201134
// Wake up through events
11211135
BoardLowPowerHandler( );
11221136
break;
11231137
}
11241138
default:
11251139
{
1126-
DeviceState = DEVICE_STATE_INIT;
1140+
DeviceState = DEVICE_STATE_START;
11271141
break;
11281142
}
11291143
}

src/apps/LoRaMac/classA/SAML21/main.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "gpio.h"
3232
#include "LoRaMac.h"
3333
#include "Commissioning.h"
34+
#include "NvmCtxMgmt.h"
3435

3536
#ifndef ACTIVE_REGION
3637

@@ -171,7 +172,7 @@ static bool NextTx = true;
171172
*/
172173
static enum eDeviceState
173174
{
174-
DEVICE_STATE_INIT,
175+
DEVICE_STATE_RESTORE,
175176
DEVICE_STATE_START,
176177
DEVICE_STATE_JOIN,
177178
DEVICE_STATE_SEND,
@@ -917,10 +918,11 @@ int main( void )
917918
macPrimitives.MacMlmeIndication = MlmeIndication;
918919
macCallbacks.GetBatteryLevel = BoardGetBatteryLevel;
919920
macCallbacks.GetTemperatureLevel = NULL;
921+
macCallbacks.NvmContextChange = NvmCtxMgmtEvent;
920922

921923
LoRaMacInitialization( &macPrimitives, &macCallbacks, ACTIVE_REGION );
922924

923-
DeviceState = DEVICE_STATE_INIT;
925+
DeviceState = DEVICE_STATE_RESTORE;
924926

925927
printf( "###### ===== ClassA demo application v1.0.RC1 ==== ######\r\n\r\n" );
926928

@@ -933,8 +935,15 @@ int main( void )
933935

934936
switch( DeviceState )
935937
{
936-
case DEVICE_STATE_INIT:
938+
case DEVICE_STATE_RESTORE:
937939
{
940+
// Try to restore from NVM and query the mac if possible.
941+
if( NvmCtxMgmtRestore( ) == NVMCTXMGMT_STATUS_SUCCESS )
942+
{
943+
printf( "\r\n###### ===== CTXS RESTORED ==== ######\r\n\r\n" );
944+
}
945+
else
946+
{
938947
mibReq.Type = MIB_APP_KEY;
939948
mibReq.Param.AppKey = AppKey;
940949
LoRaMacMibSetRequestConfirm( &mibReq );
@@ -987,6 +996,7 @@ int main( void )
987996
mibReq.Param.AppSKey = AppSKey;
988997
LoRaMacMibSetRequestConfirm( &mibReq );
989998
#endif
999+
}
9901000
DeviceState = DEVICE_STATE_START;
9911001
break;
9921002
}
@@ -1130,13 +1140,18 @@ int main( void )
11301140
}
11311141
case DEVICE_STATE_SLEEP:
11321142
{
1143+
if( NvmCtxMgmtStore( ) == NVMCTXMGMT_STATUS_SUCCESS )
1144+
{
1145+
printf( "\r\n###### ===== CTXS STORED ==== ######\r\n" );
1146+
}
1147+
11331148
// Wake up through events
11341149
BoardLowPowerHandler( );
11351150
break;
11361151
}
11371152
default:
11381153
{
1139-
DeviceState = DEVICE_STATE_INIT;
1154+
DeviceState = DEVICE_STATE_START;
11401155
break;
11411156
}
11421157
}

0 commit comments

Comments
 (0)