Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
edmont committed Oct 14, 2024
1 parent ce250be commit 1d92185
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 164 deletions.
44 changes: 14 additions & 30 deletions include/openthread/link.h
Original file line number Diff line number Diff line change
Expand Up @@ -1153,49 +1153,33 @@ otError otLinkSetWakeUpListenEnabled(otInstance *aInstance, bool aEnable);
bool otLinkIsWakeupListenEnabled(otInstance *aInstance);

/**
* Gets the WED listen interval in microseconds.
* Get the wake-up listen parameters.
*
* Requires `OPENTHREAD_CONFIG_WAKEUP_END_DEVICE_ENABLE`.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @returns The WED listen interval in microseconds.
*/
uint32_t otLinkGetWedListenInterval(otInstance *aInstance);

/**
* Sets the WED listen interval in microseconds.
*
* Requires `OPENTHREAD_CONFIG_WAKEUP_END_DEVICE_ENABLE`.
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[out] aInterval A pointer to return the wake-up listen interval in microseconds.
* @param[out] aDuration A pointer to return the wake-up listen duration in microseconds.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aInterval The WED listen interval in microseconds.
*/
void otLinkSetWedListenInterval(otInstance *aInstance, uint32_t aInterval);
void otLinkGetWakeupListenParameters(otInstance *aInstance, uint32_t *aInterval, uint32_t *aDuration);

/**
* Gets the WED listen duration.
* Set the wake-up listen parameters.
*
* Requires `OPENTHREAD_CONFIG_WAKEUP_END_DEVICE_ENABLE`.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @returns The WED listen duration in microseconds.
*/
uint32_t otLinkGetWedListenDuration(otInstance *aInstance);

/**
* Sets the WED listen duration in microseconds.
* The listen interval must be greater than the listen duration.
* The listen duration must be greater or equal than the minumum supported.
*
* Requires `OPENTHREAD_CONFIG_WAKEUP_END_DEVICE_ENABLE`.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aDuration The WED listen duration in microseconds.
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aInterval The wake-up listen interval in microseconds.
* @param[in] aDuration The wake-up listen duration in microseconds.
*
* @retval OT_ERROR_NONE Successfully set the WED listen duration.
* @retval OT_ERROR_INVALID_ARGS Invalid WED listen duration.
* @retval OT_ERROR_NONE Successfully set the wake-up listen parameters.
* @retval OT_ERROR_INVALID_ARGS Invalid wake-up listen parameters.
*/
otError otLinkSetWedListenDuration(otInstance *aInstance, uint32_t aDuration);
otError otLinkSetWakeupListenParameters(otInstance *aInstance, uint32_t aInterval, uint32_t aDuration);

