-
Notifications
You must be signed in to change notification settings - Fork 40
Feature request: MCU sleep, when all tasks in delay() #31
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
Comments
@hattesen Thanks for your Christmas Feature Request. This functionality was available in an early implementation (and actually available in Cosa). To minimize the size of the library this was removed as it required 1) a background task to perform the sleep mode, 2) alternative delay() implementation. |
@mikaelpatel wasn't aware of the previous implementation and the rationale for removing it. It is always a delicate balance between features, complexity and memory footprint. A user-domain example of how to manage MCU sleep mode would be good. Intercepting calls to delay() would be able to maintain an I may have a go at an implementation myself, and issue a pull request. |
@hattesen |
Sketch of implementation:
|
The implementation sketch that you have provided, keeping a running count of the number of tasks, NOT currently executing a The implementation Scheduler.delay(ms) works for any tasks that explicitly calls this implementation from within their As I understand the problem, the Arduino Core
... obviously, it would require a way to be able to "inject" linker options into the build process, which is probably not straightforward, or even possible, when using the Arduino IDE. |
Any movement on this? |
@infinity-computers-dot-net |
For devices where power consumption should be minimized (e.g. battery operated equipment), it would be a great if the Scheduler library would be able to identify situations, where all the executing tasks are inside a
delay()
, and in those situations enter a low-power sleep mode.In embedded systems, it is often the case, that many tasks only need to run once every tens or hundreds of milliseconds, and when reading temperature sensors, one reading per second is often more than enough.
If the code for the tasks would include a call to
delay()
(possibly at the end of thetaskLoop()
function) rather than a call toyield()
, it would result in all tasks executing code inside thedelay()
implementation (measuring elapsed time and callingyield()
), effectively busy-waiting, as no tasks require any task code to be run.Implementation
It would be fairly trivial to provide an option (
#define DELAY_SLEEP
) that, when enabled, at the start of thedelay()
implementation, would traverse the task list and identify if all tasks are currently executing adelay()
, and if so, determine the number of microseconds left until the first task is scheduled to exit thedelay()
function, and return to thetaskLoop()
code. The MCU could, at that point, be put into one of the sleep modes supported by the MCU.The optimal sleep mode depends on the concrete application and MCU architecture, and should be chosen based on a number of parameters:
Choosing the optimal sleep mode will always be a balance between power consumption and responsiveness to events.
My proposal is to leave it up to the Scheduler library user, to provide a suitable implementation (function pointer) to put the MCU into a suitable sleep mode, for a specified number of micro-seconds
sleep(microSec)
. It would be up to this user provided sleep implementation, to...delay()
task executions.The text was updated successfully, but these errors were encountered: