From d0fbfb8c768eae85d6bf5099bd8129db1c0a94b1 Mon Sep 17 00:00:00 2001 From: Zhanglong Xia Date: Tue, 23 Jul 2024 00:56:54 +0800 Subject: [PATCH] [sub-mac] use relative time when starting CSL TX delay (#10525) The original code uses the absolute time when staring the CSL TX delay in `SubMac`. The timer is a `MicroTimer` and the absolute time comes from the `mTxDelayBaseTime`. The `mTxDelayBaseTime` comes from the radio time `otPlatRadioGetNow ()`, the time of `MicroTimer` should come from `otPlatAlarmMicroGetNow()`. If the `MicroTimer` and the radio are using different timer sources, it will cause the unexpected issue. This commit use the relative time when starting CSL TX delay to fix this issue. --- src/core/mac/sub_mac.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/mac/sub_mac.cpp b/src/core/mac/sub_mac.cpp index dcd0f444b..94916f6d7 100644 --- a/src/core/mac/sub_mac.cpp +++ b/src/core/mac/sub_mac.cpp @@ -396,12 +396,13 @@ void SubMac::StartCsmaBackoff(void) { static constexpr uint32_t kAheadTime = kCcaSampleInterval + kCslTransmitTimeAhead + kRadioHeaderShrDuration; Time txStartTime = Time(mTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime); + Time radioNow = Time(static_cast(otPlatRadioGetNow(&GetInstance()))); txStartTime += (mTransmitFrame.mInfo.mTxInfo.mTxDelay - kAheadTime); - if (Time(static_cast(otPlatRadioGetNow(&GetInstance()))) < txStartTime) + if (radioNow < txStartTime) { - mTimer.FireAt(txStartTime); + StartTimer(txStartTime - radioNow); } else // Transmit without delay {