9 years ago.

How best to restore clocks from sleep() or get back into EM0?

If I am mixing both asynch and synch API, but I also would like to go into sleep() mode when appropriate, how do I "wake up" from sleep, restore clocks, or go back to EM0 on command in the mbed environment?

Question relating to:

Silicon Labs a leading provider of microcontroller, sensing and wireless connectivity solutions for the Internet of Things (IoT).

1 Answer

9 years ago.

Hi Keith,

if you execute sleep(), the system will:

  • Save the clock state
  • See which peripherals are active (i.e. asynch operation in progress, timers set to expire, GPIO interrupt, ...)
  • Shut down unneeded clocks and go into the appropriate sleep mode

At this point, the core is suspended. When the core gets a wakeup trigger (Event or Interrupt in Cortex-M terms), for example from a finished asynch transfer, a timer that expired, or any other interrupt source, it will:

  • Execute the callback handler
  • Restore clocks according to the saved clock state
  • Resume execution by returning from sleep() in this order. This is why there are warnings all over the sample code to not depend on any particular clocking setup in your callback handler routine.

There is no such thing as waking up to EM0 "on command", since sleep() inherently suspends the core, which means execution is halted, so no more commands get executed.