Function deep_sleep_ready

Source
pub fn deep_sleep_ready() -> bool
Expand description

Determines if the chip can safely go into deep sleep without preventing currently active peripherals from operating.

We look at the PM’s clock mask registers and compare them against a set of known masks that include no peripherals that can’t operate in deep sleep (or that have no function during sleep). Specifically:

  • HSB may only have clocks for the flash (and PicoCache), APBx bridges, and PDCA on.

  • PBA may only have I2C Slaves on as they can self-wake.

  • PBB may only have clocks for the flash, HRAMC1 (also flash related), and PDCA on.

  • PBC and PBD may have any clocks on.

This means it is the responsibility of each peripheral to disable it’s clock mask whenever it is idle.

A special note here regarding the PDCA (Peripheral DMA Controller) clock. If the core deep sleeps while a DMA operation is active, it is transparently paused and resumed when the core wakes again. If a peripheral needs a DMA operation to complete before sleeping, the peripheral should inhibit sleep. The rationale here is to allow deep sleep for an I2C Slave peripheral configured to use DMA.

We also special case GPIO (which is in PBCMASK), and just see if any interrupts are pending through the INTERRUPT_COUNT variable.