File syn_sleep.h¶
FileList > src > syntropic > system > syn_sleep.h
Go to the source code of this file
Sleep coordinator — low-power mode management. More...
#include "../common/syn_defs.h"#include <stdbool.h>#include <stdint.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_Sleep Sleep coordinator — tracks wake locks and sleep statistics. |
Public Types¶
| Type | Name |
|---|---|
| enum | SYN_SleepMode Sleep depth selector. |
Public Functions¶
| Type | Name |
|---|---|
| void | syn_port_sleep (SYN_SleepMode mode) Enter low-power mode. Implement for your platform. |
Public Static Functions¶
| Type | Name |
|---|---|
| bool | syn_sleep_any_locked (const SYN_Sleep * s) Check if any lock is held. |
| void | syn_sleep_enable (SYN_Sleep * s, bool en) Enable/disable sleep globally. |
| bool | syn_sleep_enter (SYN_Sleep * s) Try to enter sleep mode. |
| void | syn_sleep_init (SYN_Sleep * s, SYN_SleepMode max_depth) Initialize the sleep coordinator. |
| bool | syn_sleep_is_locked (const SYN_Sleep * s, uint32_t lock_id) Check if a specific lock is held. |
| void | syn_sleep_lock (SYN_Sleep * s, uint32_t lock_id) Acquire a wake lock (prevents sleep). |
| uint32_t | syn_sleep_locks (const SYN_Sleep * s) Get active lock mask (for debug). |
| void | syn_sleep_unlock (SYN_Sleep * s, uint32_t lock_id) Release a wake lock. |
Macros¶
| Type | Name |
|---|---|
| define | SYN_SLEEP_LOCK_ADC (1u << 4) |
| define | SYN_SLEEP_LOCK_APP0 (1u << 8) |
| define | SYN_SLEEP_LOCK_APP1 (1u << 9) |
| define | SYN_SLEEP_LOCK_APP2 (1u << 10) |
| define | SYN_SLEEP_LOCK_APP3 (1u << 11) |
| define | SYN_SLEEP_LOCK_DMA (1u << 3) |
| define | SYN_SLEEP_LOCK_I2C (1u << 2) |
| define | SYN_SLEEP_LOCK_SPI (1u << 1) |
| define | SYN_SLEEP_LOCK_TIMER (1u << 5) |
| define | SYN_SLEEP_LOCK_UART (1u << 0) |
Detailed Description¶
Coordinates sleep entry with the scheduler. When all tasks are idle (or only timer-blocked), the system can enter a low-power mode. Clients can veto sleep by holding a "stay awake" lock.
** **
- Each subsystem that needs the CPU awake holds a lock.
- When all locks are released, the scheduler calls syn_sleep_enter() which invokes the port sleep function.
- Interrupts wake the MCU, and the scheduler resumes.
** **
SYN_Sleep sleep;
syn_sleep_init(&sleep, SYN_SLEEP_LIGHT);
// UART ISR: hold lock while transmitting
syn_sleep_lock(&sleep, SYN_SLEEP_LOCK_UART);
// ... transmit complete ...
syn_sleep_unlock(&sleep, SYN_SLEEP_LOCK_UART);
// In scheduler idle hook:
syn_sleep_enter(&sleep); // sleeps only if no locks held
Public Types Documentation¶
enum SYN_SleepMode¶
Sleep depth selector.
Public Functions Documentation¶
function syn_port_sleep¶
Enter low-power mode. Implement for your platform.
For Cortex-M: SYN_SLEEP_LIGHT → WFI, SYN_SLEEP_DEEP → STOP mode. Must return when an interrupt wakes the MCU.
Parameters:
modeRequested sleep depth.
Public Static Functions Documentation¶
function syn_sleep_any_locked¶
Check if any lock is held.
Parameters:
sSleep instance.
Returns:
true if any lock is active.
function syn_sleep_enable¶
Enable/disable sleep globally.
Parameters:
sSleep instance.entrue to enable, false to disable.
function syn_sleep_enter¶
Try to enter sleep mode.
If no locks are held and sleep is enabled, calls syn_port_sleep().
Parameters:
sSleep instance.
Returns:
true if we actually slept, false if vetoed.
function syn_sleep_init¶
Initialize the sleep coordinator.
Parameters:
sSleep instance.max_depthDeepest sleep mode allowed.
function syn_sleep_is_locked¶
Check if a specific lock is held.
Parameters:
sSleep instance.lock_idLock bitmask to check.
Returns:
true if the lock is active.
function syn_sleep_lock¶
Acquire a wake lock (prevents sleep).
Parameters:
sSleep instance.lock_idLock bitmask (e.g. SYN_SLEEP_LOCK_UART).
function syn_sleep_locks¶
Get active lock mask (for debug).
Parameters:
sSleep instance.
Returns:
Active lock bitmask.
function syn_sleep_unlock¶
Release a wake lock.
Parameters:
sSleep instance.lock_idLock bitmask to release.
Macro Definition Documentation¶
define SYN_SLEEP_LOCK_ADC¶
ADC conversion in progress
define SYN_SLEEP_LOCK_APP0¶
Application-defined lock 0
define SYN_SLEEP_LOCK_APP1¶
Application-defined lock 1
define SYN_SLEEP_LOCK_APP2¶
Application-defined lock 2
define SYN_SLEEP_LOCK_APP3¶
Application-defined lock 3
define SYN_SLEEP_LOCK_DMA¶
DMA transfer in progress
define SYN_SLEEP_LOCK_I2C¶
I2C peripheral active
define SYN_SLEEP_LOCK_SPI¶
SPI peripheral active
define SYN_SLEEP_LOCK_TIMER¶
Hardware timer active
define SYN_SLEEP_LOCK_UART¶
UART peripheral active
The documentation for this class was generated from the following file src/syntropic/system/syn_sleep.h