[riot-devel] How to properly use cortexm_sleep

Juan Ignacio Carrano j.carrano at fu-berlin.de
Mon May 27 14:17:01 CEST 2019


Hi Kees,

Some observations:

1- WFI will not send you to the deepest sleep states- clocks are gated, 
but many things remain powered.

2- If you are using the timer module and depending on you clock 
configuration you may experience more or less frequent wake ups. Whether
this is acceptable is up to you.

3- Normally, if no thread is runnable (i.e. all are waiting/blocked) the
idle thread is run and that has a loop which sends the MCU to the 
deepest state possible (considering the currently-enabled peripherals). 
This means that in many cases the explicit WFI is not needed if in your
"while(forever)" loop you put some call that blocks waiting for the 
events you are interested in.

The interaction between (1) and (3) means that by doing a WFI in a 
thread it is possible that you don't sleep as deep as you could:

- The current thread will be blocked on the WFI instruction until an
   event arrives.
- In the meantime, control will not go back to the kernel.
- This means the idle thread will not run (from the schedulers point of
   view, you thread is still running).
- The pm_whatever() call in the idle thread will not run.

In conclusion, try to use the default mechanism if you can.

Regards,

Juan.


More information about the devel mailing list