7#ifndef _HARDWARE_POWMAN_H
8#define _HARDWARE_POWMAN_H
11#include "hardware/structs/powman.h"
26#ifndef PARAM_ASSERTIONS_ENABLED_HARDWARE_POWMAN
27#define PARAM_ASSERTIONS_ENABLED_HARDWARE_POWMAN 0
31#ifndef PICO_POWMAN_CALIBRATE_LPOSC_FROM_OTP
32#define PICO_POWMAN_CALIBRATE_LPOSC_FROM_OTP 1
134 invalid_params_if(HARDWARE_POWMAN, bits >> 16);
148 invalid_params_if(HARDWARE_POWMAN, bits >> 16);
156 return powman_hw->timer & POWMAN_TIMER_RUN_BITS;
202 POWMAN_POWER_DOMAIN_COUNT = 4,
206typedef uint32_t powman_power_state;
209#define pstate_bitset_none() fixed_bitset_with_fill(pstate_bitset_t, POWMAN_POWER_DOMAIN_COUNT, 0)
210#define pstate_bitset_all() fixed_bitset_with_fill(pstate_bitset_t, POWMAN_POWER_DOMAIN_COUNT, 1)
212static inline pstate_bitset_t *pstate_bitset_remove_all(pstate_bitset_t *domains) {
217static inline pstate_bitset_t *pstate_bitset_add_all(pstate_bitset_t *domains) {
222static inline pstate_bitset_t *pstate_bitset_add(pstate_bitset_t *domains, powman_power_domain_t domain) {
227static inline pstate_bitset_t *pstate_bitset_remove(pstate_bitset_t *domains, powman_power_domain_t domain) {
232static inline bool pstate_bitset_is_set(pstate_bitset_t *domains, powman_power_domain_t domain) {
236static inline bool pstate_bitset_none_set(pstate_bitset_t *domains) {
240static inline pstate_bitset_t *pstate_bitset_from_powman_power_state(pstate_bitset_t *domains, powman_power_state pstate) {
241 static_assert(
sizeof(powman_power_state) <=
sizeof(uint32_t),
"");
246static inline powman_power_state pstate_bitset_to_powman_power_state(pstate_bitset_t *domains) {
268#define POWMAN_POWER_STATE_NONE 0
276 invalid_params_if(HARDWARE_POWMAN, domain >= POWMAN_POWER_DOMAIN_COUNT);
277 return orig | (1u << domain);
286 invalid_params_if(HARDWARE_POWMAN, domain >= POWMAN_POWER_DOMAIN_COUNT);
287 return orig &= ~(1u << domain);
296 invalid_params_if(HARDWARE_POWMAN, domain >= POWMAN_POWER_DOMAIN_COUNT);
297 return state & (1u << domain);
static fixed_bitset_t * fixed_bitset_clear(fixed_bitset_t *bitset, uint bit_index)
Clear a single bit in the bitset.
Definition fixed_bitset.h:202
bool fixed_bitset_is_empty(fixed_bitset_t *bitset)
Determine if bitset is empty.
Definition fixed_bitset.c:17
static fixed_bitset_t * fixed_bitset_set(fixed_bitset_t *bitset, uint bit_index)
Set a single bit in the bitset.
Definition fixed_bitset.h:188
static bool fixed_bitset_get(const fixed_bitset_t *bitset, uint bit_index)
Get the value of a single bit in the bitset.
Definition fixed_bitset.h:231
static fixed_bitset_t * fixed_bitset_clear_all(fixed_bitset_t *bitset)
Clear all bits in the bitset.
Definition fixed_bitset.h:151
#define fixed_bitset_type(N)
Macro used to define a fixed-size bitset of a given size.
Definition fixed_bitset.h:48
static fixed_bitset_t * fixed_bitset_set_all(fixed_bitset_t *bitset)
Set all bits in the bitset.
Definition fixed_bitset.h:162
static uint32_t fixed_bitset_read_word(const fixed_bitset_t *bitset, uint word_num)
Read a word in the bitset.
Definition fixed_bitset.h:138
static fixed_bitset_t * fixed_bitset_write_word(fixed_bitset_t *bitset, uint word_num, uint32_t value)
Write a word in the bitset.
Definition fixed_bitset.h:124
static __force_inline void hw_set_bits(io_rw_32 *addr, uint32_t mask)
Atomically set the specified bits to 1 in a HW register.
Definition address_mapped.h:135
static __force_inline void hw_clear_bits(io_rw_32 *addr, uint32_t mask)
Atomically clear the specified bits to 0 in a HW register.
Definition address_mapped.h:145
static void powman_timer_start(void)
Start the powman timer.
Definition powman.h:180
void powman_timer_set_1khz_tick_source_lposc(void)
Use the ~32KHz low power oscillator as the powman timer source.
Definition powman.c:85
static void powman_set_debug_power_request_ignored(bool ignored)
Ignore wake up when the debugger is attached.
Definition powman.h:349
void powman_enable_alarm_wakeup_at_ms(uint64_t alarm_time_ms)
Wake up from an alarm at a given time.
Definition powman.c:283
static bool powman_power_state_is_domain_on(powman_power_state state, enum powman_power_domains domain)
Helper function to check if a domain is on in a given powman_power_state.
Definition powman.h:295
int powman_set_power_state(powman_power_state state)
Set the power state.
Definition powman.c:191
void powman_timer_enable_gpio_1hz_sync(uint32_t gpio)
Use a 1Hz external signal as the powman timer source for seconds only.
Definition powman.c:170
static void powman_clear_alarm(void)
Clears the powman alarm.
Definition powman.h:190
void powman_timer_disable_gpio_1hz_sync(void)
Stop using 1Hz external signal as the powman timer source for seconds.
Definition powman.c:175
static void powman_clear_bits(volatile uint32_t *reg, uint32_t bits)
hw_clear_bits helper function
Definition powman.h:147
void powman_disable_alarm_wakeup(void)
Disable waking up from alarm.
Definition powman.c:288
static bool powman_timer_is_running(void)
Determine if the powman timer is running.
Definition powman.h:155
static void powman_timer_stop(void)
Stop the powman timer.
Definition powman.h:165
uint64_t powman_timer_get_ms(void)
Returns current time in ms.
Definition powman.c:49
void powman_timer_set_1khz_tick_source_gpio(uint32_t gpio)
Use a 1KHz external tick as the powman timer source.
Definition powman.c:165
static void powman_timer_pause(void)
Pause the powman timer.
Definition powman.h:172
bool powman_configure_wakeup_state(powman_power_state sleep_state, powman_power_state wakeup_state)
Configure sleep state and wakeup state.
Definition powman.c:235
static void powman_set_bits(volatile uint32_t *reg, uint32_t bits)
hw_set_bits helper function
Definition powman.h:133
void powman_timer_set_1khz_tick_source_xosc_with_hz(uint32_t xosc_freq_hz)
Use the crystal oscillator (specifying frequency) as the powman timer source.
Definition powman.c:116
void powman_timer_set_1khz_tick_source_xosc(void)
Use the crystal oscillator as the powman timer source.
Definition powman.c:112
void powman_timer_set_ms(uint64_t time_ms)
Set current time in ms.
Definition powman.c:39
void powman_enable_gpio_wakeup(uint gpio_wakeup_num, uint32_t gpio, bool edge, bool high)
Wake up from a gpio.
Definition powman.c:293
powman_power_state powman_get_power_state(void)
Get the current power state.
Definition powman.c:179
void powman_timer_enable_alarm_at_ms(uint64_t alarm_time_ms)
Set an alarm at an absolute time in ms.
Definition powman.c:265
void powman_timer_set_1khz_tick_source_lposc_with_hz(uint32_t lposc_freq_hz)
Use the low power oscillator (specifying frequency) as the powman timer source.
Definition powman.c:89
void powman_disable_all_wakeups(void)
Disable all wakeup sources.
Definition powman.c:317
powman_power_domains
Power domains of powman.
Definition powman.h:197
static powman_power_state powman_power_state_with_domain_off(powman_power_state orig, enum powman_power_domains domain)
Helper function modify a powman_power_state to turn a domain off.
Definition powman.h:285
uint32_t powman_timer_get_lposc_calib_freq(void)
Get the calibrated frequency of the low power oscillator.
Definition powman.c:67
void powman_disable_gpio_wakeup(uint gpio_wakeup_num)
Disable wake up from a gpio.
Definition powman.c:312
static powman_power_state powman_power_state_with_domain_on(powman_power_state orig, enum powman_power_domains domain)
Helper function modify a powman_power_state to turn a domain on.
Definition powman.h:275
void powman_timer_disable_alarm(void)
Disable the alarm.
Definition powman.c:278
@ POWMAN_POWER_DOMAIN_SRAM_BANK1
bank1 includes the top 256K of sram plus sram 8 and 9 (scratch x and scratch y)
Definition powman.h:198
@ POWMAN_POWER_DOMAIN_SRAM_BANK0
bank0 is bottom 256K of sSRAM
Definition powman.h:199
@ POWMAN_POWER_DOMAIN_XIP_CACHE
XIP cache is 2x8K instances.
Definition powman.h:200
@ POWMAN_POWER_DOMAIN_SWITCHED_CORE
Switched core logic (processors, busfabric, peris etc).
Definition powman.h:201