Skip to content

Commit 7518bb5

Browse files
committed
Added a critical section protection for Ctx.PingSlotState and Ctx.MulticastSlotState variables update
1 parent 5c49ebc commit 7518bb5

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/mac/LoRaMacClassB.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -672,14 +672,18 @@ void LoRaMacClassBSetBeaconState( BeaconState_t beaconState )
672672
void LoRaMacClassBSetPingSlotState( PingSlotState_t pingSlotState )
673673
{
674674
#ifdef LORAMAC_CLASSB_ENABLED
675+
CRITICAL_SECTION_BEGIN( );
675676
Ctx.PingSlotState = pingSlotState;
677+
CRITICAL_SECTION_END( );
676678
#endif // LORAMAC_CLASSB_ENABLED
677679
}
678680

679681
void LoRaMacClassBSetMulticastSlotState( PingSlotState_t multicastSlotState )
680682
{
681683
#ifdef LORAMAC_CLASSB_ENABLED
684+
CRITICAL_SECTION_BEGIN( );
682685
Ctx.MulticastSlotState = multicastSlotState;
686+
CRITICAL_SECTION_END( );
683687
#endif // LORAMAC_CLASSB_ENABLED
684688
}
685689

@@ -991,7 +995,7 @@ static void LoRaMacClassBProcessPingSlot( void )
991995
*Ctx.LoRaMacClassBParams.LoRaMacDevAddr,
992996
ClassBNvm->PingSlotCtx.PingPeriod,
993997
&( Ctx.PingSlotCtx.PingOffset ) );
994-
Ctx.PingSlotState = PINGSLOT_STATE_SET_TIMER;
998+
LoRaMacClassBSetPingSlotState( PINGSLOT_STATE_SET_TIMER );
995999
}
9961000
// Intentional fall through
9971001
case PINGSLOT_STATE_SET_TIMER:
@@ -1021,7 +1025,7 @@ static void LoRaMacClassBProcessPingSlot( void )
10211025
}
10221026

10231027
// Start the timer if the ping slot time is in range
1024-
Ctx.PingSlotState = PINGSLOT_STATE_IDLE;
1028+
LoRaMacClassBSetPingSlotState( PINGSLOT_STATE_IDLE );
10251029
TimerSetValue( &Ctx.PingSlotTimer, pingSlotTime );
10261030
TimerStart( &Ctx.PingSlotTimer );
10271031
}
@@ -1054,12 +1058,12 @@ static void LoRaMacClassBProcessPingSlot( void )
10541058
{
10551059
// Close multicast slot window, if necessary. Multicast slots have priority
10561060
Radio.Standby( );
1057-
Ctx.MulticastSlotState = PINGSLOT_STATE_CALC_PING_OFFSET;
1061+
LoRaMacClassBSetMulticastSlotState( PINGSLOT_STATE_CALC_PING_OFFSET );
10581062
TimerSetValue( &Ctx.MulticastSlotTimer, CLASSB_PING_SLOT_WINDOW );
10591063
TimerStart( &Ctx.MulticastSlotTimer );
10601064
}
10611065

1062-
Ctx.PingSlotState = PINGSLOT_STATE_RX;
1066+
LoRaMacClassBSetPingSlotState( PINGSLOT_STATE_RX );
10631067

10641068
pingSlotRxConfig.Datarate = ClassBNvm->PingSlotCtx.Datarate;
10651069
pingSlotRxConfig.DownlinkDwellTime = Ctx.LoRaMacClassBParams.LoRaMacParams->DownlinkDwellTime;
@@ -1082,15 +1086,15 @@ static void LoRaMacClassBProcessPingSlot( void )
10821086
else
10831087
{
10841088
// Multicast slots have priority. Skip Rx
1085-
Ctx.PingSlotState = PINGSLOT_STATE_CALC_PING_OFFSET;
1089+
LoRaMacClassBSetPingSlotState( PINGSLOT_STATE_CALC_PING_OFFSET );
10861090
TimerSetValue( &Ctx.PingSlotTimer, CLASSB_PING_SLOT_WINDOW );
10871091
TimerStart( &Ctx.PingSlotTimer );
10881092
}
10891093
break;
10901094
}
10911095
default:
10921096
{
1093-
Ctx.PingSlotState = PINGSLOT_STATE_CALC_PING_OFFSET;
1097+
LoRaMacClassBSetPingSlotState( PINGSLOT_STATE_CALC_PING_OFFSET );
10941098
break;
10951099
}
10961100
}
@@ -1143,7 +1147,7 @@ static void LoRaMacClassBProcessMulticastSlot( void )
11431147
}
11441148
cur++;
11451149
}
1146-
Ctx.MulticastSlotState = PINGSLOT_STATE_SET_TIMER;
1150+
LoRaMacClassBSetMulticastSlotState( PINGSLOT_STATE_SET_TIMER );
11471151
}
11481152
// Intentional fall through
11491153
case PINGSLOT_STATE_SET_TIMER:
@@ -1194,7 +1198,7 @@ static void LoRaMacClassBProcessMulticastSlot( void )
11941198
}
11951199

