Ersa Wearable Platform
Embedded smartwatch firmware and application framework
Loading...
Searching...
No Matches
power_management.h
Go to the documentation of this file.
1#pragma once
2
3#include <stddef.h>
4#include <stdint.h>
5
6namespace ersa::board { class Pins; }
7
8namespace ersa::hal {
9
11enum class PerformanceProfile : uint8_t {
18};
19
28public:
29 virtual ~IPowerManagement() = default;
31 virtual bool initialize() = 0;
33 virtual void tick() = 0;
35 virtual bool initializeWakeSources(const board::Pins& pins) = 0;
40 virtual void allowAutomaticSleep(bool allow) = 0;
42 virtual void waitForWake(uint32_t timeoutMs) = 0;
44 virtual void notifyWake() = 0;
49 virtual void enterDeepSleep(uint64_t timerUs) = 0;
56 virtual bool acquirePerformance(PerformanceProfile profile, const char* reason) = 0;
58 virtual void releasePerformance(PerformanceProfile profile, const char* reason) = 0;
60 virtual void reportPowerModes() = 0;
62 virtual bool getPowerModeReport(char* buffer, size_t capacity) = 0;
64 virtual bool setTestCpuFrequencyMHz(unsigned mhz) = 0;
66 virtual unsigned testCpuFrequencyMHz() const = 0;
67};
68
71public:
73 PerformanceScope(IPowerManagement& power, PerformanceProfile profile, const char* reason)
74 : power_(&power), profile_(profile), reason_(reason), acquired_(power.acquirePerformance(profile, reason)) {}
79private:
82 const char* reason_;
84};
85
86} // namespace ersa::hal
Definition pins.h:57
Definition power_management.h:27
virtual void enterDeepSleep(uint64_t timerUs)=0
virtual void allowAutomaticSleep(bool allow)=0
virtual void notifyWake()=0
virtual void waitForWake(uint32_t timeoutMs)=0
virtual bool initializeWakeSources(const board::Pins &pins)=0
Configure GPIO/button wake sources from the selected board's pin map.
virtual void reportPowerModes()=0
Emit a one-time power-mode diagnostic report.
virtual ~IPowerManagement()=default
virtual bool acquirePerformance(PerformanceProfile profile, const char *reason)=0
virtual bool initialize()=0
virtual bool setTestCpuFrequencyMHz(unsigned mhz)=0
Queue a development CPU-frequency override for the next controlled restart.
virtual bool getPowerModeReport(char *buffer, size_t capacity)=0
Copy a power-mode report into a caller-owned buffer.
virtual unsigned testCpuFrequencyMHz() const =0
Return the queued development CPU-frequency override, or zero for automatic mode.
virtual void releasePerformance(PerformanceProfile profile, const char *reason)=0
Release a performance profile acquired earlier.
Definition power_management.h:70
PerformanceProfile profile_
Definition power_management.h:81
~PerformanceScope()
Release the performance profile if it was successfully acquired.
Definition power_management.h:76
const char * reason_
Definition power_management.h:82
PerformanceScope(const PerformanceScope &)=delete
PerformanceScope(IPowerManagement &power, PerformanceProfile profile, const char *reason)
Acquire a workload profile and release it when this scope ends.
Definition power_management.h:73
IPowerManagement * power_
Definition power_management.h:80
bool acquired_
Definition power_management.h:83
PerformanceScope & operator=(const PerformanceScope &)=delete
Definition board.h:20
Definition battery.h:7
PerformanceProfile
Definition power_management.h:11
@ Interactive
Keep input and short event handling responsive while callbacks run.
@ Compute
Hold the platform's maximum CPU frequency for compute-heavy work.
@ DisplayRefresh
Hold the platform's display-safe frequency through drawing and refresh.