Skip to content

Commit

Permalink
[radio] make host-rcp time sync be controlled by the posix platform (o…
Browse files Browse the repository at this point in the history
…penthread#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`.
  • Loading branch information
Irving-cl authored Jul 17, 2024
1 parent 0897b50 commit 6f52d78
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
19 changes: 14 additions & 5 deletions src/lib/spinel/radio_spinel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ RadioSpinel::RadioSpinel(void)
, mVendorRestorePropertiesCallback(nullptr)
, mVendorRestorePropertiesContext(nullptr)
#endif
, mEnableRcpTimeSync(false)
, mSpinelDriver(nullptr)
{
memset(&mRadioSpinelMetrics, 0, sizeof(mRadioSpinelMetrics));
Expand All @@ -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;
Expand All @@ -131,6 +133,8 @@ void RadioSpinel::Init(bool aSkipRcpCompatibilityCheck,
mResetRadioOnStartup = aSoftwareReset;
#endif

mEnableRcpTimeSync = aEnableRcpTimeSync;

mSpinelDriver = aSpinelDriver;
mSpinelDriver->SetFrameHandler(&HandleReceivedFrame, &HandleSavedFrame, this);

Expand Down Expand Up @@ -792,7 +796,11 @@ void RadioSpinel::Process(const void *aContext)

ProcessRadioStateMachine();
RecoverFromRcpFailure();
CalcRcpTimeOffset();

if (mEnableRcpTimeSync)
{
CalcRcpTimeOffset();
}
}

otError RadioSpinel::SetPromiscuous(bool aEnable)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -2177,7 +2183,10 @@ void RadioSpinel::RestoreProperties(void)
}
#endif

CalcRcpTimeOffset();
if (mEnableRcpTimeSync)
{
CalcRcpTimeOffset();
}
}
#endif // OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0

Expand Down
6 changes: 5 additions & 1 deletion src/lib/spinel/radio_spinel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1303,6 +1305,8 @@ class RadioSpinel : private Logger
void *mVendorRestorePropertiesContext;
#endif

bool mEnableRcpTimeSync;

SpinelDriver *mSpinelDriver;
};

Expand Down
11 changes: 8 additions & 3 deletions src/posix/platform/radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down

0 comments on commit 6f52d78

Please sign in to comment.