From 944a25a5be9acc0bfb4aa34eeda6306fe6a465cc Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Wed, 16 Oct 2024 00:17:11 +0800 Subject: [PATCH] [time-sync] correct the time sync base to radio time (#10825) The network time offset is computed based on the coprocessor time instead of the host time. --- src/core/radio/radio.hpp | 9 ++++++--- src/core/thread/time_sync_service.cpp | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/radio/radio.hpp b/src/core/radio/radio.hpp index 114be2913..5cd35b427 100644 --- a/src/core/radio/radio.hpp +++ b/src/core/radio/radio.hpp @@ -528,7 +528,8 @@ public: Error ResetCsl(void); #endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE -#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE +#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE || \ + OPENTHREAD_CONFIG_TIME_SYNC_ENABLE /** * Get the current radio time in microseconds referenced to a continuous monotonic local radio clock (64 bits * width). @@ -940,7 +941,8 @@ inline Error Radio::EnableCsl(uint32_t aCslPeriod, otShortAddress aShortAddr, co inline Error Radio::ResetCsl(void) { return otPlatRadioResetCsl(GetInstancePtr()); } #endif -#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE +#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE || \ + OPENTHREAD_CONFIG_TIME_SYNC_ENABLE inline uint64_t Radio::GetNow(void) { return otPlatRadioGetNow(GetInstancePtr()); } inline uint8_t Radio::GetCslAccuracy(void) { return otPlatRadioGetCslAccuracy(GetInstancePtr()); } @@ -1050,7 +1052,8 @@ inline Error Radio::EnableCsl(uint32_t, otShortAddress aShortAddr, const otExtAd inline Error Radio::ResetCsl(void) { return kErrorNotImplemented; } #endif -#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE +#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE || \ + OPENTHREAD_CONFIG_TIME_SYNC_ENABLE inline uint64_t Radio::GetNow(void) { return NumericLimits::kMax; } inline uint8_t Radio::GetCslAccuracy(void) { return NumericLimits::kMax; } diff --git a/src/core/thread/time_sync_service.cpp b/src/core/thread/time_sync_service.cpp index df3572d14..8b2f4d2ad 100644 --- a/src/core/thread/time_sync_service.cpp +++ b/src/core/thread/time_sync_service.cpp @@ -64,7 +64,7 @@ TimeSync::TimeSync(Instance &aInstance) TimeSync::Status TimeSync::GetTime(uint64_t &aNetworkTime) const { - aNetworkTime = static_cast(static_cast(otPlatTimeGet()) + mNetworkTimeOffset); + aNetworkTime = static_cast(static_cast(Get().GetNow()) + mNetworkTimeOffset); return mCurrentStatus; }