Skip to content

Commit

Permalink
[radio] Add API for resetting CSL parameters
Browse files Browse the repository at this point in the history
Add `ResetCslParameters` and `otPlatRadioResetCslParameters`
This allows handling stack reset as separate case instead of
using `kShortAddrInvalid` as `otShortAddress` and
`nullptr` as `otExtAddress` which can be difficult to handle
on vendor's side.

Default implementation still calls
`otPlatRadioEnableCsl(aInstance,0, Mac::kShortAddrInvalid, nullptr)`
So no action is needed if vendor has already implemented handling
this case.

Signed-off-by: Maciej Baczmanski <[email protected]>
  • Loading branch information
maciejbaczmanski committed Jan 15, 2024
1 parent f1e74a0 commit d8b23bd
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 2 deletions.
11 changes: 11 additions & 0 deletions examples/platforms/simulation/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,17 @@ otError otPlatRadioEnableCsl(otInstance *aInstance,
return error;
}

otError otPlatRadioResetCslParameters(otInstance *aInstance)
{
OT_UNUSED_VARIABLE(aInstance);

otError error = OT_ERROR_NONE;

sCslPeriod = 0;

return error;
}

void otPlatRadioUpdateCslSampleTime(otInstance *aInstance, uint32_t aCslSampleTime)
{
OT_UNUSED_VARIABLE(aInstance);
Expand Down
2 changes: 1 addition & 1 deletion include/openthread/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extern "C" {
* @note This number versions both OpenThread platform and user APIs.
*
*/
#define OPENTHREAD_API_VERSION (389)
#define OPENTHREAD_API_VERSION (390)

/**
* @addtogroup api-instance
Expand Down
14 changes: 14 additions & 0 deletions include/openthread/platform/radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,20 @@ otError otPlatRadioEnableCsl(otInstance *aInstance,
otShortAddress aShortAddr,
const otExtAddress *aExtAddr);

/**
* Reset CSL receiver parameters to default values.
*
* @note Defaults to `otPlatRadioEnableCsl(aInstance,0, Mac::kShortAddrInvalid, nullptr);`
*
* @param[in] aInstance The OpenThread instance structure.
*
* @retval kErrorNotImplemented Radio driver doesn't support CSL.
* @retval kErrorFailed Other platform specific errors.
* @retval kErrorNone Successfully enabled or disabled CSL.
*
*/
otError otPlatRadioResetCslParameters(otInstance *aInstance);

/**
* Update CSL sample time in radio driver.
*
Expand Down
2 changes: 1 addition & 1 deletion src/core/radio/radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void Radio::Init(void)
{
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
SuccessOrAssert(EnableCsl(0, Mac::kShortAddrInvalid, nullptr));
SuccessOrAssert(ResetCslParameters());
#endif

EnableSrcMatch(false);
Expand Down
13 changes: 13 additions & 0 deletions src/core/radio/radio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,15 @@ class Radio : public InstanceLocator, private NonCopyable
*
*/
Error EnableCsl(uint32_t aCslPeriod, otShortAddress aShortAddr, const otExtAddress *aExtAddr);

/** Resets CSL receiver parameters in radio to default values.
*
* @retval kErrorNotImplemented Radio driver doesn't support CSL.
* @retval kErrorFailed Other platform specific errors.
* @retval kErrorNone Successfully enabled or disabled CSL.
*
*/
Error ResetCslParameters(void);
#endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE

#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
Expand Down Expand Up @@ -958,6 +967,8 @@ inline Error Radio::EnableCsl(uint32_t aCslPeriod, otShortAddress aShortAddr, co
{
return otPlatRadioEnableCsl(GetInstancePtr(), aCslPeriod, aShortAddr, aExtAddr);
}

inline Error Radio::ResetCslParameters(void) { return otPlatRadioResetCslParameters(GetInstancePtr()); }
#endif

#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
Expand Down Expand Up @@ -1064,6 +1075,8 @@ inline Error Radio::EnableCsl(uint32_t, otShortAddress aShortAddr, const otExtAd
{
return kErrorNotImplemented;
}

inline Error Radio::ResetCslParameters(void) { return kErrorNotImplemented; }
#endif

#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
Expand Down
7 changes: 7 additions & 0 deletions src/core/radio/radio_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ OT_TOOL_WEAK uint32_t otPlatRadioGetBusSpeed(otInstance *aInstance)
return 0;
}

#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
OT_TOOL_WEAK otError otPlatRadioResetCslParameters(otInstance *aInstance)
{
return otPlatRadioEnableCsl(aInstance, 0, Mac::kShortAddrInvalid, nullptr);
}
#endif

OT_TOOL_WEAK uint8_t otPlatRadioGetCslAccuracy(otInstance *aInstance)
{
OT_UNUSED_VARIABLE(aInstance);
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ OT_TOOL_WEAK otError otPlatRadioEnableCsl(otInstance *, uint32_t, otShortAddress
return OT_ERROR_NONE;
}

OT_TOOL_WEAK otError otPlatRadioResetCslParameters(otInstance *) { return OT_ERROR_NONE; }

OT_TOOL_WEAK void otPlatRadioUpdateCslSampleTime(otInstance *, uint32_t) {}

OT_TOOL_WEAK uint8_t otPlatRadioGetCslAccuracy(otInstance *)
Expand Down

0 comments on commit d8b23bd

Please sign in to comment.