Skip to content

Commit

Permalink
update poll period when setting CSL timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
brianljt committed Apr 13, 2021
1 parent 037a19c commit 0f271fe
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 78 deletions.
4 changes: 2 additions & 2 deletions src/core/api/link_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ otError otLinkCslSetPeriod(otInstance *aInstance, uint16_t aPeriod)

uint32_t otLinkCslGetTimeout(otInstance *aInstance)
{
return static_cast<Instance *>(aInstance)->Get<Mac::Mac>().GetCslTimeout();
return static_cast<Instance *>(aInstance)->Get<Mle::MleRouter>().GetCslTimeout();
}

otError otLinkCslSetTimeout(otInstance *aInstance, uint32_t aTimeout)
Expand All @@ -529,7 +529,7 @@ otError otLinkCslSetTimeout(otInstance *aInstance, uint32_t aTimeout)
Instance &instance = *static_cast<Instance *>(aInstance);

VerifyOrExit(kMaxCslTimeout >= aTimeout, error = kErrorInvalidArgs);
instance.Get<Mac::Mac>().SetCslTimeout(aTimeout);
instance.Get<Mle::MleRouter>().SetCslTimeout(aTimeout);

exit:
return error;
Expand Down
2 changes: 1 addition & 1 deletion src/core/mac/data_poll_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ uint32_t DataPollSender::GetDefaultPollPeriod(void) const
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
if (Get<Mac::Mac>().IsCslEnabled())
{
period = OT_MIN(period, Time::SecToMsec(Get<Mac::Mac>().GetCslTimeout()));
period = OT_MIN(period, Time::SecToMsec(Get<Mle::MleRouter>().GetCslTimeout()));
}
#endif

Expand Down
15 changes: 0 additions & 15 deletions src/core/mac/mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2467,21 +2467,6 @@ void Mac::SetCslPeriod(uint16_t aPeriod)
UpdateIdleMode();
}

void Mac::SetCslTimeout(uint32_t aTimeout)
{
VerifyOrExit(GetCslTimeout() != aTimeout);

mLinks.GetSubMac().SetCslTimeout(aTimeout);

if (IsCslEnabled())
{
Get<Mle::Mle>().ScheduleChildUpdateRequest();
}

exit:
return;
}

