[sub-mac] simplify SubMac::Sleep() implementation (#13429)

This commit simplifies `SubMac::Sleep()` by inlining the logic
previously in `RadioSleep()` and `ShouldHandleTransitionToSleep()`,
allowing the removal of those private helper methods.

It also clarifies via comment why `Radio::Sleep()` is invoked when
`mRxOnWhenIdle` is true even if `kCapRxOnWhenIdle` is supported
(to support radio validation and test scenarios where the radio is
forced to sleep).
This commit is contained in:
Abtin Keshavarzian
2026-07-27 16:28:03 -07:00
committed by GitHub
parent c5168b783a
commit 553ba0763d
2 changed files with 8 additions and 17 deletions
+8 -14
View File
@@ -215,21 +215,17 @@ Error SubMac::Sleep(void)
if (IsRadioSampleEnabled())
{
RadioSample();
ExitNow();
}
else
#endif
{
error = RadioSleep();
}
return error;
}
// Even if the radio platform supports `kCapRxOnWhenIdle`, when
// `SubMac::Sleep()` is explicitly called while `mRxOnWhenIdle`
// is true, we still call `Radio::Sleep()`. This supports radio
// validation and test scenarios where the radio is being forced
// to sleep.
Error SubMac::RadioSleep(void)
{
Error error = kErrorNone;
if (ShouldHandleTransitionToSleep())
if (!RadioSupports(kCapRxOnWhenIdle) || mRxOnWhenIdle)
{
SuccessOrExit(error = Get<Radio::Radio>().Sleep());
}
@@ -237,7 +233,7 @@ Error SubMac::RadioSleep(void)
SetState(kStateSleep);
exit:
LogWarnOnError(error, "RadioSleep()");
LogWarnOnError(error, "Sleep()");
return error;
}
@@ -891,8 +887,6 @@ exit:
return shouldHandle;
}
bool SubMac::ShouldHandleTransitionToSleep(void) const { return (mRxOnWhenIdle || !RadioSupports(kCapRxOnWhenIdle)); }
void SubMac::SetState(State aState)
{
if (mState != aState)
-3
View File
@@ -581,7 +581,6 @@ private:
bool ShouldHandleEnergyScan(void) const { return ShouldHandle(kCapEnergyScan); }
bool ShouldHandleTransmitTargetTime(void) const { return ShouldHandle(kCapTransmitTiming); }
bool ShouldHandleCsmaBackOff(void) const;
bool ShouldHandleTransitionToSleep(void) const;
void ProcessTransmitSecurity(void);
void ReprocessSecurityForRetx(TxFrame &aFrame);
@@ -600,8 +599,6 @@ private:
void HandleEnergyScanDone(int8_t aMaxRssi);
void HandleTimer(void);
Error RadioSleep(void);
void SetState(State aState);
static const char *StateToString(State aState);