/**
* @}
Expand Down
38 changes: 8 additions & 30 deletions src/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4425,49 +4425,27 @@ Requires `OPENTHREAD_CONFIG_WAKEUP_COORDINATOR_ENABLE` or `OPENTHREAD_CONFIG_WAK
Done
```
### wakeup interval
### wakeup parameters
Get the wake-up listen interval.
Get the wake-up listen interval and duration.
Requires `OPENTHREAD_CONFIG_WAKEUP_END_DEVICE_ENABLE`.
```bash
> wakeup interval
1000000
> wakeup parameters
interval: 1000000us
duration: 8000us
Done
```
### wakeup interval \<interval\>
### wakeup parameters \<interval\> \<duration\>
Set the wake-up listen interval.
Set the wake-up listen interval and duration.
Requires `OPENTHREAD_CONFIG_WAKEUP_END_DEVICE_ENABLE`.
```bash
> wakeup interval 1000000
Done
```
### wakeup duration
Get the wake-up listen duration.
Requires `OPENTHREAD_CONFIG_WAKEUP_END_DEVICE_ENABLE`.
```bash
> wakeup duration
8000
Done
```
### wakeup duration \<duration\>
Set the wake-up listen duration.
Requires `OPENTHREAD_CONFIG_WAKEUP_END_DEVICE_ENABLE`.
```bash
> wakeup duration 8000
> wakeup parameters 1000000 8000
Done
```
Expand Down
56 changes: 25 additions & 31 deletions src/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8241,46 +8241,40 @@ template <> otError Interpreter::Process<Cmd("wakeup")>(Arg aArgs[])
}
#if OPENTHREAD_CONFIG_WAKEUP_END_DEVICE_ENABLE
/**
* @cli wakeup interval (get,set)
* @cli wakeup paramters (get,set)
* @code
* wakeup interval
* 12
* Done
* @endcode
* @code
* wakeup interval 1000000
* Done
* @endcode
* @cparam wakeup interval @ca{interval}
* @par
* Gets or sets the wake-up interval value.
* @sa otLinkGetWedListenInterval
* @sa otLinkSetWedListenInterval
*/
else if (aArgs[0] == "interval")
{
error = ProcessGetSet(aArgs + 1, otLinkGetWedListenInterval, otLinkSetWedListenInterval);
}
/**
* @cli wakeup duration (get,set)
* @code
* wakeup duration
* 8000
* wakeup paramters
* interval: 1000000us
* duration: 8000us
* Done
* @endcode
* @code
* wakeup duration 8000
* wakeup paramters 1000000 8000
* Done
* @endcode
* @cparam wakeup duration @ca{duration}
* @cparam wakeup paramters @ca{interval} @ca{duration}
* @par
* Gets or sets the wake-up duration value.
* @sa otLinkGetWedListenDuration
* @sa otLinkSetWedListenDuration
* Gets or sets the wake-up listen interval and wake-up listen duration values.
* @sa otLinkGetWakeUpListenParameters
* @sa otLinkSetWakeUpListenParameters
*/
else if (aArgs[0] == "duration")
else if (aArgs[0] == "paramters")
{
error = ProcessGetSet(aArgs + 1, otLinkGetWedListenDuration, otLinkSetWedListenDuration);
uint32_t interval;
uint32_t duration;

if (aArgs[1].IsEmpty())
{
otLinkGetWakeupListenParameters(GetInstancePtr(), &interval, &duration);
OutputLine("interval: %luus", ToUlong(interval));
OutputLine("duration: %luus", ToUlong(duration));
}
else
{
SuccessOrExit(error = aArgs[1].ParseAsUint32(interval));
SuccessOrExit(error = aArgs[2].ParseAsUint32(duration));
otLinkSetWakeupListenParameters(GetInstancePtr(), interval, duration);
}
}
/**
* @cli wakeup listen (enable,disable)
Expand Down
18 changes: 4 additions & 14 deletions src/core/api/link_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,23 +516,13 @@ bool otLinkIsWakeupListenEnabled(otInstance *aInstance)
return AsCoreType(aInstance).Get<Mac::Mac>().IsWakeupListenEnabled();
}

uint32_t otLinkGetWedListenInterval(otInstance *aInstance)
void otLinkGetWakeupListenParameters(otInstance *aInstance, uint32_t *aInterval, uint32_t *aDuration)
{
return AsCoreType(aInstance).Get<Mac::Mac>().GetWedListenInterval();
AsCoreType(aInstance).Get<Mac::Mac>().GetWakeupListenParameters(*aInterval, *aDuration);
}

void otLinkSetWedListenInterval(otInstance *aInstance, uint32_t aInterval)
otError otLinkSetWakeupListenParameters(otInstance *aInstance, uint32_t aInterval, uint32_t aDuration)
{
return AsCoreType(aInstance).Get<Mac::Mac>().SetWedListenInterval(aInterval);
}

uint32_t otLinkGetWedListenDuration(otInstance *aInstance)
{
return AsCoreType(aInstance).Get<Mac::Mac>().GetWedListenDuration();
}

otError otLinkSetWedListenDuration(otInstance *aInstance, uint32_t aDuration)
{
return AsCoreType(aInstance).Get<Mac::Mac>().SetWedListenDuration(aDuration);
return AsCoreType(aInstance).Get<Mac::Mac>().SetWakeupListenParameters(aInterval, aDuration);
}
#endif // OPENTHREAD_CONFIG_WAKEUP_END_DEVICE_ENABLE
6 changes: 3 additions & 3 deletions src/core/config/wakeup.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
/**
* @def OPENTHREAD_CONFIG_WED_LISTEN_INTERVAL
*
* The default WED listen interval in microseconds.
* The default wake-up listen interval in microseconds.
*/
#ifndef OPENTHREAD_CONFIG_WED_LISTEN_INTERVAL
#define OPENTHREAD_CONFIG_WED_LISTEN_INTERVAL 1000000
Expand All @@ -75,7 +75,7 @@
/**
* @def OPENTHREAD_CONFIG_WED_LISTEN_DURATION
*
* The default WED listen duration in microseconds.
* The default wake-up listen duration in microseconds.
*/
#ifndef OPENTHREAD_CONFIG_WED_LISTEN_DURATION
#define OPENTHREAD_CONFIG_WED_LISTEN_DURATION 8000
Expand All @@ -84,7 +84,7 @@
/**
* @def OPENTHREAD_CONFIG_WED_RECEIVE_TIME_AFTER
*
* Margin to be applied after the end of a WED listen duration to schedule the next listen interval, in units of
* Margin to be applied after the end of a wake-up listen duration to schedule the next listen interval, in units of
* microseconds.
*/
#ifndef OPENTHREAD_CONFIG_WED_RECEIVE_TIME_AFTER
Expand Down
22 changes: 11 additions & 11 deletions src/core/mac/mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ Mac::Mac(Instance &aInstance)
#endif
, mWakeupChannel(OPENTHREAD_CONFIG_DEFAULT_WAKEUP_CHANNEL)
#if OPENTHREAD_CONFIG_WAKEUP_END_DEVICE_ENABLE
, mWedListenInterval(kDefaultWedListenInterval)
, mWedListenDuration(kDefaultWedListenDuration)
, mWakeupListenInterval(kDefaultWedListenInterval)
, mWakeupListenDuration(kDefaultWedListenDuration)
#endif
, mActiveScanHandler(nullptr) // Initialize `mActiveScanHandler` and `mEnergyScanHandler` union
, mScanHandlerContext(nullptr)
Expand Down Expand Up @@ -2467,19 +2467,21 @@ Error Mac::SetWakeupChannel(uint8_t aChannel)
#endif

