v2.0.0
powman.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _HARDWARE_POWMAN_H
8#define _HARDWARE_POWMAN_H
9
10#include "pico.h"
11#include "hardware/structs/powman.h"
12
20// PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_HARDWARE_POWMAN, Enable/disable hardware_powman assertions, type=bool, default=0, group=hardware_powman
21#ifndef PARAM_ASSERTIONS_ENABLED_HARDWARE_POWMAN
22#define PARAM_ASSERTIONS_ENABLED_HARDWARE_POWMAN 0
23#endif
24
28void powman_timer_set_1khz_tick_source_lposc(void);
29
34void powman_timer_set_1khz_tick_source_lposc_with_hz(uint32_t lposc_freq_hz);
35
39void powman_timer_set_1khz_tick_source_xosc(void);
40
45void powman_timer_set_1khz_tick_source_xosc_with_hz(uint32_t xosc_freq_hz);
46
51void powman_timer_set_1khz_tick_source_gpio(uint32_t gpio);
52
61void powman_timer_enable_gpio_1hz_sync(uint32_t gpio);
62
66void powman_timer_disable_gpio_1hz_sync(void);
67
71uint64_t powman_timer_get_ms(void);
72
78void powman_timer_set_ms(uint64_t time_ms);
79
88void powman_timer_enable_alarm_at_ms(uint64_t alarm_time_ms);
89
96void powman_timer_disable_alarm(void);
97
106 static inline void powman_set_bits(volatile uint32_t *reg, uint32_t bits) {
107 invalid_params_if(HARDWARE_POWMAN, bits >> 16);
108 hw_set_bits(reg, POWMAN_PASSWORD_BITS | bits);
109}
110
120 static inline void powman_clear_bits(volatile uint32_t *reg, uint32_t bits) {
121 invalid_params_if(HARDWARE_POWMAN, bits >> 16);
122 hw_clear_bits(reg, POWMAN_PASSWORD_BITS | bits);
123}
124
128 static inline bool powman_timer_is_running(void) {
129 return powman_hw->timer & POWMAN_TIMER_RUN_BITS;
130}
131
135 static inline void powman_timer_stop(void) {
136 powman_clear_bits(&powman_hw->timer, POWMAN_TIMER_RUN_BITS);
137}
138
142 static inline void powman_timer_start(void) {
143 powman_set_bits(&powman_hw->timer, POWMAN_TIMER_RUN_BITS);
144}
145
152 static inline void powman_clear_alarm(void) {
153 powman_clear_bits(&powman_hw->timer, POWMAN_TIMER_ALARM_BITS);
154}
155
159 enum powman_power_domains {
160 POWMAN_POWER_DOMAIN_SRAM_BANK1 = 0,
161 POWMAN_POWER_DOMAIN_SRAM_BANK0 = 1,
162 POWMAN_POWER_DOMAIN_XIP_CACHE = 2,
163 POWMAN_POWER_DOMAIN_SWITCHED_CORE = 3,
164 POWMAN_POWER_DOMAIN_COUNT = 4,
165};
166
167typedef uint32_t powman_power_state;
168
172powman_power_state powman_get_power_state(void);
173
185int powman_set_power_state(powman_power_state state);
186
187#define POWMAN_POWER_STATE_NONE 0
188
194 static inline powman_power_state powman_power_state_with_domain_on(powman_power_state orig, enum powman_power_domains domain) {
195 invalid_params_if(HARDWARE_POWMAN, domain >= POWMAN_POWER_DOMAIN_COUNT);
196 return orig | (1u << domain);
197}
198
204 static inline powman_power_state powman_power_state_with_domain_off(powman_power_state orig, enum powman_power_domains domain) {
205 invalid_params_if(HARDWARE_POWMAN, domain >= POWMAN_POWER_DOMAIN_COUNT);
206 return orig &= ~(1u << domain);
207}
208
214 static inline bool powman_power_state_is_domain_on(powman_power_state state, enum powman_power_domains domain) {
215 invalid_params_if(HARDWARE_POWMAN, domain >= POWMAN_POWER_DOMAIN_COUNT);
216 return state & (1u << domain);
217}
218
223void powman_enable_alarm_wakeup_at_ms(uint64_t alarm_time_ms);
224
232void powman_enable_gpio_wakeup(uint gpio_wakeup_num, uint32_t gpio, bool edge, bool high);
233
237void powman_disable_alarm_wakeup(void);
238
243void powman_disable_gpio_wakeup(uint gpio_wakeup_num);
244
248void powman_disable_all_wakeups(void);
249
256bool powman_configure_wakeup_state(powman_power_state sleep_state, powman_power_state wakeup_state);
257
268 static inline void powman_set_debug_power_request_ignored(bool ignored) {
269 if (ignored)
270 powman_set_bits(&powman_hw->dbg_pwrcfg, 1);
271 else
272 powman_clear_bits(&powman_hw->dbg_pwrcfg, 0);
273}
274
275#endif
hw_set_bits
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
hw_clear_bits
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
powman_timer_start
static void powman_timer_start(void)
Start the powman timer.
Definition: powman.h:142
powman_timer_set_1khz_tick_source_lposc
void powman_timer_set_1khz_tick_source_lposc(void)
Use the ~32KHz low power oscillator as the powman timer source.
Definition: powman.c:64
powman_set_debug_power_request_ignored
static void powman_set_debug_power_request_ignored(bool ignored)
Ignore wake up when the debugger is attached.
Definition: powman.h:268
powman_enable_alarm_wakeup_at_ms
void powman_enable_alarm_wakeup_at_ms(uint64_t alarm_time_ms)
Wake up from an alarm at a given time.
Definition: powman.c:220
powman_power_state_is_domain_on
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:214
powman_set_power_state
int powman_set_power_state(powman_power_state state)
Set the power state.
Definition: powman.c:139
powman_timer_enable_gpio_1hz_sync
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:118
powman_clear_alarm
static void powman_clear_alarm(void)
Clears the powman alarm.
Definition: powman.h:152
powman_timer_disable_gpio_1hz_sync
void powman_timer_disable_gpio_1hz_sync(void)
Stop using 1Hz external signal as the powman timer source for seconds.
Definition: powman.c:123
powman_clear_bits
static void powman_clear_bits(volatile uint32_t *reg, uint32_t bits)
hw_clear_bits helper function
Definition: powman.h:120
powman_disable_alarm_wakeup
void powman_disable_alarm_wakeup(void)
Disable waking up from alarm.
Definition: powman.c:225
powman_timer_is_running
static bool powman_timer_is_running(void)
Determine if the powman timer is running.
Definition: powman.h:128
powman_timer_stop
static void powman_timer_stop(void)
Stop the powman timer.
Definition: powman.h:135
powman_timer_get_ms
uint64_t powman_timer_get_ms(void)
Returns current time in ms.
Definition: powman.c:46
powman_timer_set_1khz_tick_source_gpio
void powman_timer_set_1khz_tick_source_gpio(uint32_t gpio)
Use a 1KHz external tick as the powman timer source.
Definition: powman.c:113
powman_configure_wakeup_state
bool powman_configure_wakeup_state(powman_power_state sleep_state, powman_power_state wakeup_state)
Configure sleep state and wakeup state.
Definition: powman.c:183
powman_set_bits
static void powman_set_bits(volatile uint32_t *reg, uint32_t bits)
hw_set_bits helper function
Definition: powman.h:106
powman_timer_set_1khz_tick_source_xosc_with_hz
void powman_timer_set_1khz_tick_source_xosc_with_hz(uint32_t xosc_freq_hz)
Use the crystal oscillator as the powman timer source.
Definition: powman.c:86
powman_timer_set_1khz_tick_source_xosc
void powman_timer_set_1khz_tick_source_xosc(void)
Use the crystal oscillator as the powman timer source.
Definition: powman.c:82
powman_timer_set_ms
void powman_timer_set_ms(uint64_t time_ms)
Set current time in ms.
Definition: powman.c:36
powman_enable_gpio_wakeup
void powman_enable_gpio_wakeup(uint gpio_wakeup_num, uint32_t gpio, bool edge, bool high)
Wake up from a gpio.
Definition: powman.c:230
powman_get_power_state
powman_power_state powman_get_power_state(void)
Get the current power state.
Definition: powman.c:127
powman_timer_enable_alarm_at_ms
void powman_timer_enable_alarm_at_ms(uint64_t alarm_time_ms)
Set an alarm at an absolute time in ms.
Definition: powman.c:202
powman_timer_set_1khz_tick_source_lposc_with_hz
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:68
powman_disable_all_wakeups
void powman_disable_all_wakeups(void)
Disable all wakeup sources.
Definition: powman.c:254
powman_power_domains
powman_power_domains
Power domains of powman.
Definition: powman.h:159
powman_power_state_with_domain_off
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:204
powman_disable_gpio_wakeup
void powman_disable_gpio_wakeup(uint gpio_wakeup_num)
Disable wake up from a gpio.
Definition: powman.c:249
powman_power_state_with_domain_on
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:194
powman_timer_disable_alarm
void powman_timer_disable_alarm(void)
Disable the alarm.
Definition: powman.c:215
POWMAN_POWER_DOMAIN_SRAM_BANK1
@ 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:160
POWMAN_POWER_DOMAIN_SRAM_BANK0
@ POWMAN_POWER_DOMAIN_SRAM_BANK0
bank0 is bottom 256K of sSRAM
Definition: powman.h:161
POWMAN_POWER_DOMAIN_XIP_CACHE
@ POWMAN_POWER_DOMAIN_XIP_CACHE
XIP cache is 2x8K instances.
Definition: powman.h:162
POWMAN_POWER_DOMAIN_SWITCHED_CORE
@ POWMAN_POWER_DOMAIN_SWITCHED_CORE
Switched core logic (processors, busfabric, peris etc)
Definition: powman.h:163
pico.h