oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
pm.h
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
34#ifndef OVE_PM_H
35#define OVE_PM_H
36
37#include "ove/types.h"
38#include "ove/gpio.h"
39#include "ove_config.h"
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45/* ── Enumerations ───────────────────────────────────────────────────── */
46
50typedef enum {
55 OVE_PM_STATE_COUNT = 4,
57
67
71typedef enum {
72 OVE_PM_DOMAIN_RADIO = 0,
73 OVE_PM_DOMAIN_SENSOR = 1,
74 OVE_PM_DOMAIN_DISPLAY = 2,
75 OVE_PM_DOMAIN_AUDIO = 3,
76 OVE_PM_DOMAIN_STORAGE = 4,
77 OVE_PM_DOMAIN_COMMS = 5,
78 OVE_PM_DOMAIN_USER0 = 6,
79 OVE_PM_DOMAIN_USER1 = 7,
80 OVE_PM_DOMAIN_COUNT = 8,
82
90
91/* ── Structures ─────────────────────────────────────────────────────── */
92
101
107 union {
108 struct {
109 unsigned int port;
110 unsigned int pin;
113 struct {
114 uint32_t timeout_ms;
116 struct {
117 unsigned int instance;
119 struct {
120 uint32_t alarm_ms;
121 } rtc;
122 };
123};
124
129 uint64_t time_in_state_us[OVE_PM_STATE_COUNT];
130 uint32_t transition_count[OVE_PM_STATE_COUNT];
133};
134
135/* ── Callback types ─────────────────────────────────────────────────── */
136
147 uint32_t idle_ms,
148 uint32_t next_timeout_ms,
149 void *user_data);
150
159typedef void (*ove_pm_notify_fn)(ove_pm_event_t event,
160 ove_pm_state_t from_state,
161 ove_pm_state_t to_state,
162 void *user_data);
163
164/* ── Public API ─────────────────────────────────────────────────────── */
165
166#ifdef CONFIG_OVE_PM
167
174int ove_pm_init(const struct ove_pm_cfg *cfg);
175
179void ove_pm_deinit(void);
180
187int ove_pm_set_state(ove_pm_state_t state);
188
194ove_pm_state_t ove_pm_get_state(void);
195
201void ove_pm_activity(void);
202
209int ove_pm_wake_register(const struct ove_pm_wake_src *src);
210
217int ove_pm_wake_unregister(const struct ove_pm_wake_src *src);
218
227int ove_pm_domain_request(ove_pm_domain_t domain);
228
237int ove_pm_domain_release(ove_pm_domain_t domain);
238
245int ove_pm_domain_get_refcount(ove_pm_domain_t domain);
246
257int ove_pm_set_policy(ove_pm_policy_fn policy, void *user_data);
258
266int ove_pm_notify_register(ove_pm_notify_fn cb, void *user_data);
267
275int ove_pm_notify_unregister(ove_pm_notify_fn cb, void *user_data);
276
283int ove_pm_get_stats(struct ove_pm_stats *stats);
284
288void ove_pm_reset_stats(void);
289
296int ove_pm_set_budget(uint32_t target_low_power_pct_x100);
297
304int ove_pm_get_budget_status(uint32_t *actual_pct_x100);
305
313void ove_pm_idle_process(void);
314
315#else /* !CONFIG_OVE_PM */
316
317static inline int ove_pm_init(const struct ove_pm_cfg *c) { (void)c; return OVE_ERR_NOT_SUPPORTED; }
318static inline void ove_pm_deinit(void) {}
319static inline int ove_pm_set_state(ove_pm_state_t s) { (void)s; return OVE_ERR_NOT_SUPPORTED; }
320static inline ove_pm_state_t ove_pm_get_state(void) { return OVE_PM_STATE_ACTIVE; }
321static inline void ove_pm_activity(void) {}
322static inline int ove_pm_wake_register(const struct ove_pm_wake_src *s) { (void)s; return OVE_ERR_NOT_SUPPORTED; }
323static inline int ove_pm_wake_unregister(const struct ove_pm_wake_src *s) { (void)s; return OVE_ERR_NOT_SUPPORTED; }
324static inline int ove_pm_domain_request(ove_pm_domain_t d) { (void)d; return OVE_ERR_NOT_SUPPORTED; }
325static inline int ove_pm_domain_release(ove_pm_domain_t d) { (void)d; return OVE_ERR_NOT_SUPPORTED; }
326static inline int ove_pm_domain_get_refcount(ove_pm_domain_t d) { (void)d; return OVE_ERR_NOT_SUPPORTED; }
327static inline int ove_pm_set_policy(ove_pm_policy_fn p, void *u) { (void)p; (void)u; return OVE_ERR_NOT_SUPPORTED; }
328static inline int ove_pm_notify_register(ove_pm_notify_fn c, void *u) { (void)c; (void)u; return OVE_ERR_NOT_SUPPORTED; }
329static inline int ove_pm_notify_unregister(ove_pm_notify_fn c, void *u) { (void)c; (void)u; return OVE_ERR_NOT_SUPPORTED; }
330static inline int ove_pm_get_stats(struct ove_pm_stats *s) { (void)s; return OVE_ERR_NOT_SUPPORTED; }
331static inline void ove_pm_reset_stats(void) {}
332static inline int ove_pm_set_budget(uint32_t t) { (void)t; return OVE_ERR_NOT_SUPPORTED; }
333static inline int ove_pm_get_budget_status(uint32_t *a) { (void)a; return OVE_ERR_NOT_SUPPORTED; }
334static inline void ove_pm_idle_process(void) {}
335
336#endif /* CONFIG_OVE_PM */
337
338#ifdef __cplusplus
339}
340#endif
341
/* end of ove_pm group */
343
344#endif /* OVE_PM_H */
ove_gpio_irq_mode_t
GPIO interrupt trigger edge selection (re-exported for BSP-only callers).
Definition bsp.h:48
ove_pm_state_t
System power states, ordered by increasing sleep depth.
Definition pm.h:50
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:159
ove_pm_wake_type_t
Wake source types.
Definition pm.h:61
ove_pm_event_t
Transition event type for notification callbacks.
Definition pm.h:86
ove_pm_domain_t
Peripheral power domain identifiers.
Definition pm.h:71
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:146
@ OVE_PM_STATE_ACTIVE
Definition pm.h:51
@ OVE_PM_STATE_STANDBY
Definition pm.h:53
@ OVE_PM_STATE_IDLE
Definition pm.h:52
@ OVE_PM_STATE_DEEP_SLEEP
Definition pm.h:54
@ OVE_PM_WAKE_UART
Definition pm.h:64
@ OVE_PM_WAKE_TIMER
Definition pm.h:63
@ OVE_PM_WAKE_GPIO
Definition pm.h:62
@ OVE_PM_WAKE_RTC
Definition pm.h:65
@ OVE_PM_EVENT_PRE_SLEEP
Definition pm.h:87
@ OVE_PM_EVENT_POST_WAKE
Definition pm.h:88
#define OVE_ERR_NOT_SUPPORTED
The requested feature is not supported by the active backend.
Definition types.h:38
PM subsystem configuration.
Definition pm.h:96
uint32_t standby_threshold_ms
Definition pm.h:98
uint32_t deep_sleep_threshold_ms
Definition pm.h:99
uint32_t idle_threshold_ms
Definition pm.h:97
Runtime power statistics.
Definition pm.h:128
uint32_t active_pct_x100
Definition pm.h:132
uint32_t transition_count[OVE_PM_STATE_COUNT]
Definition pm.h:130
uint64_t total_runtime_us
Definition pm.h:131
uint64_t time_in_state_us[OVE_PM_STATE_COUNT]
Definition pm.h:129
Wake source descriptor.
Definition pm.h:105
struct ove_pm_wake_src::@4::@8 uart
struct ove_pm_wake_src::@4::@7 timer
ove_pm_wake_type_t type
Definition pm.h:106
struct ove_pm_wake_src::@4::@9 rtc
struct ove_pm_wake_src::@4::@6 gpio