---
title: "Power"
description: "System-power-mode control: run, sleep, deep-sleep, standby and stop — plus, since v0.17.0, RAM retention, a reported wake-capability contract, and SoM power domains that are quiesced around the deepest modes."
source: https://docs.alplab.ai/sdk/api/power
---

# `<alp/power.h>` — System Power

System-power-mode control: run, sleep, deep-sleep, standby and stop — plus, since v0.17.0, RAM retention, a reported wake-capability contract, and SoM power domains that are quiesced around the deepest modes.

## Header

```c
#include <alp/power.h>
```

## Quick example

```c
alp_power_t *p = alp_power_open();

// Declare which sources may wake the SoC (bitmap; replaces, not adds).
alp_power_configure_wake_source(p, ALP_POWER_WAKE_RTC | ALP_POWER_WAKE_GPIO);

// Enter deep sleep, waking after 30 s at the latest.
alp_power_wake_info_t info = { 0 };
alp_power_request_sleep(p, ALP_POWER_MODE_DEEP_SLEEP, 30 * 1000u, &info);

// ...wake-up handler: branch on info.wake_source / info.realised_mode...

alp_power_close(p);
```

## Modes

`alp_power_mode_t` selectors. Backends round to the closest SoC-supported mode; the realised mode is reported back in `alp_power_wake_info_t::realised_mode`.

| Mode                        | Description                                                   |
|-----------------------------|--------------------------------------------------------------|
| `ALP_POWER_MODE_RUN`        | Normal running mode (no sleep).                              |
| `ALP_POWER_MODE_SLEEP`      | CPU clock-gated; peripherals + RAM live.                     |
| `ALP_POWER_MODE_DEEP_SLEEP` | Clocks gated; RAM retained; vendor wake sources only.        |
| `ALP_POWER_MODE_STANDBY`    | Lowest power; RAM **not** retained; vendor wake only.        |
| `ALP_POWER_MODE_STOP`       | v0.17.0. Deepest rung: main-domain peripherals powered down, only the low-power island stays alive. Say what else to keep with `alp_power_configure_retention()`. |

Treat the modes as a monotonic ladder (deeper = lower power + longer wake). The exact wake latency and retained-state guarantees are SoC-defined and documented in the per-SoM HW reference. A backend without a distinct STOP state rounds down to its deepest supported mode and reports that honestly in `realised_mode`. On a multi-core SoC the realised mode is the **calling core's**: it reports STOP once this core's subsystem is powered off, while the SoC itself reaches STOP only when every core is off.

