From b8f305b825644818790240b9931ddb6d7dd19de9 Mon Sep 17 00:00:00 2001 From: Eduardo Montoya Date: Thu, 12 May 2022 00:57:55 +0200 Subject: [PATCH] [spinel] add CSL Accuracy and CSL Uncertainty properties (#7638) Allow the host to get CSL Accuracy and CSL Uncertainty from the RCP. --- .../config/openthread-core-config-check.h | 4 ++++ src/core/config/platform.h | 10 -------- src/core/radio/radio.hpp | 2 ++ src/core/radio/radio_platform.cpp | 2 +- src/lib/spinel/radio_spinel.hpp | 22 +++++++++++++++++ src/lib/spinel/radio_spinel_impl.hpp | 24 +++++++++++++++++++ src/lib/spinel/spinel.c | 2 ++ src/lib/spinel/spinel.h | 20 +++++++++++++++- src/ncp/ncp_base.cpp | 14 +++++++++++ src/ncp/ncp_base_dispatcher.cpp | 6 +++++ src/posix/platform/radio.cpp | 14 ++++++++++- 11 files changed, 107 insertions(+), 13 deletions(-) diff --git a/src/core/config/openthread-core-config-check.h b/src/core/config/openthread-core-config-check.h index d7975d8cb..ed8495aaa 100644 --- a/src/core/config/openthread-core-config-check.h +++ b/src/core/config/openthread-core-config-check.h @@ -619,4 +619,8 @@ "SRP host uses dynamic heap array to store addresses so no need for config on max number of addresses". #endif +#ifdef OPENTHREAD_CONFIG_PLATFORM_CSL_UNCERT +#error "OPENTHREAD_CONFIG_PLATFORM_CSL_UNCERT was removed and no longer supported" +#endif + #endif // OPENTHREAD_CORE_CONFIG_CHECK_H_ diff --git a/src/core/config/platform.h b/src/core/config/platform.h index ff47f11e4..ca132dbae 100644 --- a/src/core/config/platform.h +++ b/src/core/config/platform.h @@ -176,14 +176,4 @@ #endif #endif -/** - * @def OPENTHREAD_CONFIG_PLATFORM_CSL_UNCERT - * - * The Uncertainty of the scheduling CSL of transmission by the parent, in ±10 us units. - * - */ -#ifndef OPENTHREAD_CONFIG_PLATFORM_CSL_UNCERT -#define OPENTHREAD_CONFIG_PLATFORM_CSL_UNCERT UINT8_MAX -#endif - #endif // CONFIG_PLATFORM_H_ diff --git a/src/core/radio/radio.hpp b/src/core/radio/radio.hpp index 2e2ef8893..d82a8b867 100644 --- a/src/core/radio/radio.hpp +++ b/src/core/radio/radio.hpp @@ -809,7 +809,9 @@ inline uint8_t Radio::GetCslAccuracy(void) { return otPlatRadioGetCslAccuracy(GetInstancePtr()); } +#endif +#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE inline uint8_t Radio::GetCslClockUncertainty(void) { return otPlatRadioGetCslClockUncertainty(GetInstancePtr()); diff --git a/src/core/radio/radio_platform.cpp b/src/core/radio/radio_platform.cpp index 87ec5e6e2..877de44bd 100644 --- a/src/core/radio/radio_platform.cpp +++ b/src/core/radio/radio_platform.cpp @@ -254,7 +254,7 @@ OT_TOOL_WEAK uint8_t otPlatRadioGetCslClockUncertainty(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); - return OPENTHREAD_CONFIG_PLATFORM_CSL_UNCERT; + return UINT8_MAX; } OT_TOOL_WEAK otError otPlatRadioGetFemLnaGain(otInstance *aInstance, int8_t *aGain) diff --git a/src/lib/spinel/radio_spinel.hpp b/src/lib/spinel/radio_spinel.hpp index c047dc894..bfa1a18b3 100644 --- a/src/lib/spinel/radio_spinel.hpp +++ b/src/lib/spinel/radio_spinel.hpp @@ -701,6 +701,28 @@ public: const otExtAddress & aExtAddress); #endif +#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE + /** + * Get the current accuracy, in units of ± ppm, of the clock used for scheduling CSL operations. + * + * @note Platforms may optimize this value based on operational conditions (i.e.: temperature). + * + * @retval The current CSL rx/tx scheduling drift, in units of ± ppm. + * + */ + uint8_t GetCslAccuracy(void); +#endif + +#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE + /** + * Get the current uncertainty, in units of 10 us, of the clock used for scheduling CSL operations. + * + * @retval The current CSL Clock Uncertainty in units of 10 us. + * + */ + uint8_t GetCslUncertainty(void); +#endif + /** * This method checks whether the spinel interface is radio-only. * diff --git a/src/lib/spinel/radio_spinel_impl.hpp b/src/lib/spinel/radio_spinel_impl.hpp index d5da5ba42..c6c02e288 100644 --- a/src/lib/spinel/radio_spinel_impl.hpp +++ b/src/lib/spinel/radio_spinel_impl.hpp @@ -2461,5 +2461,29 @@ otError RadioSpinel::ConfigureEnhAckProbing(o } #endif +#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE +template +uint8_t RadioSpinel::GetCslAccuracy(void) +{ + uint8_t accuracy = UINT8_MAX; + otError error = Get(SPINEL_PROP_RCP_CSL_ACCURACY, SPINEL_DATATYPE_UINT8_S, &accuracy); + + LogIfFail("Get CSL Accuracy failed", error); + return accuracy; +} +#endif + +#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE +template +uint8_t RadioSpinel::GetCslUncertainty(void) +{ + uint8_t uncertainty = UINT8_MAX; + otError error = Get(SPINEL_PROP_RCP_CSL_UNCERTAINTY, SPINEL_DATATYPE_UINT8_S, &uncertainty); + + LogIfFail("Get CSL Uncertainty failed", error); + return uncertainty; +} +#endif + } // namespace Spinel } // namespace ot diff --git a/src/lib/spinel/spinel.c b/src/lib/spinel/spinel.c index 726ca3e30..190381db5 100644 --- a/src/lib/spinel/spinel.c +++ b/src/lib/spinel/spinel.c @@ -1401,6 +1401,8 @@ const char *spinel_prop_key_to_cstr(spinel_prop_key_t prop_key) {SPINEL_PROP_CHILD_SUPERVISION_CHECK_TIMEOUT, "CHILD_SUPERVISION_CHECK_TIMEOUT"}, {SPINEL_PROP_RCP_VERSION, "RCP_VERSION"}, {SPINEL_PROP_RCP_ENH_ACK_PROBING, "ENH_ACK_PROBING"}, + {SPINEL_PROP_RCP_CSL_ACCURACY, "CSL_ACCURACY"}, + {SPINEL_PROP_RCP_CSL_UNCERTAINTY, "CSL_UNCERTAINTY"}, {SPINEL_PROP_PARENT_RESPONSE_INFO, "PARENT_RESPONSE_INFO"}, {SPINEL_PROP_SLAAC_ENABLED, "SLAAC_ENABLED"}, {SPINEL_PROP_SUPPORTED_RADIO_LINKS, "SUPPORTED_RADIO_LINKS"}, diff --git a/src/lib/spinel/spinel.h b/src/lib/spinel/spinel.h index 8b6db66fa..3a2c81a6d 100644 --- a/src/lib/spinel/spinel.h +++ b/src/lib/spinel/spinel.h @@ -377,7 +377,7 @@ * Please see section "Spinel definition compatibility guideline" for more details. * */ -#define SPINEL_RCP_API_VERSION 5 +#define SPINEL_RCP_API_VERSION 6 /** * @def SPINEL_MIN_HOST_SUPPORTED_RCP_API_VERSION @@ -4731,6 +4731,24 @@ enum */ SPINEL_PROP_RCP_ENH_ACK_PROBING = SPINEL_PROP_RCP_EXT__BEGIN + 3, + /// CSL Accuracy + /** Format: `C` + * Required capability: `SPINEL_CAP_NET_THREAD_1_2` + * + * The current CSL rx/tx scheduling drift, in units of ± ppm. + * + */ + SPINEL_PROP_RCP_CSL_ACCURACY = SPINEL_PROP_RCP_EXT__BEGIN + 4, + + /// CSL Uncertainty + /** Format: `C` + * Required capability: `SPINEL_CAP_NET_THREAD_1_2` + * + * The current uncertainty, in units of 10 us, of the clock used for scheduling CSL operations. + * + */ + SPINEL_PROP_RCP_CSL_UNCERTAINTY = SPINEL_PROP_RCP_EXT__BEGIN + 5, + SPINEL_PROP_RCP_EXT__END = 0x900, SPINEL_PROP_NEST__BEGIN = 0x3BC0, diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 1c35701f0..401aa7347 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -1547,6 +1547,20 @@ exit: return error; } +#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE +template <> otError NcpBase::HandlePropertyGet(void) +{ + return mEncoder.WriteUint8(otPlatRadioGetCslAccuracy(mInstance)); +} +#endif + +#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE +template <> otError NcpBase::HandlePropertyGet(void) +{ + return mEncoder.WriteUint8(otPlatRadioGetCslClockUncertainty(mInstance)); +} +#endif + otError NcpBase::EncodeChannelMask(uint32_t aChannelMask) { otError error = OT_ERROR_NONE; diff --git a/src/ncp/ncp_base_dispatcher.cpp b/src/ncp/ncp_base_dispatcher.cpp index 20084a5fb..89b1f61fe 100644 --- a/src/ncp/ncp_base_dispatcher.cpp +++ b/src/ncp/ncp_base_dispatcher.cpp @@ -210,6 +210,12 @@ NcpBase::PropertyHandler NcpBase::FindGetPropertyHandler(spinel_prop_key_t aKey) #if OPENTHREAD_RADIO || OPENTHREAD_CONFIG_LINK_RAW_ENABLE OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_RCP_TIMESTAMP), #endif +#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE + OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_RCP_CSL_ACCURACY), +#endif +#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE + OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_RCP_CSL_UNCERTAINTY), +#endif #if OPENTHREAD_MTD || OPENTHREAD_FTD OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_UNSOL_UPDATE_FILTER), OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_UNSOL_UPDATE_LIST), diff --git a/src/posix/platform/radio.cpp b/src/posix/platform/radio.cpp index 546e02736..4eaaed031 100644 --- a/src/posix/platform/radio.cpp +++ b/src/posix/platform/radio.cpp @@ -35,6 +35,7 @@ #include +#include "common/code_utils.hpp" #include "common/new.hpp" #include "lib/spinel/radio_spinel.hpp" #include "posix/platform/radio.hpp" @@ -603,12 +604,23 @@ uint32_t otPlatRadioGetBusSpeed(otInstance *aInstance) return sRadioSpinel.GetBusSpeed(); } +#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE uint8_t otPlatRadioGetCslAccuracy(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); - return 0; + return sRadioSpinel.GetCslAccuracy(); } +#endif + +#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE +uint8_t otPlatRadioGetCslClockUncertainty(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return sRadioSpinel.GetCslUncertainty(); +} +#endif otError otPlatRadioSetChannelMaxTransmitPower(otInstance *aInstance, uint8_t aChannel, int8_t aMaxPower) {