@@ -182,11 +182,11 @@ static TimerEvent_t LedBeaconTimer;
182182static bool NextTx = true;
183183
184184/*!
185- * Indicates if LoRaMacProcess must be called .
185+ * Indicates if LoRaMacProcess call is pending .
186186 *
187187 * \warning If variable is equal to 0 then the MCU can be set in low power mode
188188 */
189- static uint8_t IsMacProcessRequired = 0 ;
189+ static uint8_t IsMacProcessPending = 0 ;
190190
191191/*!
192192 * Device states
@@ -1197,7 +1197,7 @@ static void MlmeIndication( MlmeIndication_t *mlmeIndication )
11971197
11981198void OnMacProcessNotify ( void )
11991199{
1200- IsMacProcessRequired = 1 ;
1200+ IsMacProcessPending = 1 ;
12011201}
12021202
12031203/**
@@ -1236,15 +1236,8 @@ int main( void )
12361236 {
12371237 Radio .IrqProcess ( );
12381238 }
1239- if ( IsMacProcessRequired == 1 )
1240- {
1241- CRITICAL_SECTION_BEGIN ( );
1242- IsMacProcessRequired = 0 ;
1243- CRITICAL_SECTION_END ( );
1244-
1245- // Processes the LoRaMac events
1246- LoRaMacProcess ( );
1247- }
1239+ // Processes the LoRaMac events
1240+ LoRaMacProcess ( );
12481241
12491242 switch ( DeviceState )
12501243 {
@@ -1521,11 +1514,18 @@ int main( void )
15211514 printf ( "\r\n###### ===== CTXS STORED ==== ######\r\n" );
15221515 }
15231516
1524- if ( IsMacProcessRequired == 0 )
1517+ CRITICAL_SECTION_BEGIN ( );
1518+ if ( IsMacProcessPending == 1 )
15251519 {
1526- // Wake up through events
1520+ // Clear flag and prevent MCU to go into low power modes.
1521+ IsMacProcessPending = 0 ;
1522+ }
1523+ else
1524+ {
1525+ // The MCU wakes up through events
15271526 BoardLowPowerHandler ( );
1528- }
1527+ }
1528+ CRITICAL_SECTION_END ( );
15291529 break ;
15301530 }
15311531 default :
0 commit comments