From f4554e8ff78672e1e448b5572599444ef7d09116 Mon Sep 17 00:00:00 2001 From: Jintao Lin Date: Fri, 27 Nov 2020 00:47:45 +0800 Subject: [PATCH] [low-power] enable CCA sampling before CSL transmission (#5862) CCA should be performed before CSL transmission. This commit enables CCA for CSL transmissions on nRF platform. --- examples/platforms/nrf528xx/src/radio.c | 5 ++--- src/core/config/mac.h | 2 +- src/core/mac/sub_mac.cpp | 5 +++-- src/core/mac/sub_mac.hpp | 11 ++++++----- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/examples/platforms/nrf528xx/src/radio.c b/examples/platforms/nrf528xx/src/radio.c index 76198a675..2911f38ea 100644 --- a/examples/platforms/nrf528xx/src/radio.c +++ b/examples/platforms/nrf528xx/src/radio.c @@ -477,9 +477,8 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame) #if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2 if (aFrame->mInfo.mTxInfo.mTxDelay != 0) { - if (!nrf_802154_transmit_raw_at(&aFrame->mPsdu[-1], aFrame->mInfo.mTxInfo.mCsmaCaEnabled, - aFrame->mInfo.mTxInfo.mTxDelayBaseTime, aFrame->mInfo.mTxInfo.mTxDelay, - aFrame->mChannel)) + if (!nrf_802154_transmit_raw_at(&aFrame->mPsdu[-1], true, aFrame->mInfo.mTxInfo.mTxDelayBaseTime, + aFrame->mInfo.mTxInfo.mTxDelay, aFrame->mChannel)) { error = OT_ERROR_INVALID_STATE; } diff --git a/src/core/config/mac.h b/src/core/config/mac.h index 643286a44..7a87e68c7 100644 --- a/src/core/config/mac.h +++ b/src/core/config/mac.h @@ -403,7 +403,7 @@ * */ #ifndef OPENTHREAD_CONFIG_CSL_RECEIVE_TIME_AHEAD -#define OPENTHREAD_CONFIG_CSL_RECEIVE_TIME_AHEAD 1 +#define OPENTHREAD_CONFIG_CSL_RECEIVE_TIME_AHEAD 2 #endif #endif // CONFIG_MAC_H_ diff --git a/src/core/mac/sub_mac.cpp b/src/core/mac/sub_mac.cpp index a4c32ecc9..10f89ce90 100644 --- a/src/core/mac/sub_mac.cpp +++ b/src/core/mac/sub_mac.cpp @@ -357,9 +357,10 @@ void SubMac::StartCsmaBackoff(void) if (ShouldHandleTransmitTargetTime()) { if (Time(static_cast(otPlatRadioGetNow(&GetInstance()))) < - Time(mTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime) + mTransmitFrame.mInfo.mTxInfo.mTxDelay) + Time(mTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime) + mTransmitFrame.mInfo.mTxInfo.mTxDelay - + kCcaSampleInterval) { - mTimer.StartAt(Time(mTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime), + mTimer.StartAt(Time(mTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime) - kCcaSampleInterval, mTransmitFrame.mInfo.mTxInfo.mTxDelay); } else // Transmit without delay diff --git a/src/core/mac/sub_mac.hpp b/src/core/mac/sub_mac.hpp index db9155aef..98a6c23a0 100644 --- a/src/core/mac/sub_mac.hpp +++ b/src/core/mac/sub_mac.hpp @@ -509,11 +509,12 @@ private: enum { - kMinBE = 3, ///< macMinBE (IEEE 802.15.4-2006). - kMaxBE = 5, ///< macMaxBE (IEEE 802.15.4-2006). - kUnitBackoffPeriod = 20, ///< Number of symbols (IEEE 802.15.4-2006). - kMinBackoff = 1, ///< Minimum backoff (milliseconds). - kAckTimeout = 16, ///< Timeout for waiting on an ACK (milliseconds). + kMinBE = 3, ///< macMinBE (IEEE 802.15.4-2006). + kMaxBE = 5, ///< macMaxBE (IEEE 802.15.4-2006). + kUnitBackoffPeriod = 20, ///< Number of symbols (IEEE 802.15.4-2006). + kMinBackoff = 1, ///< Minimum backoff (milliseconds). + kAckTimeout = 16, ///< Timeout for waiting on an ACK (milliseconds). + kCcaSampleInterval = 128, ///< CCA sample interval, 128 usec. #if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE kEnergyScanRssiSampleInterval = 128, ///< RSSI sample interval during energy scan, 128 usec