mirror of
https://github.com/espressif/openthread.git
synced 2026-08-05 02:17:47 +00:00
[sub-mac] fix elapsed time in GetCslWindowEdges() (#7299)
Do all the calculations on uint32_t to prevent bad wraparound check due to mixing uint32_t with uint64_t. Signed-off-by: George Stefan <[email protected]>
This commit is contained in:
@@ -1131,20 +1131,13 @@ void SubMac::HandleCslTimer(void)
|
||||
void SubMac::GetCslWindowEdges(uint32_t &ahead, uint32_t &after)
|
||||
{
|
||||
uint32_t semiPeriod = mCslPeriod * kUsPerTenSymbols / 2;
|
||||
uint64_t curTime = otPlatRadioGetNow(&GetInstance());
|
||||
uint64_t elapsed;
|
||||
uint32_t curTime = static_cast<uint32_t>(otPlatRadioGetNow(&GetInstance()));
|
||||
uint32_t elapsed;
|
||||
uint32_t semiWindow;
|
||||
|
||||
if (mCslLastSync.GetValue() > curTime)
|
||||
{
|
||||
elapsed = UINT64_MAX - mCslLastSync.GetValue() + curTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
elapsed = curTime - mCslLastSync.GetValue();
|
||||
}
|
||||
elapsed = curTime - mCslLastSync.GetValue();
|
||||
|
||||
semiWindow = static_cast<uint32_t>(elapsed * (Get<Radio>().GetCslAccuracy() + mCslParentAccuracy) / 1000000);
|
||||
semiWindow = elapsed * (Get<Radio>().GetCslAccuracy() + mCslParentAccuracy) / 1000000;
|
||||
semiWindow += mCslParentUncert * kUsPerUncertUnit;
|
||||
|
||||
ahead = (semiWindow + kCslReceiveTimeAhead > semiPeriod) ? semiPeriod : semiWindow + kCslReceiveTimeAhead;
|
||||
|
||||
Reference in New Issue
Block a user