#if OPENTHREAD_CONFIG_WAKEUP_END_DEVICE_ENABLE
void Mac::SetWedListenInterval(uint32_t aInterval)
void Mac::GetWakeupListenParameters(uint32_t &aInterval, uint32_t &aDuration) const
{
mWedListenInterval = aInterval;
UpdateWakeupListening();
aInterval = mWakeupListenInterval;
aDuration = mWakeupListenDuration;
}

Error Mac::SetWedListenDuration(uint32_t aDuration)
Error Mac::SetWakeupListenParameters(uint32_t aInterval, uint32_t aDuration)
{
Error error = kErrorNone;

VerifyOrExit(aDuration >= kMinWedListenDuration, error = kErrorInvalidArgs);
VerifyOrExit(aDuration >= kMinWakeupListenDuration, error = kErrorInvalidArgs);
VerifyOrExit(aInterval > aDuration, error = kErrorInvalidArgs);

mWedListenDuration = aDuration;
mWakeupListenInterval = aInterval;
mWakeupListenDuration = aDuration;
UpdateWakeupListening();

exit:
Expand All @@ -2490,8 +2492,6 @@ Error Mac::SetWakeupListenEnabled(bool aEnable)
{
Error error = kErrorNone;

VerifyOrExit(GetWedListenInterval() > GetWedListenDuration(), error = kErrorInvalidArgs);

#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
if (aEnable && GetCslPeriod() > 0)
{
Expand Down Expand Up @@ -2520,7 +2520,7 @@ void Mac::UpdateWakeupListening(void)
{
uint8_t channel = mWakeupChannel ? mWakeupChannel : mPanChannel;

mLinks.UpdateWakeupListening(mWakeupListenEnabled, mWedListenInterval, mWedListenDuration, channel);
mLinks.UpdateWakeupListening(mWakeupListenEnabled, mWakeupListenInterval, mWakeupListenDuration, channel);
}

Error Mac::HandleWakeupFrame(const RxFrame &aFrame)
Expand Down
37 changes: 14 additions & 23 deletions src/core/mac/mac.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,35 +704,26 @@ class Mac : public InstanceLocator, private NonCopyable

#if OPENTHREAD_CONFIG_WAKEUP_END_DEVICE_ENABLE
/**
* Gets the WED listen interval.
* Gets the wake-up listen parameters.
*
* @returns WED listen interval in microseconds.
* @param[out] aInterval A reference to return the wake-up listen interval in microseconds.
* @param[out] aDuration A reference to return the wake-up listen duration in microseconds.
*/
uint32_t GetWedListenInterval(void) const { return mWedListenInterval; }
void GetWakeupListenParameters(uint32_t &aInterval, uint32_t &aDuration) const;

/**
* Sets the WED listen interval.
* Sets the wake-up listen parameters.
*
* @param[in] aInterval The WED listen interval in microseconds.
*/
void SetWedListenInterval(uint32_t aInterval);

/**
* Gets the WED listen duration.
*
* @returns WED listen duration in microseconds.
*/
uint32_t GetWedListenDuration(void) const { return mWedListenDuration; }

/**
* Sets the WED listen duration.
* The listen interval must be greater than the listen duration.
* The listen duration must be greater or equal than `kMinWakeupListenDuration`.
*
* @param[in] aDuration The WED listen duration in microseconds.
* @param[in] aInterval The wake-up listen interval in microseconds.
* @param[in] aDuration The wake-up listen duration in microseconds.
*
* @retval kErrorNone Successfully set the WED listen duration.
* @retval kErrorInvalidArgs The @p aDuration is below the minimum supported.
* @retval kErrorNone Successfully set the wake-up listen parameters.
* @retval kErrorInvalidArgs Configured listen interval is not greater than listen duration.
*/
Error SetWedListenDuration(uint32_t aDuration);
Error SetWakeupListenParameters(uint32_t aInterval, uint32_t aDuration);

/**
* Enables/disables listening for wake-up frames.
Expand Down Expand Up @@ -892,8 +883,8 @@ class Mac : public InstanceLocator, private NonCopyable
#endif
uint8_t mWakeupChannel;
#if OPENTHREAD_CONFIG_WAKEUP_END_DEVICE_ENABLE
uint32_t mWedListenInterval;
uint32_t mWedListenDuration;
uint32_t mWakeupListenInterval;
uint32_t mWakeupListenDuration;
#endif
union
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/mac/mac_links.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ class Links : public InstanceLocator
* Configures wake-up listening parameters in all radios.
*
* @param[in] aEnable Whether to enable or disable wake-up listening.
* @param[in] aInterval The WED listen interval in microseconds.
* @param[in] aDuration The WED listen duration in microseconds.
* @param[in] aInterval The wake-up listen interval in microseconds.
* @param[in] aDuration The wake-up listen duration in microseconds.
* @param[in] aChannel The wake-up channel.
*/
void UpdateWakeupListening(bool aEnable, uint32_t aInterval, uint32_t aDuration, uint8_t aChannel)
Expand Down
Loading

0 comments on commit 1d92185

Please sign in to comment.