Skip to content

Commit

Permalink
[csl] use host time for counting CSL synchronization elapsed time
Browse files Browse the repository at this point in the history
Limit periodic radio API calls to `otPlatRadioGetNow` in order to save power.

The impact of the error in the receive window duration calculation is small
compared with the power consumption savings obtained with the reduction of
radio API calls in serialized platforms.
  • Loading branch information
edmont committed Oct 27, 2023
1 parent 1528c88 commit 550d05d
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/core/mac/sub_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void SubMac::HandleReceiveDone(RxFrame *aFrame, Error aError)
// Assuming the risk of the parent missing the Enh-ACK in favor of smaller CSL receive window
if ((mCslPeriod > 0) && aFrame->mInfo.mRxInfo.mAckedWithSecEnhAck)
{
mCslLastSync = TimeMicro(static_cast<uint32_t>(aFrame->mInfo.mRxInfo.mTimestamp));
mCslLastSync = ot::TimerMicro::GetNow();
}
}
#endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
Expand Down Expand Up @@ -611,11 +611,11 @@ void SubMac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, Error aErro
mCallbacks.RecordCcaStatus(ccaSuccess, aFrame.GetChannel());
}
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
// Actual synchronization timestamp should be from the sent frame instead of the current time.
// Actual synchronization timestamp should be from the sent frame instead of the current local time.
// Assuming the error here since it is bounded and has very small effect on the final window duration.
if (mCslPeriod > 0)
if (aAckFrame != nullptr && aFrame.GetHeaderIe(CslIe::kHeaderIeId) != nullptr)
{
mCslLastSync = TimeMicro(static_cast<uint32_t>(otPlatRadioGetNow(&GetInstance())));
mCslLastSync = ot::TimerMicro::GetNow();
}
#endif
break;
Expand Down Expand Up @@ -1231,13 +1231,10 @@ void SubMac::HandleCslTimer(void)

void SubMac::GetCslWindowEdges(uint32_t &aAhead, uint32_t &aAfter)
{
uint32_t elapsed = ot::TimerMicro::GetNow() - mCslLastSync;
uint32_t semiPeriod = mCslPeriod * kUsPerTenSymbols / 2;
uint32_t curTime = static_cast<uint32_t>(otPlatRadioGetNow(&GetInstance()));
uint32_t elapsed;
uint32_t semiWindow;

elapsed = curTime - mCslLastSync.GetValue();

semiWindow =
static_cast<uint32_t>(static_cast<uint64_t>(elapsed) *
(Get<Radio>().GetCslAccuracy() + mCslParentAccuracy.GetClockAccuracy()) / 1000000);
Expand Down

0 comments on commit 550d05d

Please sign in to comment.