diff --git a/examples/platforms/nrf528xx/src/radio.c b/examples/platforms/nrf528xx/src/radio.c index 31c17d5c2..172103317 100644 --- a/examples/platforms/nrf528xx/src/radio.c +++ b/examples/platforms/nrf528xx/src/radio.c @@ -472,8 +472,6 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame) nrf5FemEnable(); } - nrf_802154_channel_set(aFrame->mChannel); - #if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2 if (aFrame->mInfo.mTxInfo.mTxDelay != 0) { @@ -486,6 +484,8 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame) else #endif { + nrf_802154_channel_set(aFrame->mChannel); + if (aFrame->mInfo.mTxInfo.mCsmaCaEnabled) { nrf_802154_transmit_csma_ca_raw(&aFrame->mPsdu[-1]); diff --git a/src/core/mac/sub_mac.hpp b/src/core/mac/sub_mac.hpp index b2c1c8ec0..b2036e3a5 100644 --- a/src/core/mac/sub_mac.hpp +++ b/src/core/mac/sub_mac.hpp @@ -532,8 +532,8 @@ private: #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE enum : uint32_t{ - kCslSampleWindow = - OPENTHREAD_CONFIG_CSL_SAMPLE_WINDOW * kUsPerTenSymbols, ///< The SSED sample window in units of 10 symbols. + kCslSampleWindow = OPENTHREAD_CONFIG_CSL_SAMPLE_WINDOW * + kUsPerTenSymbols, ///< The SSED sample window in units of microseconds. kCslReceiveTimeAhead = OPENTHREAD_CONFIG_CSL_RECEIVE_TIME_AHEAD, ///< CSL receivers would wake up `kCslReceiveTimeAhead` earlier ///< than expected sample window. The time is in unit of 10 diff --git a/src/core/thread/csl_tx_scheduler.cpp b/src/core/thread/csl_tx_scheduler.cpp index d81385d68..613003e93 100644 --- a/src/core/thread/csl_tx_scheduler.cpp +++ b/src/core/thread/csl_tx_scheduler.cpp @@ -119,7 +119,6 @@ void CslTxScheduler::Clear(void) */ void CslTxScheduler::RescheduleCslTx(void) { - uint64_t radioNow = otPlatRadioGetNow(&GetInstance()); uint32_t minDelayTime = Time::kMaxDuration; Child * bestChild = nullptr; @@ -133,7 +132,7 @@ void CslTxScheduler::RescheduleCslTx(void) continue; } - delay = GetNextCslTransmissionDelay(child, radioNow, cslTxDelay); + delay = GetNextCslTransmissionDelay(child, cslTxDelay); if (delay < minDelayTime) { @@ -150,19 +149,18 @@ void CslTxScheduler::RescheduleCslTx(void) mCslTxChild = bestChild; } -uint32_t CslTxScheduler::GetNextCslTransmissionDelay(const Child &aChild, - uint64_t aRadioNow, - uint32_t & aDelayFromLastRx) const +uint32_t CslTxScheduler::GetNextCslTransmissionDelay(const Child &aChild, uint32_t &aDelayFromLastRx) const { + uint64_t radioNow = otPlatRadioGetNow(&GetInstance()); uint32_t periodInUs = aChild.GetCslPeriod() * kUsPerTenSymbols; uint64_t firstTxWindow = aChild.GetLastRxTimestamp() + aChild.GetCslPhase() * kUsPerTenSymbols; - uint64_t nextTxWindow = aRadioNow - (aRadioNow % periodInUs) + (firstTxWindow % periodInUs); + uint64_t nextTxWindow = radioNow - (radioNow % periodInUs) + (firstTxWindow % periodInUs); - while (aRadioNow + mCslFrameRequestAheadUs >= nextTxWindow) nextTxWindow += periodInUs; + while (nextTxWindow < radioNow + mCslFrameRequestAheadUs) nextTxWindow += periodInUs; aDelayFromLastRx = static_cast(nextTxWindow - aChild.GetLastRxTimestamp()); - return static_cast(nextTxWindow - aRadioNow - mCslFrameRequestAheadUs); + return static_cast(nextTxWindow - radioNow - mCslFrameRequestAheadUs); } Mac::TxFrame *CslTxScheduler::HandleFrameRequest(Mac::TxFrames &aTxFrames) @@ -207,7 +205,8 @@ Mac::TxFrame *CslTxScheduler::HandleFrameRequest(Mac::TxFrames &aTxFrames) frame->SetChannel(mCslTxChild->GetCslChannel() == 0 ? Get().GetPanChannel() : mCslTxChild->GetCslChannel()); - GetNextCslTransmissionDelay(*mCslTxChild, otPlatRadioGetNow(&GetInstance()), txDelay); + + GetNextCslTransmissionDelay(*mCslTxChild, txDelay); frame->SetTxDelay(txDelay); frame->SetTxDelayBaseTime( static_cast(mCslTxChild->GetLastRxTimestamp())); // Only LSB part of the time is required. diff --git a/src/core/thread/csl_tx_scheduler.hpp b/src/core/thread/csl_tx_scheduler.hpp index 319c59881..645315c63 100644 --- a/src/core/thread/csl_tx_scheduler.hpp +++ b/src/core/thread/csl_tx_scheduler.hpp @@ -193,7 +193,7 @@ private: void InitFrameRequestAhead(void); void RescheduleCslTx(void); - uint32_t GetNextCslTransmissionDelay(const Child &aChild, uint64_t aRadioNow, uint32_t &aDelayFromLastRx) const; + uint32_t GetNextCslTransmissionDelay(const Child &aChild, uint32_t &aDelayFromLastRx) const; // Callbacks from `Mac` Mac::TxFrame *HandleFrameRequest(Mac::TxFrames &aTxFrames);