[low-power] small improvements in CSL code (#5939)

- Simplify 'GetNextCslTransmissionDelay'. Remove one unneeded function
  argument.

- For a CSL transmission using 'nrf_802154_transmit_raw_at' there is
  no need for 'nrf_802154_channel_set'.
This commit is contained in:
Eduardo Montoya
2020-12-12 10:58:31 -08:00
committed by GitHub
parent 0c18108100
commit 4e6924ea1d
4 changed files with 13 additions and 14 deletions
+2 -2
View File
@@ -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]);
+2 -2
View File
@@ -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
+8 -9
View File
@@ -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<uint32_t>(nextTxWindow - aChild.GetLastRxTimestamp());
return static_cast<uint32_t>(nextTxWindow - aRadioNow - mCslFrameRequestAheadUs);
return static_cast<uint32_t>(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<Mac::Mac>().GetPanChannel()
: mCslTxChild->GetCslChannel());
GetNextCslTransmissionDelay(*mCslTxChild, otPlatRadioGetNow(&GetInstance()), txDelay);
GetNextCslTransmissionDelay(*mCslTxChild, txDelay);
frame->SetTxDelay(txDelay);
frame->SetTxDelayBaseTime(
static_cast<uint32_t>(mCslTxChild->GetLastRxTimestamp())); // Only LSB part of the time is required.
+1 -1
View File
@@ -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);