Skip to content

Commit cbde060

Browse files
authored
Merge pull request #602 from thingsconnected/pullreq1
Fixed TimerGetElapsedTime race conditions
2 parents 3c68c3f + 13982ff commit cbde060

File tree

11 files changed

+33
-23
lines changed

11 files changed

+33
-23
lines changed

src/mac/region/RegionAS923.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,8 @@ LoRaMacStatus_t RegionAS923NextChannel( NextChanParams_t* nextChanParams, uint8_
917917
NvmCtx.ChannelsMask[0] |= LC( 1 ) + LC( 2 );
918918
}
919919

920-
if( nextChanParams->AggrTimeOff <= TimerGetElapsedTime( nextChanParams->LastAggrTx ) )
920+
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
921+
if( nextChanParams->AggrTimeOff <= elapsed )
921922
{
922923
// Reset Aggregated time off
923924
*aggregatedTimeOff = 0;
@@ -933,7 +934,7 @@ LoRaMacStatus_t RegionAS923NextChannel( NextChanParams_t* nextChanParams, uint8_
933934
else
934935
{
935936
delayTx++;
936-
nextTxDelay = nextChanParams->AggrTimeOff - TimerGetElapsedTime( nextChanParams->LastAggrTx );
937+
nextTxDelay = nextChanParams->AggrTimeOff - elapsed;
937938
}
938939

939940
if( nbEnabledChannels > 0 )

src/mac/region/RegionAU915.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,8 @@ LoRaMacStatus_t RegionAU915NextChannel( NextChanParams_t* nextChanParams, uint8_
917917
}
918918
}
919919

920-
if( nextChanParams->AggrTimeOff <= TimerGetElapsedTime( nextChanParams->LastAggrTx ) )
920+
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
921+
if( nextChanParams->AggrTimeOff <= elapsed )
921922
{
922923
// Reset Aggregated time off
923924
*aggregatedTimeOff = 0;
@@ -933,7 +934,7 @@ LoRaMacStatus_t RegionAU915NextChannel( NextChanParams_t* nextChanParams, uint8_
933934
else
934935
{
935936
delayTx++;
936-
nextTxDelay = nextChanParams->AggrTimeOff - TimerGetElapsedTime( nextChanParams->LastAggrTx );
937+
nextTxDelay = nextChanParams->AggrTimeOff - elapsed;
937938
}
938939

939940
if( nbEnabledChannels > 0 )

src/mac/region/RegionCN470.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,8 @@ LoRaMacStatus_t RegionCN470NextChannel( NextChanParams_t* nextChanParams, uint8_
734734
NvmCtx.ChannelsMask[5] = 0xFFFF;
735735
}
736736

737-
if( nextChanParams->AggrTimeOff <= TimerGetElapsedTime( nextChanParams->LastAggrTx ) )
737+
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
738+
if( nextChanParams->AggrTimeOff <= elapsed )
738739
{
739740
// Reset Aggregated time off
740741
*aggregatedTimeOff = 0;
@@ -750,7 +751,7 @@ LoRaMacStatus_t RegionCN470NextChannel( NextChanParams_t* nextChanParams, uint8_
750751
else
751752
{
752753
delayTx++;
753-
nextTxDelay = nextChanParams->AggrTimeOff - TimerGetElapsedTime( nextChanParams->LastAggrTx );
754+
nextTxDelay = nextChanParams->AggrTimeOff - elapsed;
754755
}
755756

756757
if( nbEnabledChannels > 0 )

src/mac/region/RegionCN779.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,8 @@ LoRaMacStatus_t RegionCN779NextChannel( NextChanParams_t* nextChanParams, uint8_
860860
NvmCtx.ChannelsMask[0] |= LC( 1 ) + LC( 2 ) + LC( 3 );
861861
}
862862

863-
if( nextChanParams->AggrTimeOff <= TimerGetElapsedTime( nextChanParams->LastAggrTx ) )
863+
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
864+
if( nextChanParams->AggrTimeOff <= elapsed )
864865
{
865866
// Reset Aggregated time off
866867
*aggregatedTimeOff = 0;
@@ -876,7 +877,7 @@ LoRaMacStatus_t RegionCN779NextChannel( NextChanParams_t* nextChanParams, uint8_
876877
else
877878
{
878879
delayTx++;
879-
nextTxDelay = nextChanParams->AggrTimeOff - TimerGetElapsedTime( nextChanParams->LastAggrTx );
880+
nextTxDelay = nextChanParams->AggrTimeOff - elapsed;
880881
}
881882

882883
if( nbEnabledChannels > 0 )

src/mac/region/RegionCommon.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ TimerTime_t RegionCommonUpdateBandTimeOff( bool joined, bool dutyCycle, Band_t*
185185
{
186186
if( dutyCycle == true )
187187
{
188-
if( bands[i].TimeOff <= TimerGetElapsedTime( bands[i].LastTxDoneTime ) )
188+
TimerTime_t elapsed = TimerGetElapsedTime( bands[i].LastTxDoneTime );
189+
if( bands[i].TimeOff <= elapsed )
189190
{
190191
bands[i].TimeOff = 0;
191192
}
192193
if( bands[i].TimeOff != 0 )
193194
{
194-
nextTxDelay = MIN( bands[i].TimeOff - TimerGetElapsedTime( bands[i].LastTxDoneTime ),
195-
nextTxDelay );
195+
nextTxDelay = MIN( bands[i].TimeOff - elapsed, nextTxDelay );
196196
}
197197
}
198198
else

src/mac/region/RegionEU433.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,8 @@ LoRaMacStatus_t RegionEU433NextChannel( NextChanParams_t* nextChanParams, uint8_
860860
NvmCtx.ChannelsMask[0] |= LC( 1 ) + LC( 2 ) + LC( 3 );
861861
}
862862

863-
if( nextChanParams->AggrTimeOff <= TimerGetElapsedTime( nextChanParams->LastAggrTx ) )
863+
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
864+
if( nextChanParams->AggrTimeOff <= elapsed )
864865
{
865866
// Reset Aggregated time off
866867
*aggregatedTimeOff = 0;
@@ -876,7 +877,7 @@ LoRaMacStatus_t RegionEU433NextChannel( NextChanParams_t* nextChanParams, uint8_
876877
else
877878
{
878879
delayTx++;
879-
nextTxDelay = nextChanParams->AggrTimeOff - TimerGetElapsedTime( nextChanParams->LastAggrTx );
880+
nextTxDelay = nextChanParams->AggrTimeOff - elapsed;
880881
}
881882

882883
if( nbEnabledChannels > 0 )

src/mac/region/RegionEU868.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,8 @@ LoRaMacStatus_t RegionEU868NextChannel( NextChanParams_t* nextChanParams, uint8_
892892
NvmCtx.ChannelsMask[0] |= LC( 1 ) + LC( 2 ) + LC( 3 );
893893
}
894894

895-
if( nextChanParams->AggrTimeOff <= TimerGetElapsedTime( nextChanParams->LastAggrTx ) )
895+
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
896+
if( nextChanParams->AggrTimeOff <= elapsed )
896897
{
897898
// Reset Aggregated time off
898899
*aggregatedTimeOff = 0;
@@ -908,7 +909,7 @@ LoRaMacStatus_t RegionEU868NextChannel( NextChanParams_t* nextChanParams, uint8_
908909
else
909910
{
910911
delayTx++;
911-
nextTxDelay = nextChanParams->AggrTimeOff - TimerGetElapsedTime( nextChanParams->LastAggrTx );
912+
nextTxDelay = nextChanParams->AggrTimeOff - elapsed;
912913
}
913914

914915
if( nbEnabledChannels > 0 )

src/mac/region/RegionIN865.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,8 @@ LoRaMacStatus_t RegionIN865NextChannel( NextChanParams_t* nextChanParams, uint8_
885885
NvmCtx.ChannelsMask[0] |= LC( 1 ) + LC( 2 ) + LC( 3 );
886886
}
887887

888-
if( nextChanParams->AggrTimeOff <= TimerGetElapsedTime( nextChanParams->LastAggrTx ) )
888+
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
889+
if( nextChanParams->AggrTimeOff <= elapsed )
889890
{
890891
// Reset Aggregated time off
891892
*aggregatedTimeOff = 0;
@@ -901,7 +902,7 @@ LoRaMacStatus_t RegionIN865NextChannel( NextChanParams_t* nextChanParams, uint8_
901902
else
902903
{
903904
delayTx++;
904-
nextTxDelay = nextChanParams->AggrTimeOff - TimerGetElapsedTime( nextChanParams->LastAggrTx );
905+
nextTxDelay = nextChanParams->AggrTimeOff - elapsed;
905906
}
906907

907908
if( nbEnabledChannels > 0 )

src/mac/region/RegionKR920.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,8 @@ LoRaMacStatus_t RegionKR920NextChannel( NextChanParams_t* nextChanParams, uint8_
854854
NvmCtx.ChannelsMask[0] |= LC( 1 ) + LC( 2 ) + LC( 3 );
855855
}
856856

857-
if( nextChanParams->AggrTimeOff <= TimerGetElapsedTime( nextChanParams->LastAggrTx ) )
857+
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
858+
if( nextChanParams->AggrTimeOff <= elapsed )
858859
{
859860
// Reset Aggregated time off
860861
*aggregatedTimeOff = 0;
@@ -870,7 +871,7 @@ LoRaMacStatus_t RegionKR920NextChannel( NextChanParams_t* nextChanParams, uint8_
870871
else
871872
{
872873
delayTx++;
873-
nextTxDelay = nextChanParams->AggrTimeOff - TimerGetElapsedTime( nextChanParams->LastAggrTx );
874+
nextTxDelay = nextChanParams->AggrTimeOff - elapsed;
874875
}
875876

876877
if( nbEnabledChannels > 0 )

src/mac/region/RegionRU864.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,8 @@ LoRaMacStatus_t RegionRU864NextChannel( NextChanParams_t* nextChanParams, uint8_
851851
NvmCtx.ChannelsMask[0] |= LC( 1 ) + LC( 2 );
852852
}
853853

854-
if( nextChanParams->AggrTimeOff <= TimerGetElapsedTime( nextChanParams->LastAggrTx ) )
854+
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
855+
if( nextChanParams->AggrTimeOff <= elapsed )
855856
{
856857
// Reset Aggregated time off
857858
*aggregatedTimeOff = 0;
@@ -867,7 +868,7 @@ LoRaMacStatus_t RegionRU864NextChannel( NextChanParams_t* nextChanParams, uint8_
867868
else
868869
{
869870
delayTx++;
870-
nextTxDelay = nextChanParams->AggrTimeOff - TimerGetElapsedTime( nextChanParams->LastAggrTx );
871+
nextTxDelay = nextChanParams->AggrTimeOff - elapsed;
871872
}
872873

873874
if( nbEnabledChannels > 0 )

0 commit comments

Comments
 (0)