Skip to content

Commit bdde3a1

Browse files
committed
Make uses of TimerGetElapsedTime(t) aware of t==0 situation
Unset timestamps typically have value 0. For t==0, TimerGetElapsedTime(t) will return arbitrary values (depending on system uptime and initial system tick value) which might lead to non-intended behavior. These fixes make the case for t==0 explicit, by assuming zero elapsed time.
1 parent 923b905 commit bdde3a1

File tree

11 files changed

+25
-25
lines changed

11 files changed

+25
-25
lines changed

src/mac/region/RegionAS923.c

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

920-
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
921-
if( nextChanParams->AggrTimeOff <= elapsed )
920+
TimerTime_t elapsed = nextChanParams->LastAggrTx==0?0:TimerGetElapsedTime( nextChanParams->LastAggrTx );
921+
if( nextChanParams->LastAggrTx == 0 || nextChanParams->AggrTimeOff <= elapsed )
922922
{
923923
// Reset Aggregated time off
924924
*aggregatedTimeOff = 0;

src/mac/region/RegionAU915.c

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

920-
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
921-
if( nextChanParams->AggrTimeOff <= elapsed )
920+
TimerTime_t elapsed = nextChanParams->LastAggrTx==0?0:TimerGetElapsedTime( nextChanParams->LastAggrTx );
921+
if( nextChanParams->LastAggrTx == 0 || nextChanParams->AggrTimeOff <= elapsed )
922922
{
923923
// Reset Aggregated time off
924924
*aggregatedTimeOff = 0;

src/mac/region/RegionCN470.c

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

737-
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
738-
if( nextChanParams->AggrTimeOff <= elapsed )
737+
TimerTime_t elapsed = nextChanParams->LastAggrTx==0?0:TimerGetElapsedTime( nextChanParams->LastAggrTx );
738+
if( nextChanParams->LastAggrTx == 0 || nextChanParams->AggrTimeOff <= elapsed )
739739
{
740740
// Reset Aggregated time off
741741
*aggregatedTimeOff = 0;

src/mac/region/RegionCN779.c

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

863-
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
864-
if( nextChanParams->AggrTimeOff <= elapsed )
863+
TimerTime_t elapsed = nextChanParams->LastAggrTx==0?0:TimerGetElapsedTime( nextChanParams->LastAggrTx );
864+
if( nextChanParams->LastAggrTx == 0 || nextChanParams->AggrTimeOff <= elapsed )
865865
{
866866
// Reset Aggregated time off
867867
*aggregatedTimeOff = 0;

src/mac/region/RegionCommon.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ TimerTime_t RegionCommonUpdateBandTimeOff( bool joined, bool dutyCycle, Band_t*
169169
{
170170
if( joined == false )
171171
{
172-
TimerTime_t elapsedJoin = TimerGetElapsedTime( bands[i].LastJoinTxDoneTime );
173-
TimerTime_t elapsedTx = TimerGetElapsedTime( bands[i].LastTxDoneTime );
174-
TimerTime_t txDoneTime = MAX( elapsedJoin,
175-
( dutyCycle == true ) ? elapsedTx : 0 );
172+
TimerTime_t elapsed_join = bands[i].LastJoinTxDoneTime==0?0:TimerGetElapsedTime( bands[i].LastJoinTxDoneTime );
173+
TimerTime_t elapsed_tx = bands[i].LastTxDoneTime==0?0:TimerGetElapsedTime( bands[i].LastTxDoneTime );
174+
TimerTime_t txDoneTime = MAX( elapsed_join,
175+
( dutyCycle == true ) ? elapsed_tx : 0 );
176176

177177
if( bands[i].TimeOff <= txDoneTime )
178178
{
@@ -187,7 +187,7 @@ TimerTime_t RegionCommonUpdateBandTimeOff( bool joined, bool dutyCycle, Band_t*
187187
{
188188
if( dutyCycle == true )
189189
{
190-
TimerTime_t elapsed = TimerGetElapsedTime( bands[i].LastTxDoneTime );
190+
TimerTime_t elapsed = bands[i].LastTxDoneTime==0?0:TimerGetElapsedTime( bands[i].LastTxDoneTime );
191191
if( bands[i].TimeOff <= elapsed )
192192
{
193193
bands[i].TimeOff = 0;

src/mac/region/RegionEU433.c

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

863-
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
864-
if( nextChanParams->AggrTimeOff <= elapsed )
863+
TimerTime_t elapsed = nextChanParams->LastAggrTx==0?0:TimerGetElapsedTime( nextChanParams->LastAggrTx );
864+
if( nextChanParams->LastAggrTx == 0 || nextChanParams->AggrTimeOff <= elapsed )
865865
{
866866
// Reset Aggregated time off
867867
*aggregatedTimeOff = 0;

src/mac/region/RegionEU868.c

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

895-
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
896-
if( nextChanParams->AggrTimeOff <= elapsed )
895+
TimerTime_t elapsed = nextChanParams->LastAggrTx==0?0:TimerGetElapsedTime( nextChanParams->LastAggrTx );
896+
if( nextChanParams->LastAggrTx == 0 || nextChanParams->AggrTimeOff <= elapsed )
897897
{
898898
// Reset Aggregated time off
899899
*aggregatedTimeOff = 0;

src/mac/region/RegionIN865.c

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

888-
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
889-
if( nextChanParams->AggrTimeOff <= elapsed )
888+
TimerTime_t elapsed = nextChanParams->LastAggrTx==0?0:TimerGetElapsedTime( nextChanParams->LastAggrTx );
889+
if( nextChanParams->LastAggrTx == 0 || nextChanParams->AggrTimeOff <= elapsed )
890890
{
891891
// Reset Aggregated time off
892892
*aggregatedTimeOff = 0;

src/mac/region/RegionKR920.c

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

857-
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
858-
if( nextChanParams->AggrTimeOff <= elapsed )
857+
TimerTime_t elapsed = nextChanParams->LastAggrTx==0?0:TimerGetElapsedTime( nextChanParams->LastAggrTx );
858+
if( nextChanParams->LastAggrTx == 0 || nextChanParams->AggrTimeOff <= elapsed )
859859
{
860860
// Reset Aggregated time off
861861
*aggregatedTimeOff = 0;

src/mac/region/RegionRU864.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,8 @@ LoRaMacStatus_t RegionRU864NextChannel( NextChanParams_t* nextChanParams, uint8_
856856
NvmCtx.ChannelsMask[0] |= LC( 1 ) + LC( 2 );
857857
}
858858

859-
TimerTime_t elapsed = TimerGetElapsedTime( nextChanParams->LastAggrTx );
860-
if( nextChanParams->AggrTimeOff <= elapsed )
859+
TimerTime_t elapsed = nextChanParams->LastAggrTx==0?0:TimerGetElapsedTime( nextChanParams->LastAggrTx );
860+
if( nextChanParams->LastAggrTx == 0 || nextChanParams->AggrTimeOff <= elapsed )
861861
{
862862
// Reset Aggregated time off
863863
*aggregatedTimeOff = 0;

0 commit comments

Comments
 (0)