[radio] make host-rcp time sync be controlled by the posix platform (#10504)

This commit makes `CalcRcpTimeOffset` of `RadioSpinel` into a public
method and call it from system `Process` method instead of making it
default behavior of `RadioSpinel`. This is also to avoid `RadioSpinel`
has a fixed behavior which is decided by
`OPENTHREAD_CONFIG_THREAD_VERSION`.
This commit is contained in:
Li Cao
2024-07-17 10:44:38 -07:00
committed by GitHub
parent 0897b50a27
commit 6f52d78195
3 changed files with 27 additions and 9 deletions
+14 -5
View File
@@ -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
+5 -1
View File
@@ -165,12 +165,14 @@ public:
* @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 @@ private:
void *mVendorRestorePropertiesContext;
#endif
bool mEnableRcpTimeSync;
SpinelDriver *mSpinelDriver;
};
+8 -3
View File
@@ -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);
}