:::warning[STOP and STANDBY may not return]
SLEEP and DEEP_SLEEP resume the caller where it stopped. On a backend whose STOP / STANDBY rung powers the core down — the Alif Ensemble family, where wake is a **cold boot** through the Secure Enclave — `alp_power_request_sleep()` never returns: execution restarts from the reset vector and only retained RAM survives. Portable code must treat a STOP / STANDBY request as "may never return", keep state worth keeping in a retained region, and read the wake cause after boot with [`alp_power_boot_wake_info()`](#boot-wake-record) instead of from `alp_power_wake_info_t`.
:::

### Wake sources

OR together the `ALP_POWER_WAKE_*` bits passed to `alp_power_configure_wake_source`. The bitmap replaces, not adds to, the active set.

| Bit | Meaning |
|-----|---------|
| `ALP_POWER_WAKE_RTC` | RTC alarm / periodic tick. |
| `ALP_POWER_WAKE_GPIO` | Configured GPIO IRQ line. |
| `ALP_POWER_WAKE_UART_RX` | UART RX activity. |
| `ALP_POWER_WAKE_TIMER` | Free-running timer match. |
| `ALP_POWER_WAKE_USB` | USB SOF / VBUS event. |
| `ALP_POWER_WAKE_ETH_LINK` | Ethernet link-up / WoL packet. |
| `ALP_POWER_WAKE_COMPARATOR` | v0.17.0. Analog comparator threshold (e.g. LPCMP). |
| `ALP_POWER_WAKE_BROWNOUT` | v0.17.0. Brown-out / under-voltage detect. |

A sleep request with no configured wake source returns `ALP_ERR_INVAL`. When `wake_after_ms > 0` the backend arms a timed wake (RTC alarm or low-power timer, whichever the mode can use) even if `ALP_POWER_WAKE_RTC` was not set. The timed wake is never **early**: a backend with a coarse or inaccurate timer rounds the length up, so the actual sleep can be longer. Where the timed wake is a 32-bit low-power timer (e.g. the Alif LPTIMER) the value is bounded by that counter, and a longer request returns `ALP_ERR_INVAL`.

#### Reported wake capabilities (v0.17.0)

:::warning[Behaviour change in v0.17.0]
Unsupported wake bits are **no longer silently ignored.** `alp_power_configure_wake_source()` now returns `ALP_ERR_NOSUPPORT` for a bitmap containing any bit the active backend cannot arm, so a caller finds out at configuration time instead of after a sleep that never wakes.
:::

`alp_power_wake_capabilities(handle)` returns exactly the `ALP_POWER_WAKE_*` bits the active backend can arm (`0` for a `NULL` handle, or when no real power backend is linked). Build your bitmap from it:

```c
uint32_t can  = alp_power_wake_capabilities(p);
uint32_t want = ALP_POWER_WAKE_RTC | ALP_POWER_WAKE_GPIO;
alp_power_configure_wake_source(p, want & can);
```

It is deliberately a dedicated accessor, not a field of `alp_power_capabilities()`: that call returns the cross-class `alp_capabilities_t`, whose `flags` the power class does not use.

`alp_power_request_sleep()` also checks the configured bitmap against what the **requested mode** can arm — a source armable in SLEEP may not be armable in STOP — and returns `ALP_ERR_NOSUPPORT` with nothing changed on a mismatch. It likewise returns `ALP_ERR_NOSUPPORT` for `wake_after_ms > 0` when the mode can arm neither `ALP_POWER_WAKE_TIMER` nor `ALP_POWER_WAKE_RTC` (on backends that report per-mode capabilities).

### `alp_power_request_sleep` return codes

| Code | Cause |
|------|-------|
| `ALP_OK` | Slept and woke (for a mode that returns). |
| `ALP_ERR_INVAL` | No wake source and `wake_after_ms == 0`; `mode == RUN`; a timed wake beyond the backend's counter; or a domain policy that conflicts with an armed wake source. |
| `ALP_ERR_NOSUPPORT` | Includes a configured wake bitmap the requested mode cannot arm. |
| `ALP_ERR_NOT_READY` | Handle or backend not ready. |
| `ALP_ERR_IO` | Backend transport failure mid-cycle. |
| `ALP_ERR_BUSY` | Alif STOP backend: a debugger is attached, or an armed wake source is already pending, so the sleep would not hold or would end at once. |

## RAM retention

`[ABI-EXPERIMENTAL]` · new in v0.17.0

`alp_power_configure_retention(handle, &retain)` says how much RAM stays powered across the next sleep. It is optional — without it the backend uses its minimum for the requested mode (typically no application RAM) — and is called before `alp_power_request_sleep()`, like the wake-source call.

```c
alp_power_configure_retention(p, &(alp_power_retain_t){
    .level     = ALP_POWER_RETAIN_TCM,
    .retain_kb = 64,
});
```

| `alp_power_retain_level_t` | Meaning |
|----------------------------|---------|
| `ALP_POWER_RETAIN_NONE` | No application RAM retained. |
| `ALP_POWER_RETAIN_UTILITY` | Smallest SoC-guaranteed retained block. Backends without STOP retention return `ALP_ERR_NOSUPPORT`. |
| `ALP_POWER_RETAIN_TCM` | `retain_kb` KiB of tightly-coupled memory. The backend rounds **up** to its own retention granularity — a size that does not land exactly is never `NOSUPPORT`. |
| `ALP_POWER_RETAIN_FULL` | Every RAM block the requested mode supports retaining. |

Returns `ALP_OK`, `ALP_ERR_INVAL` (`NULL` `retain`, an out-of-range `level`, or `ALP_POWER_RETAIN_TCM` with `retain_kb == 0` — use `ALP_POWER_RETAIN_NONE` to retain nothing), `ALP_ERR_NOT_READY`, or `ALP_ERR_NOSUPPORT` when the backend cannot realise the footprint at all (no TCM retention, or `retain_kb` larger than the SoC's TCM).

:::note[Alif E8: the Utility SRAM belongs to the SDK]
With the Alif STOP backend, the E8's 4 KB Utility SRAM is always retained and reserved for the SDK (wake record, domain-restore state) — it is not application RAM at any level. The lowest floor the API can select is therefore the Utility-SRAM-retained rung (STOP_2, about 1.1 µA typical), and `ALP_POWER_RETAIN_UTILITY` behaves like `ALP_POWER_RETAIN_NONE` there: it returns `ALP_OK` and retains nothing extra.
:::

## SoM power domains

`[ABI-EXPERIMENTAL]` · new in v0.17.0 · implemented on E1M-AEN801 and E1M-AEN803

Before STOP or STANDBY the SDK can quiesce the on-module consumers that would otherwise draw power through the sleep, and restore them on the cold-boot wake. Domains are named by portable **role**, not by chip or pad, so the same code keeps working when the SoM is swapped within a family. Every other backend answers `ALP_ERR_NOSUPPORT`.

| `alp_power_domain_t` | Role |
|----------------------|------|
| `ALP_POWER_DOMAIN_WIFI_BLE` | Wi-Fi / BLE coprocessor. |
| `ALP_POWER_DOMAIN_ETH_PHY` | Ethernet PHY. |
| `ALP_POWER_DOMAIN_EXT_FLASH` | External (XIP / NOR) flash. |
| `ALP_POWER_DOMAIN_EXT_RAM` | External (Hyper / PSRAM) RAM. |
| `ALP_POWER_DOMAIN_TEMP_SENSOR` | On-module temperature sensor. |
| `ALP_POWER_DOMAIN_RTC` | On-module RTC — clock-out only; the time base is kept alive. |
| `ALP_POWER_DOMAIN_BACKLIGHT` | On-module backlight driver. |

`ALP_POWER_DOMAIN_COUNT` (`7`) bounds the enum; `ALP_POWER_DOMAIN_BIT(d)` gives a domain's bit in the boot-record bitmaps.

| Call | Notes |
|------|-------|
| `alp_power_domain_policy_set(handle, domain, policy)` | Sets the policy for the next STOP / STANDBY (SLEEP and DEEP_SLEEP never quiesce domains). Returns `ALP_ERR_INVAL` (out-of-range argument), `ALP_ERR_NOT_READY` (`NULL` or closed handle), `ALP_ERR_NOT_PRESENT_ON_THIS_SOC` (domain not populated on this SKU) or `ALP_ERR_NOSUPPORT` (no domain backend, or `RAIL_OFF` unavailable for the domain or its build-time gate off). |
| `alp_power_domain_info(domain, &info)` | Handle-less, read-only description of one domain. `info` is zero-filled first, so any non-OK return reads as "not present". |

| `alp_power_domain_policy_t` | Meaning |
|-----------------------------|---------|
| `ALP_POWER_DOMAIN_POLICY_AUTO` | Default — the SoM's safe default action for the mode (`alp_power_domain_info_t.default_action`). |
| `ALP_POWER_DOMAIN_POLICY_KEEP_ALIVE` | Never touched. |
| `ALP_POWER_DOMAIN_POLICY_RAIL_OFF` | Explicit supply gate. Opt-in: refused unless the SoM marks it available and its build-time gate (e.g. `CONFIG_ALP_SDK_SOM_PD_WIFI_RAIL_OFF`) is enabled. |

A policy that conflicts with the armed wake sources — e.g. `ALP_POWER_DOMAIN_RTC` at `RAIL_OFF` while `ALP_POWER_WAKE_RTC` is armed — is rejected at the sleep request with `ALP_ERR_INVAL` before anything changes.

`alp_power_domain_info_t` carries `present`, `holds_through_stop` (the quiesce state survives STOP itself rather than being re-applied at wake), `supported_actions` and `default_action` (`ALP_POWER_ACTION_HOLD_RESET`, `_POWERDOWN_PIN`, `_DEEP_POWER_DOWN_CMD`, `_SHUTDOWN_REG`, `_RAIL_OFF`), and `dependents` — other loads that quiescing the domain also affects (`ALP_POWER_DEP_CAM_LDO`, `ALP_POWER_DEP_SD_EN`, and `ALP_POWER_DEP_PHY_REFCLK`, the PHY's 50 MHz reference oscillator).

The domain runtime is `CONFIG_ALP_SDK_SOM_POWER`, on by default where the devicetree carries the SoM power-domain nodes (it needs `CONFIG_GPIO` and `CONFIG_PINCTRL`). Without it, every domain call returns `ALP_ERR_NOSUPPORT`.

### Boot wake record

`alp_power_boot_wake_info(&rec)` is the recovery path for a sleep that did not return: call it early in boot. It is handle-less and read-only; `rec` is zero-filled first.

```c
alp_power_boot_info_t rec;
if (alp_power_boot_wake_info(&rec) == ALP_OK && rec.valid) {
    printf("woke from mode %d by 0x%08x after %u ms\n",
           (int)rec.realised_mode, rec.wake_source, rec.slept_ms);
}
```

| Field | Notes |
|-------|-------|
| `valid` | A record from a completed cycle exists. `false` after a plain power-on reset (every other field is then zero). |
| `realised_mode` | Mode actually entered. |
| `wake_source` | The `ALP_POWER_WAKE_*` bit that fired. |
| `slept_ms` | Sleep duration, best effort. |
| `quiesced_domains` / `restored_domains` / `restore_failed_domains` | `ALP_POWER_DOMAIN_BIT()` bitmaps. A failed restore is reported, never fatal. |

A cycle interrupted by an external reset (a debugger nRESET, a reset button) is reported with `valid` true, `realised_mode == ALP_POWER_MODE_RUN` and `wake_source == 0`: the sleep was aborted, it did not wake. The record is written by the Alif STOP backend, so `valid` stays false on a build without it. Returns `ALP_OK`, `ALP_ERR_INVAL` (`NULL`) or `ALP_ERR_NOSUPPORT` (no backend keeps a wake record).

## Operating-point profiles

`[ABI-EXPERIMENTAL]` · new in v0.9

Some SoCs keep the power/clock tree behind a system-controller firmware: the application core never pokes PLL / DC-DC / power-domain registers directly — it reads and writes a per-core **profile** instead. This handle-less surface exposes the two profiles every such platform keeps: the active **RUN** operating point and the **STANDBY** (off/retention) operating point.

```c
alp_power_profile_t run = { 0 };
if (alp_power_profile_get(ALP_POWER_PROFILE_RUN, &run) == ALP_OK) {
    printf("RUN: %u Hz @ %u mV\n", run.cpu_clk_hz, run.rail_mv);
}

// Read-modify-write: only non-zero fields are applied; everything else
// keeps its current value.  Drops the core rail to 800 mV, touching nothing else.
alp_power_profile_set(ALP_POWER_PROFILE_RUN, &(alp_power_profile_t){ .rail_mv = 800 });
```

`which` selects the profile:

| Value | Meaning |
|-------|---------|
| `ALP_POWER_PROFILE_RUN` | The active operating point. |
| `ALP_POWER_PROFILE_STANDBY` | The standby/off operating point + wake configuration. |

### `alp_power_profile_t` fields

Frequencies are Hz; rails are millivolts. A zero field means *"unknown / not reported"* on `get` and *"keep the current value"* on `set`.

| Field | Type | Notes |
|-------|------|-------|
| `cpu_clk_hz` | `uint32_t` | Core clock of the calling core's domain, Hz. RUN = active CPU clock; STANDBY = standby-scaled clock. |
| `rail_mv` | `uint32_t` | Core DC-DC rail, millivolts. Per-SoM window (e.g. E8 / AEN801: 750–850 mV via the SE aiPM DC-DC); a value outside it returns `ALP_ERR_INVAL` from `set` without touching the live operating point. |
| `power_domains` | `uint32_t` | Implementation-defined bitmask of power domains held on in this profile. |
| `memory_blocks` | `uint32_t` | Implementation-defined bitmask of memory blocks retained/powered. |
| `wake_events` | `uint32_t` | Implementation-defined wake-event bitmask. Meaningful for STANDBY only; `0` for RUN. |
| `io_mv` | `uint32_t` | Flexible-IO bank rail, millivolts (e.g. `3300` or `1800`); `0` when the SoC has no switchable IO rail. |

:::caution
The `power_domains` / `memory_blocks` / `wake_events` bitmasks are **implementation-defined opaque tokens** — their bit legends are SoC-specific and documented in the per-SoM HW reference. Portable code must read-modify-write, log, or compare them; **never construct them from portable constants.**
:::

`alp_power_profile_get(which, out)` is read-only — nothing about the live operating point changes. On SoCs whose profiles live behind a system-controller firmware it is a bounded mailbox round-trip that never hangs. Returns `ALP_OK` / `ALP_ERR_INVAL` (NULL `out` or invalid `which`) / `ALP_ERR_NOSUPPORT` (no profile-capable backend) / `ALP_ERR_NOT_READY` (controller asleep, retryable) / `ALP_ERR_IO`.

`alp_power_profile_set(which, profile)` is a **read-modify-write** that **changes the live operating point.** The backend reads the current profile, overwrites exactly the fields set to a non-zero value, and writes the result back. Frequencies must match a value the silicon supports **exactly** — the backend never rounds, so a mismatch returns `ALP_ERR_INVAL`. `wake_events` is writable only on the STANDBY profile. Returns the same codes as `get`.

:::danger
`alp_power_profile_set` changes the live power/clock operating point. A wrong rail voltage or clock selection can brown out the core or stall the SoC — treat every call like a firmware update: know the target values from the per-SoM HW reference and have a recovery plan before running it on hardware.
:::

## Backends

The application API is identical across backends; each maps the portable modes and wake sources onto its platform:

- **Zephyr** — the SoC's PM policy / stub backend.
- **Alif SE profile** — the Ensemble system-controller operating-point path (see the profile API above).
- **Alif SE STOP / STANDBY** — new in v0.17.0, `CONFIG_ALP_SDK_POWER_ALIF_SE` (**experimental, default off**) on the Alif Ensemble E8 M55-HE and M55-HP. It builds a complete OFF profile for the Secure Enclave, quiesces the SoM power domains, arms the wake source (the on-module RV-3028 RTC, the low-power timer for short intervals, or application wake pads named in the devicetree with an `alp,power-wake-gpios` node for `ALP_POWER_WAKE_GPIO`) and enters the subsystem-off sleep; wake is a cold boot. STOP is bench-proven on the E1M-AEN803 M55-HE; STANDBY is not. On the M55-HP, STOP is bench-proven on the E1M-AEN803 only (the AEN801 HP is not verified); the HP has STOP only (STANDBY returns `ALP_ERR_NOSUPPORT`), no TCM retention, and needs an MRAM-booted image. With the other core still running, a STOP powers down only the calling core's subsystem. The `aen-power-stop` example exercises it.
- **V2N GD32-supervisor** — sleep entered via the on-module supervisor.
- **Yocto / Linux** — new in v0.13.0: `alp_power_request_sleep` drives `/sys/power/state` (`freeze` / `standby` / `mem`) and arms the RTC wakealarm for a timed wake; errno-mapped failures are surfaced, never swallowed. Real-board confirmation is a later bench step.

:::danger[Alif STOP backend: keep a way to restore the MRAM image]
An image that gets the STOP entry sequence wrong can stop at the Secure Enclave until the module is power-cycled. Keep a way to re-flash MRAM before enabling `CONFIG_ALP_SDK_POWER_ALIF_SE`.
:::

## See also

- [`<alp/wdt.h>`](https://docs.alplab.ai/sdk/api/wdt) — wake from watchdog
- [`<alp/rtc.h>`](https://docs.alplab.ai/sdk/api/rtc) — wake on alarm
- [`<alp/temperature.h>`](https://docs.alplab.ai/sdk/api/temperature) — on-module temperature sensor (one of the quiescable domains)
