Skip to content

Conversation

jia200x
Copy link
Member

@jia200x jia200x commented Aug 22, 2019

Contribution description

This commit changes the representation of the SLEEP state in the at86rf2xx driver.

I'm trying to make a distinction between PHY states (RX_ON, TRX_OFF, TX_ON/PLL_ON) and hardware states (P_ON, RESET, SLEEP). This will simplify a lot the state handling of radios, and also add some mechanism to prevent race conditions when changing between RX, BUSY_RX, TX and BUSY_TX (I will open a PR soon that show this in action).

The first step then is to remove the SLEEP state from at86rf2xx_set_state and add some dedicated functions for turning the radio on and off (inspired in the Linux at86rf2xx driver).

The API of netdev is the same (NETOPT_STATE set with NETOPT_STATE_SLEEP sets the radio to sleep), but the behavior of the driver changes a bit because of the dev->idle_state variable. In current master, it's possible to send data while the device is sleeping, and then the device will do a TX->SLEEP transition. With this change, if the device was sleeping it will end in TRX_OFF.

In any case, the idle_state logic shouldn't be in the driver (e.g in TSCH networks the MAC layer needs to set the state of the radio without cooperation from the driver. Same applies for LoRaWAN). So I hope it's OK ;)

Testing procedure

Test it with the default example:

  • Set the devices to sleep (e.g ifconfig 4 set state SLEEP)
  • Try to send data with txtsnd. The device should be able to send data and go back to STANDBY state (TRX_OFF)
  • Wake up the devices (ifconfig 4 set state IDLE).
  • Send data again. Verify nodes can still receive data after wake up.

It would be possible to verify that the device is actually sleeping measuring the power consumption of the node (I know this is possible with not so much efforts on IoT-LAB)

Issues/PRs references

Related to #11483

@jia200x jia200x added Area: drivers Area: Device drivers Area: network Area: Networking Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation labels Aug 22, 2019
This commit removes the SLEEP state and adds a dedicated function for
turning the radio on and off. The motivation for removing the SLEEP
state is to simplify the state machine of `at86rf2xx_set_state`
@jia200x jia200x force-pushed the pr/at86rf2xx_sleep branch from 3f0fad0 to 23eae5d Compare August 27, 2019 12:09
/* temporarily wake up if sleeping */
if (old_state == AT86RF2XX_STATE_SLEEP) {
at86rf2xx_assert_awake(dev);
if (dev->flags & AT86RF2XX_OPT_SLEEP) {
Copy link
Member

@PeterKietzmann PeterKietzmann Aug 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you verify that dev->flags is not been changed elsewhere?

Copy link
Member

@PeterKietzmann PeterKietzmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jia200x thanks for your contribution! Although I think that I understood the main idea, there are some points on which I would need clarification.

the device will do a TX->SLEEP transition. With this change, if the device was sleeping it will end in TRX_OFF.

  1. Is this really the case or do we go back to AT86RF2XX_STATE_RX_AACK_ON as initialized in the setup function? If we don't, then how comes we are always able to receive frames by default?
  2. I understand that the intention is not to handle sleep state from within the device driver but if we actually switch to TRX_OFF instead of SLEEP without a higher layer control, this would increase current consumption by means for existing applications. Would this break anything for you @roberthartung or @MichelRottleuthner?
  • Try to send data with txtsnd. The device should be able to send data and go back to STANDBY state (TRX_OFF)

So the assumption is, that a device returns to its previous state after sending. If the previous state was TRX_OFF, then we will return to that state again after sending and we won't be able to receive afterwards. Is that correct? If so, do we have any kind of documentation for that behavior?

(@jia200x I know not all questions directly relate to your changes but if we could sort out some misunderstandings here, we should do so :-))

@@ -418,8 +418,8 @@ static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len)
}

/* go back to sleep if were sleeping */
if (old_state == AT86RF2XX_STATE_SLEEP) {
at86rf2xx_set_state(dev, AT86RF2XX_STATE_SLEEP);
if (dev->flags & AT86RF2XX_OPT_SLEEP) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you verify that dev->flags is not been changed elsewhere?

@@ -222,7 +222,7 @@ static int _set_state(at86rf2xx_t *dev, netopt_state_t state)
at86rf2xx_set_state(dev, AT86RF2XX_STATE_TRX_OFF);
break;
case NETOPT_STATE_SLEEP:
at86rf2xx_set_state(dev, AT86RF2XX_STATE_SLEEP);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need AT86RF2XX_STATE_SLEEP anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe not

@jia200x
Copy link
Member Author

jia200x commented Aug 28, 2019

@PeterKietzmann I will give it a second look to try to leave it with the original behavior

@benpicco
Copy link
Contributor

Ping?
This appears to be the root of the dependency chain of your at86rf2xx rework.

@jia200x
Copy link
Member Author

jia200x commented Oct 29, 2019

Ping?
This appears to be the root of the dependency chain of your at86rf2xx rework.

Yes, this is the root.
I gave more priority to netif stuff but I can revive this again

@jia200x
Copy link
Member Author

jia200x commented Mar 12, 2020

I will close this one for now, the driver has changed quite a lot. I will re open it if needed

@jia200x jia200x closed this Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers Area: network Area: Networking Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants