-
Notifications
You must be signed in to change notification settings - Fork 2.1k
at86rf2xx: implement sleep mode #3867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -25,6 +25,7 @@ | |||
#include "at86rf2xx_internal.h" | |||
#include "at86rf2xx_registers.h" | |||
#include "periph/spi.h" | |||
#include "xtimer.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used.
I assume this will be used as a part of your work on a MAC protocol. |
Yes. Switching to sleep mode only introduces a 300us wakeup delay and flushes the internal packet buffer. There's no example for state switching though. |
if( (at86rf2xx_get_status(dev) == AT86RF2XX_STATE_SLEEP) && | ||
(opt != NETOPT_STATE) ) { | ||
return -ECANCELED; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about this. Shouldn't we maybe wake the device up, to get/set options, and put it to sleep then again? I could imagine the MAC protocol awakes the device only when it expects receive/send actions and in this case it could be an advantage to be able to change options when there is nothing to do instead.
I guess that my current implementation may also lead to weird behavior with ifconfig on the shell. Waking up and putting to sleep should work. But that should be a more generic question about netapi and devices sleeping. Is there already a driver that has the same problem? |
At least this is not the case.
|
So it seems that only |
I agree, it is also more user friendly to do what Thomas proposed.
|
I'm not really happy with either solution :/ With this PR I think the API lacks a state between Automatically waking up and putting to sleep again feels like to much magic somehow. And not that netapi calls are already quite expensive (execution time wise), waking up introduces another 300us at least. That doesn't sound like power saving or transparent APIs to me. |
@daniel-k Do you have a use case where you want to linger in TRX_OFF instead of going to SLEEP or remaining in RX_AACK_ON? |
Actually no apart from configuring the device at startup. Or configuring the device in genral without the need to wakeup. Maybe if there's a short time frame where you don't want to receive new packets for whatever reason.
I think this really depends on the use case, i.e. on the time it takes for the computations. Maybe you're right that we don't really need such a state. |
Addressed temporarily wake up in 5b0c737 |
@thomaseichinger, @haukepetersen, @authmillenon, @OlegHahm, @kaspar030 etc. What is the general opinion on this regarding introducing a separate state for "device powered and fully responding towards the MCU, but RF components switched off" (i.e. deaf and mute)? We could introduce another state ( |
Done, see 004371b. Edit: forgot about the going back to sleep. But it does no harm as |
@daniel-k That works, |
417ea8b
to
78820e3
Compare
I wonder if we can't already map this with the existing states. To my knowledge, on most boards you can't really power off the radio module completely. So how about we change the states' descriptions to:
|
@thomaseichinger |
@thomaseichinger I agree with @daniel-k. OFF should be the lowest possible state, i.e. no state can be assumed to be retained after switching to OFF. A use case for the OFF state even if the chip itself does not support such a state is a platform/board where the power to the radio transceiver is controlled by an external circuit, that can be turned on and off from software. For example, 1 is an IC that we (Eistec) have used in multiple projects for controlling power to different sections of the board or even individual components in order to save power. |
@gebart @thomaseichinger |
5ff7cea
to
173fe42
Compare
I just found one :-( At some point in time I decide to put the transceiver to sleep. Just before that moment something happens and an IRQ is generated that queues a message for the (no)mac thread. There are 2 bad situations now:
To get rid of this situation I would like to clear the current state of transceiver and put it back to sleep as soon as possible. Apart from the fact that there's no API for discarding IRQs, when putting the transceiver back to Hope that is not too confusing :) |
Your problem statement was very clear and understandable, thank you. However, does it actually help to have one more state in this case or will the fix be all internal to the IRQ handling function of the driver? |
I guess no. As long as this is the only case it's not worth changing a system-wide API. But I'm thinking now how to implement this. I see 2 possiblities:
Any ideas? |
Actually, I would vote for aborting if an RX interrupt occurs before the state transition to sleep has finished. |
You mean abort going to sleep? That implies that you can't put your radio to sleep if someone hammers you with packets. |
@gebart For this particular transceiver putting it to sleep means that the framebuffer is lost anyway. So when the user decides to put it to sleep, it already implies that any incoming frame is lost. And given the just arriving frame would have come in only a moment later, it would have been lost too. |
b449564
to
1370afb
Compare
Rebased on master |
1370afb
to
f6a7adc
Compare
nitpick: Remove ACK, let's defer the decision regarding adding extra modes for "awake for MCU commands but not listening on radio" to a separate PR/issue |
OK to squash |
ad9981b
to
502786b
Compare
Travis is happy -> go! |
at86rf2xx: implement sleep mode
The
at86rf2xx
driver can now reach theSLEEP
state by setting its state via netapi toNETOPT_STATE_SLEEP
. Everything except the framebuffer is retained in the power mode. Wake up takes approx. 300us, power consumption is about 0.2uA.The netapi is blocked in sleep mode except for setting and getting the state. But using some driver functions directly by including the header file might lead to a deadlock. On the other hand putting a
at86rf2xx_assert_awake()
everywhere seems wrong too.