oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
Loading...
Searching...
No Matches
pm.hpp
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
15#pragma once
16
17#include <ove/pm.h>
18#include <ove/types.hpp>
19#include <ove/error.hpp>
20
21#ifdef CONFIG_OVE_PM
22
23namespace ove::pm
24{
25
34/* ── Enums (re-export C types for convenience) ──────────────────────── */
35
37using State = ove_pm_state_t;
39using WakeType = ove_pm_wake_type_t;
41using Domain = ove_pm_domain_t;
43using Event = ove_pm_event_t;
45using WakeSrc = ove_pm_wake_src;
47using Cfg = ove_pm_cfg;
49using Stats = ove_pm_stats;
50
51/* ── Lifecycle ──────────────────────────────────────────────────────── */
52
59[[nodiscard]] inline Result<void> init(const Cfg &cfg) noexcept
60{
61 return from_rc(ove_pm_init(&cfg));
62}
63
67inline void deinit()
68{
69 ove_pm_deinit();
70}
71
72/* ── State machine ──────────────────────────────────────────────────── */
73
80[[nodiscard]] inline Result<void> set_state(State state) noexcept
81{
82 return from_rc(ove_pm_set_state(state));
83}
84
90{
91 return ove_pm_get_state();
92}
93
100inline void activity()
101{
102 ove_pm_activity();
103}
104
105/* ── Wake sources ───────────────────────────────────────────────────── */
106
113[[nodiscard]] inline Result<void> wake_register(const WakeSrc &src) noexcept
114{
115 return from_rc(ove_pm_wake_register(&src));
116}
117
124[[nodiscard]] inline Result<void> wake_unregister(const WakeSrc &src) noexcept
125{
126 return from_rc(ove_pm_wake_unregister(&src));
127}
128
129/* ── Peripheral power domains ───────────────────────────────────────── */
130
137[[nodiscard]] inline Result<void> domain_request(Domain domain) noexcept
138{
139 return from_rc(ove_pm_domain_request(domain));
140}
141
148[[nodiscard]] inline Result<void> domain_release(Domain domain) noexcept
149{
150 return from_rc(ove_pm_domain_release(domain));
151}
152
159[[nodiscard]] inline Result<int> domain_get_refcount(Domain domain) noexcept
160{
161 const int rc = ove_pm_domain_get_refcount(domain);
162 if (rc >= 0)
163 return rc;
164 return std::unexpected{static_cast<Error>(rc)};
165}
166
167/* ── Policy ─────────────────────────────────────────────────────────── */
168
176[[nodiscard]] inline Result<void> set_policy(ove_pm_policy_fn policy,
177 void *user_data = nullptr) noexcept
178{
179 return from_rc(ove_pm_set_policy(policy, user_data));
180}
181
182/* ── Notifications ──────────────────────────────────────────────────── */
183
191[[nodiscard]] inline Result<void> notify_register(ove_pm_notify_fn cb,
192 void *user_data = nullptr) noexcept
193{
194 return from_rc(ove_pm_notify_register(cb, user_data));
195}
196
204[[nodiscard]] inline Result<void> notify_unregister(ove_pm_notify_fn cb,
205 void *user_data = nullptr) noexcept
206{
207 return from_rc(ove_pm_notify_unregister(cb, user_data));
208}
209
210/* ── Statistics ─────────────────────────────────────────────────────── */
211
217[[nodiscard]] inline Result<Stats> get_stats() noexcept
218{
219 Stats stats{};
220 const int rc = ove_pm_get_stats(&stats);
221 return from_rc(rc, stats);
222}
223
227inline void reset_stats()
228{
229 ove_pm_reset_stats();
230}
231
232/* ── Power budget ───────────────────────────────────────────────────── */
233
240[[nodiscard]] inline Result<void> set_budget(uint32_t target_pct_x100) noexcept
241{
242 return from_rc(ove_pm_set_budget(target_pct_x100));
243}
244
250[[nodiscard]] inline Result<uint32_t> get_budget_status() noexcept
251{
252 uint32_t actual_pct_x100 = 0;
253 const int rc = ove_pm_get_budget_status(&actual_pct_x100);
254 return from_rc(rc, actual_pct_x100);
255}
256
257/* ── Idle processing ────────────────────────────────────────────────── */
258
265inline void idle_process()
266{
267 ove_pm_idle_process();
268}
269
270} /* namespace ove::pm */
271
272#endif /* CONFIG_OVE_PM */
Strong ove::Error type, Result<T> alias, and std::error_code interop for the oveRTOS C++ binding.
Thin C++ wrappers around the oveRTOS power management API.
Definition pm.hpp:24
ove_pm_stats Stats
Aggregated runtime statistics (time in each state, etc.).
Definition pm.hpp:49
ove_pm_cfg Cfg
Runtime configuration consumed by init().
Definition pm.hpp:47
ove_pm_event_t Event
PM event delivered to subscribers (entering/exiting a state, etc.).
Definition pm.hpp:43
ove_pm_wake_src WakeSrc
Wake-source descriptor passed to enable_wake_src().
Definition pm.hpp:45
void reset_stats()
Reset all accumulated power statistics to zero.
Definition pm.hpp:227
State get_state()
Query the current power state.
Definition pm.hpp:89
Result< void > set_budget(uint32_t target_pct_x100) noexcept
Set a target percentage of time in low-power states.
Definition pm.hpp:240
Result< int > domain_get_refcount(Domain domain) noexcept
Query the current reference count for a domain.
Definition pm.hpp:159
void deinit()
Tear down the PM subsystem and release resources.
Definition pm.hpp:67
void activity()
Report system activity (ISR-safe).
Definition pm.hpp:100
Result< uint32_t > get_budget_status() noexcept
Query actual low-power percentage vs. budget target.
Definition pm.hpp:250
Result< void > wake_register(const WakeSrc &src) noexcept
Register a wake source.
Definition pm.hpp:113
Result< void > init(const Cfg &cfg) noexcept
Initialise the PM subsystem.
Definition pm.hpp:59
Result< void > notify_unregister(ove_pm_notify_fn cb, void *user_data=nullptr) noexcept
Unregister a transition notification callback.
Definition pm.hpp:204
ove_pm_wake_type_t WakeType
Wake-source kind (GPIO, RTC, timer, …).
Definition pm.hpp:39
Result< void > set_policy(ove_pm_policy_fn policy, void *user_data=nullptr) noexcept
Register a custom power policy callback.
Definition pm.hpp:176
Result< void > set_state(State state) noexcept
Request an explicit power state transition.
Definition pm.hpp:80
ove_pm_domain_t Domain
Peripheral power domain identifier.
Definition pm.hpp:41
Result< Stats > get_stats() noexcept
Query accumulated power statistics.
Definition pm.hpp:217
Result< void > notify_register(ove_pm_notify_fn cb, void *user_data=nullptr) noexcept
Register a transition notification callback.
Definition pm.hpp:191
ove_pm_state_t State
System power state (active / sleep / deep-sleep / off).
Definition pm.hpp:37
Result< void > domain_release(Domain domain) noexcept
Decrement the reference count for a peripheral power domain.
Definition pm.hpp:148
Result< void > domain_request(Domain domain) noexcept
Increment the reference count for a peripheral power domain.
Definition pm.hpp:137
void idle_process()
Process idle — drive the PM state machine.
Definition pm.hpp:265
Result< void > wake_unregister(const WakeSrc &src) noexcept
Unregister a previously registered wake source.
Definition pm.hpp:124
Result< void > from_rc(int rc) noexcept
Lifts a substrate rc-code into a Result<void>.
Definition error.hpp:254
Error
Strong-typed mirror of substrate OVE_ERR_* codes.
Definition error.hpp:64
std::expected< T, Error > Result
std::expected-based result alias.
Definition error.hpp:139
Common type definitions and concepts for the C++ wrapper layer.