11961200
// Start the timer if the ping slot time is in range
1197-
Ctx.MulticastSlotState = PINGSLOT_STATE_IDLE;
1201+
LoRaMacClassBSetMulticastSlotState( PINGSLOT_STATE_IDLE );
11981202
TimerSetValue( &Ctx.MulticastSlotTimer, multicastSlotTime );
11991203
TimerStart( &Ctx.MulticastSlotTimer );
12001204
}
@@ -1207,7 +1211,7 @@ static void LoRaMacClassBProcessMulticastSlot( void )
12071211
// Verify if the multicast channel is valid
12081212
if( Ctx.PingSlotCtx.NextMulticastChannel == NULL )
12091213
{
1210-
Ctx.MulticastSlotState = PINGSLOT_STATE_CALC_PING_OFFSET;
1214+
LoRaMacClassBSetMulticastSlotState( PINGSLOT_STATE_CALC_PING_OFFSET );
12111215
TimerSetValue( &Ctx.MulticastSlotTimer, 1 );
12121216
TimerStart( &Ctx.MulticastSlotTimer );
12131217
break;
@@ -1236,12 +1240,12 @@ static void LoRaMacClassBProcessMulticastSlot( void )
12361240
{
12371241
// Close ping slot window, if necessary. Multicast slots have priority
12381242
Radio.Standby( );
1239-
Ctx.PingSlotState = PINGSLOT_STATE_CALC_PING_OFFSET;
1243+
LoRaMacClassBSetPingSlotState( PINGSLOT_STATE_CALC_PING_OFFSET );
12401244
TimerSetValue( &Ctx.PingSlotTimer, CLASSB_PING_SLOT_WINDOW );
12411245
TimerStart( &Ctx.PingSlotTimer );
12421246
}
12431247

1244-
Ctx.MulticastSlotState = PINGSLOT_STATE_RX;
1248+
LoRaMacClassBSetMulticastSlotState( PINGSLOT_STATE_RX );
12451249

12461250
multicastSlotRxConfig.Datarate = Ctx.PingSlotCtx.NextMulticastChannel->ChannelParams.RxParams.Params.ClassB.Datarate;
12471251
multicastSlotRxConfig.DownlinkDwellTime = Ctx.LoRaMacClassBParams.LoRaMacParams->DownlinkDwellTime;
@@ -1264,15 +1268,15 @@ static void LoRaMacClassBProcessMulticastSlot( void )
12641268
else
12651269
{
12661270
// Unicast slots have priority. Skip Rx
1267-
Ctx.MulticastSlotState = PINGSLOT_STATE_CALC_PING_OFFSET;
1271+
LoRaMacClassBSetMulticastSlotState( PINGSLOT_STATE_CALC_PING_OFFSET );
12681272
TimerSetValue( &Ctx.MulticastSlotTimer, CLASSB_PING_SLOT_WINDOW );
12691273
TimerStart( &Ctx.MulticastSlotTimer );
12701274
}
12711275
break;
12721276
}
12731277
default:
12741278
{
1275-
Ctx.MulticastSlotState = PINGSLOT_STATE_CALC_PING_OFFSET;
1279+
LoRaMacClassBSetMulticastSlotState( PINGSLOT_STATE_CALC_PING_OFFSET );
12761280
break;
12771281
}
12781282
}
@@ -1788,11 +1792,11 @@ void LoRaMacClassBStartRxSlots( void )
17881792
#ifdef LORAMAC_CLASSB_ENABLED
17891793
if( ClassBNvm->PingSlotCtx.Ctrl.Assigned == 1 )
17901794
{
1791-
Ctx.PingSlotState = PINGSLOT_STATE_CALC_PING_OFFSET;
1795+
LoRaMacClassBSetPingSlotState( PINGSLOT_STATE_CALC_PING_OFFSET );
17921796
TimerSetValue( &Ctx.PingSlotTimer, 1 );
17931797
TimerStart( &Ctx.PingSlotTimer );
17941798

1795-
Ctx.MulticastSlotState = PINGSLOT_STATE_CALC_PING_OFFSET;
1799+
LoRaMacClassBSetMulticastSlotState( PINGSLOT_STATE_CALC_PING_OFFSET );
17961800
TimerSetValue( &Ctx.MulticastSlotTimer, 1 );
17971801
TimerStart( &Ctx.MulticastSlotTimer );
17981802
}

0 commit comments

Comments
 (0)