-
Notifications
You must be signed in to change notification settings - Fork 3k
Added function to get the timestamp of the next us_ticker event. #931
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
Can you elaborate, how this would allow you wakeup? can provide a code snippet. |
To minimize power in deepsleep, the high frequency clock to the us_ticker can be disabled. The RTC is clocked from a slower, low-power clock. When deepsleep is called, the next event timestamp is retrieved from the us_ticker and an RTC alarm is set to wakeup at the next event time. Upon wakeup, the us_ticker is updated an reenabled. This allows you to have high resolution timing during run mode, and low power consumption during deepsleep. |
I guess this would do the same as just using a set time for deepsleep such as WakeUp library does, only it allows you to check when the next ticker event is going to happen. What do you do with all the events in the queue though? Because if you go into deepsleep for lets say the 2 seconds until the next ticker event happens (then automatically the high frequency clocks will be disabled), and you wake up again, then the other events are still in the queue, with their original timestamps, and the us_ticker timer is still at its old time, two seconds in the past. |
@jeremybrodt how do you update the ticker and reenable? There's no function which would allow to do it. @Sissors A good question, what to do with us ticker event's queue if the system is about to enter the deep sleep ? Fire all events right before the entering the deep_sleep()? |
The HAL implementation that we are working on supports these functions. Here is a code snippet from deepsleep().
|
@0xc0170 All other events in the queue are later than the event that would be returned by us_ticker_get_next_timestamp(). There is no need to fire them all. They do not occur until after the next scheduled wakeup. |
@Sissors What is the WakeUp library? |
Library of mine for timed waking from deepsleep: https://developer.mbed.org/users/Sissors/code/WakeUp/ |
Ah. That looks like a useful library. Without my proposed function, how do you know how long you can go to sleep without missing an event? |
That is up for the user to set. But generally it is intended for for example sensor applications, where you want to sample a sensor roughly every minute, and sleep in the meantime. Then you don't have other tickers running. But you are correct that something like this would be a useful addition for systems with multiple different tickers with different periods where it may sleep in between. Of course it is still then up to the user to decide if it should go to sleep during that time. Just because no tickers are active does not mean no other code is active ;). |
@jeremybrodt the snippet you shared looks like a small scheduler. It's more clear now the intention of the usage of this functionality, thanks. We might consider deinit(), reinit(arguments required to us ticker to function again). A new issue can be created for this, a new functionality. Something to think about. |
Us ticker - add function to get the timestamp of the next us_ticker event.
@jeremybrodt Added an issue, regarding this new addition. |
This function will allow us to have a tickless wakeup from deepstop using a low-speed RTC timer.