diff --git a/src/lib/spinel/radio_spinel.cpp b/src/lib/spinel/radio_spinel.cpp index 016dd95d26e..ff4819045fd 100644 --- a/src/lib/spinel/radio_spinel.cpp +++ b/src/lib/spinel/radio_spinel.cpp @@ -110,6 +110,7 @@ RadioSpinel::RadioSpinel(void) , mVendorRestorePropertiesCallback(nullptr) , mVendorRestorePropertiesContext(nullptr) #endif + , mEnableRcpTimeSync(false) , mSpinelDriver(nullptr) { memset(&mRadioSpinelMetrics, 0, sizeof(mRadioSpinelMetrics)); @@ -119,7 +120,8 @@ RadioSpinel::RadioSpinel(void) void RadioSpinel::Init(bool aSkipRcpCompatibilityCheck, bool aSoftwareReset, SpinelDriver *aSpinelDriver, - otRadioCaps aRequiredRadioCaps) + otRadioCaps aRequiredRadioCaps, + bool aEnableRcpTimeSync) { otError error = OT_ERROR_NONE; bool supportsRcpApiVersion; @@ -131,6 +133,8 @@ void RadioSpinel::Init(bool aSkipRcpCompatibilityCheck, mResetRadioOnStartup = aSoftwareReset; #endif + mEnableRcpTimeSync = aEnableRcpTimeSync; + mSpinelDriver = aSpinelDriver; mSpinelDriver->SetFrameHandler(&HandleReceivedFrame, &HandleSavedFrame, this); @@ -792,7 +796,11 @@ void RadioSpinel::Process(const void *aContext) ProcessRadioStateMachine(); RecoverFromRcpFailure(); - CalcRcpTimeOffset(); + + if (mEnableRcpTimeSync) + { + CalcRcpTimeOffset(); + } } otError RadioSpinel::SetPromiscuous(bool aEnable) @@ -1843,7 +1851,6 @@ otRadioState RadioSpinel::GetState(void) const void RadioSpinel::CalcRcpTimeOffset(void) { -#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2 otError error = OT_ERROR_NONE; uint64_t localTxTimestamp; uint64_t localRxTimestamp; @@ -1899,7 +1906,6 @@ void RadioSpinel::CalcRcpTimeOffset(void) exit: LogIfFail("Error calculating RCP time offset: %s", error); -#endif // OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2 } uint64_t RadioSpinel::GetNow(void) { return (mIsTimeSynced) ? (otPlatTimeGet() + mRadioTimeOffset) : UINT64_MAX; } @@ -2177,7 +2183,10 @@ void RadioSpinel::RestoreProperties(void) } #endif - CalcRcpTimeOffset(); + if (mEnableRcpTimeSync) + { + CalcRcpTimeOffset(); + } } #endif // OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0 diff --git a/src/lib/spinel/radio_spinel.hpp b/src/lib/spinel/radio_spinel.hpp index 5abc8de439f..eae94b06fcc 100644 --- a/src/lib/spinel/radio_spinel.hpp +++ b/src/lib/spinel/radio_spinel.hpp @@ -165,12 +165,14 @@ class RadioSpinel : private Logger * @param[in] aSpinelDriver A pointer to the spinel driver instance that this object depends on. * @param[in] aRequiredRadioCaps The required radio capabilities. RadioSpinel will check if RCP has * the required capabilities during initiailization. + * @param[in] aEnableRcpTimeSync TRUE to enable RCP time sync, FALSE to not enable. * */ void Init(bool aSkipRcpCompatibilityCheck, bool aSoftwareReset, SpinelDriver *aSpinelDriver, - otRadioCaps aRequiredRadioCaps); + otRadioCaps aRequiredRadioCaps, + bool aEnableRcpTimeSync); /** * This method sets the notification callbacks. @@ -1303,6 +1305,8 @@ class RadioSpinel : private Logger void *mVendorRestorePropertiesContext; #endif + bool mEnableRcpTimeSync; + SpinelDriver *mSpinelDriver; }; diff --git a/src/posix/platform/radio.cpp b/src/posix/platform/radio.cpp index c82b07ebfd1..82551e3113f 100644 --- a/src/posix/platform/radio.cpp +++ b/src/posix/platform/radio.cpp @@ -72,8 +72,13 @@ Radio::Radio(void) void Radio::Init(const char *aUrl) { - bool resetRadio; - bool skipCompatibilityCheck; + bool resetRadio; + bool skipCompatibilityCheck; +#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2 && OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE + bool aEnableRcpTimeSync = true; +#else + bool aEnableRcpTimeSync = false; +#endif struct ot::Spinel::RadioSpinelCallbacks callbacks; mRadioUrl.Init(aUrl); @@ -93,7 +98,7 @@ void Radio::Init(const char *aUrl) skipCompatibilityCheck = mRadioUrl.HasParam("skip-rcp-compatibility-check"); mRadioSpinel.SetCallbacks(callbacks); - mRadioSpinel.Init(skipCompatibilityCheck, resetRadio, &GetSpinelDriver(), kRequiredRadioCaps); + mRadioSpinel.Init(skipCompatibilityCheck, resetRadio, &GetSpinelDriver(), kRequiredRadioCaps, aEnableRcpTimeSync); ProcessRadioUrl(mRadioUrl); }