From b29b6433d9153b434f3f8e8e5a69d14c745ae2b0 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 22 Nov 2024 16:49:30 -0800 Subject: [PATCH] [radio] add `GetBusSpeed()` and `GetBusLatency()` methods (#10959) This commit adds `GetBusSpeed()` and `GetBusLatency()` methods to the `Radio` class, which map to the corresponding `otPlatRadio` platform APIs. --- src/core/mac/wakeup_tx_scheduler.cpp | 4 ++-- src/core/radio/radio.hpp | 26 ++++++++++++++++++++++++++ src/core/thread/csl_tx_scheduler.cpp | 4 ++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/core/mac/wakeup_tx_scheduler.cpp b/src/core/mac/wakeup_tx_scheduler.cpp index 5c4aa3a75..8d60c2b71 100644 --- a/src/core/mac/wakeup_tx_scheduler.cpp +++ b/src/core/mac/wakeup_tx_scheduler.cpp @@ -158,8 +158,8 @@ void WakeupTxScheduler::UpdateFrameRequestAhead(void) // This is used to make sure that a wake-up frame is received by the radio early enough to be transmitted on time. constexpr uint32_t kWakeupFrameWeight = 100; - uint32_t busSpeedHz = otPlatRadioGetBusSpeed(&GetInstance()); - uint32_t busLatency = otPlatRadioGetBusLatency(&GetInstance()); + uint32_t busSpeedHz = Get().GetBusSpeed(); + uint32_t busLatency = Get().GetBusLatency(); uint32_t busTxTimeUs = ((busSpeedHz == 0) ? 0 : (kWakeupFrameWeight * 8 * 1000000 + busSpeedHz - 1) / busSpeedHz); mTxRequestAheadTimeUs = OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US + busTxTimeUs + busLatency; diff --git a/src/core/radio/radio.hpp b/src/core/radio/radio.hpp index 9943c74c4..d8fef61c9 100644 --- a/src/core/radio/radio.hpp +++ b/src/core/radio/radio.hpp @@ -812,6 +812,24 @@ public: return mask; } + /** + * Get the bus speed in bits/second between the host and the radio chip. + * + * @returns The bus speed in bits/second between the host and the radio chip. + * Return 0 when the MAC and above layer and Radio layer resides on the same chip. + */ + uint32_t GetBusSpeed(void); + + /** + * Get the bus latency in microseconds between the host and the radio chip. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The bus latency in microseconds between the host and the radio chip. + * Return 0 when the MAC and above layer and Radio layer resides on the same chip. + */ + uint32_t GetBusLatency(void); + private: otInstance *GetInstancePtr(void) const { return reinterpret_cast(&InstanceLocator::GetInstance()); } @@ -995,6 +1013,10 @@ inline void Radio::ClearSrcMatchShortEntries(void) { otPlatRadioClearSrcMatchSho inline void Radio::ClearSrcMatchExtEntries(void) { otPlatRadioClearSrcMatchExtEntries(GetInstancePtr()); } +inline uint32_t Radio::GetBusSpeed(void) { return otPlatRadioGetBusSpeed(GetInstancePtr()); } + +inline uint32_t Radio::GetBusLatency(void) { return otPlatRadioGetBusLatency(GetInstancePtr()); } + #else //---------------------------------------------------------------------------------------------------------------- inline otRadioCaps Radio::GetCaps(void) @@ -1095,6 +1117,10 @@ inline void Radio::ClearSrcMatchShortEntries(void) {} inline void Radio::ClearSrcMatchExtEntries(void) {} +inline uint32_t Radio::GetBusSpeed(void) { return 0; } + +inline uint32_t Radio::GetBusLatency(void) { return 0; } + #endif // #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE } // namespace ot diff --git a/src/core/thread/csl_tx_scheduler.cpp b/src/core/thread/csl_tx_scheduler.cpp index edda0427c..ab079bd61 100644 --- a/src/core/thread/csl_tx_scheduler.cpp +++ b/src/core/thread/csl_tx_scheduler.cpp @@ -47,8 +47,8 @@ CslTxScheduler::CslTxScheduler(Instance &aInstance) void CslTxScheduler::UpdateFrameRequestAhead(void) { - uint32_t busSpeedHz = otPlatRadioGetBusSpeed(&GetInstance()); - uint32_t busLatency = otPlatRadioGetBusLatency(&GetInstance()); + uint32_t busSpeedHz = Get().GetBusSpeed(); + uint32_t busLatency = Get().GetBusLatency(); // longest frame on bus is 127 bytes with some metadata, use 150 bytes for bus Tx time estimation uint32_t busTxTimeUs = ((busSpeedHz == 0) ? 0 : (150 * 8 * 1000000 + busSpeedHz - 1) / busSpeedHz);