bool Mac::IsCslEnabled(void) const
{
return (GetCslPeriod() > 0) && !GetRxOnWhenIdle() && Get<Mle::MleRouter>().IsChild() &&
Expand Down
16 changes: 0 additions & 16 deletions src/core/mac/mac.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,22 +720,6 @@ class Mac : public InstanceLocator, private NonCopyable
*/
void SetCslPeriod(uint16_t aPeriod);

/**
* This method gets the CSL timeout.
*
* @returns CSL timeout in seconds.
*
*/
uint32_t GetCslTimeout(void) const { return mLinks.GetSubMac().GetCslTimeout(); }

/**
* This method sets the CSL timeout.
*
* @param[in] aTimeout The CSL timeout in seconds.
*
*/
void SetCslTimeout(uint32_t aTimeout);

/**
* This method indicates whether CSL is started at the moment.
*
Expand Down
6 changes: 0 additions & 6 deletions src/core/mac/sub_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ SubMac::SubMac(Instance &aInstance)
, mKeyId(0)
, mTimer(aInstance, SubMac::HandleTimer)
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
, mCslTimeout(OPENTHREAD_CONFIG_CSL_TIMEOUT)
, mCslPeriod(0)
, mCslChannel(0)
, mIsCslChannelSpecified(false)
Expand Down Expand Up @@ -972,11 +971,6 @@ void SubMac::SetCslPeriod(uint16_t aPeriod)
return;
}

void SubMac::SetCslTimeout(uint32_t aTimeout)
{
mCslTimeout = aTimeout;
}

void SubMac::HandleCslTimer(Timer &aTimer)
{
aTimer.Get<SubMac>().HandleCslTimer();
Expand Down
52 changes: 17 additions & 35 deletions src/core/mac/sub_mac.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,25 +319,6 @@ class SubMac : public InstanceLocator, private NonCopyable
*/
Error Receive(uint8_t aChannel);

#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
/**
* This method lets `SubMac` start CSL sample.
*
* `SubMac` would switch the radio state between `Receive` and `Sleep` according the CSL timer. When CslSample is
* started, `mState` will become `kStateCslSample`. But it could be doing `Sleep` or `Receive` at this moment
* (depending on `mCslState`).
*
* @param[in] aPanChannel The current phy channel used by the device. This param will only take effect when CSL
* channel hasn't been explicitly specified.
*
* @retval kErrorNone Successfully entered CSL operation (sleep or receive according to CSL timer).
* @retval kErrorBusy The radio was transmitting.
* @retval kErrorInvalidState The radio was disabled.
*
*/
Error CslSample(uint8_t aPanChannel);
#endif

/**
* This method gets the radio transmit frame.
*
Expand Down Expand Up @@ -398,6 +379,23 @@ class SubMac : public InstanceLocator, private NonCopyable

#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE

/**
* This method lets `SubMac` start CSL sample.
*
* `SubMac` would switch the radio state between `Receive` and `Sleep` according the CSL timer. When CslSample is
* started, `mState` will become `kStateCslSample`. But it could be doing `Sleep` or `Receive` at this moment
* (depending on `mCslState`).
*
* @param[in] aPanChannel The current phy channel used by the device. This param will only take effect when CSL
* channel hasn't been explicitly specified.
*
* @retval kErrorNone Successfully entered CSL operation (sleep or receive according to CSL timer).
* @retval kErrorBusy The radio was transmitting.
* @retval kErrorInvalidState The radio was disabled.
*
*/
Error CslSample(uint8_t aPanChannel);

/**
* This method gets the CSL channel.
*
Expand Down Expand Up @@ -444,21 +442,6 @@ class SubMac : public InstanceLocator, private NonCopyable
*/
void SetCslPeriod(uint16_t aPeriod);

/**
* This method gets the CSL timeout.
*
* @returns CSL timeout
*
*/
uint32_t GetCslTimeout(void) const { return mCslTimeout; }

/**
* This method sets the CSL timeout.
*
* @param[in] aTimeout The CSL timeout in seconds.
*
*/
void SetCslTimeout(uint32_t aTimeout);
#endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE

/**
Expand Down Expand Up @@ -643,7 +626,6 @@ class SubMac : public InstanceLocator, private NonCopyable
#endif

#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
uint32_t mCslTimeout; ///< The CSL synchronized timeout in seconds.
uint16_t mCslPeriod; ///< The CSL sample period, in units of 10 symbols (160 microseconds).
uint8_t mCslChannel : 7; ///< The actually CSL sample channel. If `mIsCslChannelSpecified` is 0, this should be
///< equal to the Pan channel of `Mac`.
Expand Down
24 changes: 21 additions & 3 deletions src/core/thread/mle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ Mle::Mle(Instance &aInstance)
, mReceivedResponseFromParent(false)
, mSocket(aInstance)
, mTimeout(kMleEndDeviceTimeout)
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
, mCslTimeout(OPENTHREAD_CONFIG_CSL_TIMEOUT)
#endif
#if OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH
, mPreviousParentRloc(Mac::kShortAddrInvalid)
#endif
Expand Down Expand Up @@ -1451,8 +1454,24 @@ Error Mle::AppendCslChannel(Message &aMessage)
Error Mle::AppendCslTimeout(Message &aMessage)
{
OT_ASSERT(Get<Mac::Mac>().IsCslEnabled());
return Tlv::Append<CslTimeoutTlv>(aMessage, Get<Mac::Mac>().GetCslTimeout() == 0 ? mTimeout
: Get<Mac::Mac>().GetCslTimeout());
return Tlv::Append<CslTimeoutTlv>(aMessage, mCslTimeout == 0 ? mTimeout : mCslTimeout);
}

void Mle::SetCslTimeout(uint32_t aTimeout)
{
VerifyOrExit(mCslTimeout != aTimeout);

mCslTimeout = aTimeout;

Get<DataPollSender>().RecalculatePollPeriod();

if (Get<Mac::Mac>().IsCslEnabled())
{
ScheduleChildUpdateRequest();
}

exit:
return;
}
#endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE

Expand Down Expand Up @@ -2305,7 +2324,6 @@ Error Mle::SendChildUpdateRequest(void)
if (!IsRxOnWhenIdle())
{
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
Get<DataPollSender>().RecalculatePollPeriod();
Get<DataPollSender>().SetAttachMode(!Get<Mac::Mac>().IsCslEnabled());
#else
Get<DataPollSender>().SetAttachMode(true);
Expand Down
21 changes: 21 additions & 0 deletions src/core/thread/mle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,24 @@ class Mle : public InstanceLocator, private NonCopyable
*/
bool HasRestored(void) const { return mHasRestored; }

#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
/**
* This method gets the CSL timeout.
*
* @returns CSL timeout
*
*/
uint32_t GetCslTimeout(void) const { return mCslTimeout; }

/**
* This method sets the CSL timeout.
*
* @param[in] aTimeout The CSL timeout in seconds.
*
*/
void SetCslTimeout(uint32_t aTimeout);
#endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE

protected:
/**
* MLE Command Types.
Expand Down Expand Up @@ -1815,6 +1833,9 @@ class Mle : public InstanceLocator, private NonCopyable

Ip6::Udp::Socket mSocket;
uint32_t mTimeout;
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
uint32_t mCslTimeout;
#endif

#if OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH
uint16_t mPreviousParentRloc;
Expand Down

0 comments on commit 0f271fe

Please sign in to comment.