Register / Login  |  Desktop view  |  Jump to bottom of page

IoAbstraction & TaskManagerIO » Taskmanager and slepping..

Author: lafleur
20/02/2021 15:50:57
If I have a number of tasks, and I put the CPU to sleep if an interrupt occurs, and I process the interrupt..

what is the best method to resume my sleep??

go back and use taskManager.microsToNextTask() to recompute my next wake time ??
or what other options??

Author: davetcc
20/02/2021 17:25:34
This is an advanced topic. There are so many possible combinations that it is probably beyond the scope of the forum to discuss them all.

However, task manager execution is driven by the runLoop() method, which you would normally call in the main() or loop() method, it checks if any tasks are ready to be executed and executes them if needed, it also evaluates any events if needed.

As you rightly pointed out below you can use microsToNextTask along with a low power library or call, to avoid busy waiting by repeatedly calling the runLoop method, in fact there is an example of this for SAMD here: https://www.thecoderscorner.com/products/arduino-libraries/taskmanager-io/task-manager-low-power-samd-example/. A major point to consider is that you must make sure that if you want to process interrupts, that the processor would be awakened from the sleep by that interrupt.

I would say the best way unless it doesn't work is to follow something similar to the example above.

Author: davetcc
20/02/2021 17:31:53
Also, let's say that you handled the interrupt as an event, you could either marshall the interrupt by using the task manager interrupt support, or you could have a raw interrupt handler instead and just trigger an event in the raw IRQ. As long as your sleep method woke up on the interrupt, set the event as triggered, then all should be good.

As with all signals, you should probably wake up occasionally and make sure that all state is as expected. You could add a task to task manager that scheduled every N seconds (or whatever was tolerable) that ensured everything was in a good state.

I would take a look at the events and interrupt sections of https://www.thecoderscorner.com/products/arduino-libraries/taskmanager-io/




Register / Login  |  Desktop view  |  Jump to top of page