oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
pm.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
35#ifndef OVE_PM_H
36#define OVE_PM_H
37
38#include "ove/types.h"
39#include "ove/gpio.h"
40#include "ove_config.h"
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/* ── Enumerations ───────────────────────────────────────────────────── */
47
51typedef enum {
56 OVE_PM_STATE_COUNT = 4,
58
68
72typedef enum {
73 OVE_PM_DOMAIN_RADIO = 0,
74 OVE_PM_DOMAIN_SENSOR = 1,
75 OVE_PM_DOMAIN_DISPLAY = 2,
76 OVE_PM_DOMAIN_AUDIO = 3,
77 OVE_PM_DOMAIN_STORAGE = 4,
78 OVE_PM_DOMAIN_COMMS = 5,
79 OVE_PM_DOMAIN_USER0 = 6,
80 OVE_PM_DOMAIN_USER1 = 7,
81 OVE_PM_DOMAIN_COUNT = 8,
83
91
92/* ── Structures ─────────────────────────────────────────────────────── */
93
102
108 union {
109 struct {
110 unsigned int port;
111 unsigned int pin;
114 struct {
115 uint32_t timeout_ms;
117 struct {
118 unsigned int instance;
120 struct {
121 uint32_t alarm_ms;
122 } rtc;
123 };
124};
125
130 uint64_t time_in_state_us[OVE_PM_STATE_COUNT];
131 uint32_t transition_count[OVE_PM_STATE_COUNT];
134};
135
136/* ── Callback types ─────────────────────────────────────────────────── */
137
147typedef ove_pm_state_t (*ove_pm_policy_fn)(ove_pm_state_t current, uint32_t idle_ms,
148 uint32_t next_timeout_ms, void *user_data);
149
158typedef void (*ove_pm_notify_fn)(ove_pm_event_t event, ove_pm_state_t from_state,
159 ove_pm_state_t to_state, void *user_data);
160
161/* ── Public API ─────────────────────────────────────────────────────── */
162
163#ifdef CONFIG_OVE_PM
164
171int ove_pm_init(const struct ove_pm_cfg *cfg);
172
176void ove_pm_deinit(void);
177
185
199
206
214
222
232
242
250
261int ove_pm_set_policy(ove_pm_policy_fn policy, void *user_data);
262
271
280
288
293
300int ove_pm_set_budget(uint32_t target_low_power_pct_x100);
301
308int ove_pm_get_budget_status(uint32_t *actual_pct_x100);
309
318
319#else /* !CONFIG_OVE_PM */
320
321static inline int ove_pm_init(const struct ove_pm_cfg *c)
322{
323 (void)c;
325}
326static inline void ove_pm_deinit(void)
327{
328}
329static inline int ove_pm_set_state(ove_pm_state_t s)
330{
331 (void)s;
333}
334static inline ove_pm_state_t ove_pm_get_state(void)
335{
336 return OVE_PM_STATE_ACTIVE;
337}
338static inline void ove_pm_activity(void)
339{
340}
341static inline int ove_pm_wake_register(const struct ove_pm_wake_src *s)
342{
343 (void)s;
345}
346static inline int ove_pm_wake_unregister(const struct ove_pm_wake_src *s)
347{
348 (void)s;
350}
351static inline int ove_pm_domain_request(ove_pm_domain_t d)
352{
353 (void)d;
355}
356static inline int ove_pm_domain_release(ove_pm_domain_t d)
357{
358 (void)d;
360}
362{
363 (void)d;
365}
366static inline int ove_pm_set_policy(ove_pm_policy_fn p, void *u)
367{
368 (void)p;
369 (void)u;
371}
372static inline int ove_pm_notify_register(ove_pm_notify_fn c, void *u)
373{
374 (void)c;
375 (void)u;
377}
378static inline int ove_pm_notify_unregister(ove_pm_notify_fn c, void *u)
379{
380 (void)c;
381 (void)u;
383}
384static inline int ove_pm_get_stats(struct ove_pm_stats *s)
385{
386 (void)s;
388}
389static inline void ove_pm_reset_stats(void)
390{
391}
392static inline int ove_pm_set_budget(uint32_t t)
393{
394 (void)t;
396}
397static inline int ove_pm_get_budget_status(uint32_t *a)
398{
399 (void)a;
401}
402static inline void ove_pm_idle_process(void)
403{
404}
405
406#endif /* CONFIG_OVE_PM */
407
408#ifdef __cplusplus
409}
410#endif
411
/* end of ove_pm group */
413
414#endif /* OVE_PM_H */
ove_gpio_irq_mode_t
GPIO interrupt trigger edge selection (re-exported for BSP-only callers).
Definition bsp.h:49
int ove_pm_set_policy(ove_pm_policy_fn policy, void *user_data)
Register a custom power policy callback.
int ove_pm_wake_unregister(const struct ove_pm_wake_src *src)
Unregister a previously registered wake source.
ove_pm_state_t
System power states, ordered by increasing sleep depth.
Definition pm.h:51
int ove_pm_set_state(ove_pm_state_t state)
Request an explicit transition to state.
void ove_pm_deinit(void)
Tear down the PM subsystem and release resources.
void(* ove_pm_notify_fn)(ove_pm_event_t event, ove_pm_state_t from_state, ove_pm_state_t to_state, void *user_data)
Transition notification callback.
Definition pm.h:158
int ove_pm_get_budget_status(uint32_t *actual_pct_x100)
Query actual low-power percentage vs. budget target.
int ove_pm_domain_release(ove_pm_domain_t domain)
Decrement the reference count for a peripheral power domain.
int ove_pm_domain_get_refcount(ove_pm_domain_t domain)
Query the current reference count for a domain.
void ove_pm_idle_process(void)
Process idle — called from RTOS idle context by the HAL.
ove_pm_wake_type_t
Wake source types.
Definition pm.h:62
int ove_pm_notify_register(ove_pm_notify_fn cb, void *user_data)
Register a transition notification callback.
void ove_pm_reset_stats(void)
Reset all accumulated power statistics to zero.
void ove_pm_activity(void)
Report system activity (resets idle timer).
int ove_pm_wake_register(const struct ove_pm_wake_src *src)
Register a wake source.
int ove_pm_init(const struct ove_pm_cfg *cfg)
Initialise the PM subsystem.
ove_pm_event_t
Transition event type for notification callbacks.
Definition pm.h:87
ove_pm_domain_t
Peripheral power domain identifiers.
Definition pm.h:72
int ove_pm_domain_request(ove_pm_domain_t domain)
Increment the reference count for a peripheral power domain.
int ove_pm_get_stats(struct ove_pm_stats *stats)
Query accumulated power statistics.
ove_pm_state_t(* ove_pm_policy_fn)(ove_pm_state_t current, uint32_t idle_ms, uint32_t next_timeout_ms, void *user_data)
Power policy callback — returns recommended next state.
Definition pm.h:147
int ove_pm_set_budget(uint32_t target_low_power_pct_x100)
Set a target percentage of time in low-power states.
ove_pm_state_t ove_pm_get_state(void)
Query the current power state.
int ove_pm_notify_unregister(ove_pm_notify_fn cb, void *user_data)
Unregister a transition notification callback.
@ OVE_PM_STATE_ACTIVE
Definition pm.h:52
@ OVE_PM_STATE_STANDBY
Definition pm.h:54
@ OVE_PM_STATE_IDLE
Definition pm.h:53
@ OVE_PM_STATE_DEEP_SLEEP
Definition pm.h:55
@ OVE_PM_WAKE_UART
Definition pm.h:65
@ OVE_PM_WAKE_TIMER
Definition pm.h:64
@ OVE_PM_WAKE_GPIO
Definition pm.h:63
@ OVE_PM_WAKE_RTC
Definition pm.h:66
@ OVE_PM_EVENT_PRE_SLEEP
Definition pm.h:88
@ OVE_PM_EVENT_POST_WAKE
Definition pm.h:89
@ OVE_ERR_NOT_SUPPORTED
Definition types.h:98
PM subsystem configuration.
Definition pm.h:97
uint32_t standby_threshold_ms
Definition pm.h:99
uint32_t deep_sleep_threshold_ms
Definition pm.h:100
uint32_t idle_threshold_ms
Definition pm.h:98
Runtime power statistics.
Definition pm.h:129
uint32_t active_pct_x100
Definition pm.h:133
uint32_t transition_count[OVE_PM_STATE_COUNT]
Definition pm.h:131
uint64_t total_runtime_us
Definition pm.h:132
uint64_t time_in_state_us[OVE_PM_STATE_COUNT]
Definition pm.h:130
Wake source descriptor.
Definition pm.h:106
struct ove_pm_wake_src::@5::@10 rtc
ove_pm_wake_type_t type
Definition pm.h:107
struct ove_pm_wake_src::@5::@7 gpio
struct ove_pm_wake_src::@5::@8 timer
struct ove_pm_wake_src::@5::@9 uart