7#ifndef _PICO_LOW_POWER_H_
8#define _PICO_LOW_POWER_H_
73#ifndef PARAM_ASSERTIONS_ENABLED_PICO_LOW_POWER
74#define PARAM_ASSERTIONS_ENABLED_PICO_LOW_POWER 0
78#ifndef PICO_LOW_POWER_MIN_AON_SLEEP_TIME_MS
80#define PICO_LOW_POWER_MIN_AON_SLEEP_TIME_MS 2000
82#define PICO_LOW_POWER_MIN_AON_SLEEP_TIME_MS 10
87#ifndef PICO_LOW_POWER_MIN_DORMANT_TIME_MS
89#define PICO_LOW_POWER_MIN_DORMANT_TIME_MS 2000
91#define PICO_LOW_POWER_MIN_DORMANT_TIME_MS 10
96#ifndef PICO_LOW_POWER_MIN_PSTATE_TIME_MS
97#define PICO_LOW_POWER_MIN_PSTATE_TIME_MS 10
102#include "hardware/rtc.h"
109 DORMANT_CLOCK_SOURCE_XOSC,
110 DORMANT_CLOCK_SOURCE_ROSC,
112 DORMANT_CLOCK_SOURCE_RTC,
114 DORMANT_CLOCK_SOURCE_LPOSC,
116 NUM_DORMANT_CLOCK_SOURCES
117} dormant_clock_source_t;
120#define DORMANT_CLOCK_SOURCE_DEFAULT DORMANT_CLOCK_SOURCE_RTC
122#define DORMANT_CLOCK_SOURCE_DEFAULT DORMANT_CLOCK_SOURCE_LPOSC
126#define DORMANT_CLOCK_HZ_DEFAULT RTC_CLOCK_FREQ_HZ
128#define DORMANT_CLOCK_HZ_DEFAULT 0
132typedef void (*low_power_pstate_resume_func)(pstate_bitset_t *pstate);
154#if NUM_BANK0_GPIOS <= 32
366 ms_to_timespec(ms, &ts);
423static inline int low_power_dormant_for_ms(uint32_t ms, dormant_clock_source_t dormant_clock_source,
const clock_dest_bitset_t *keep_enabled) {
#define PICO_DEFAULT_TIMER_INSTANCE()
Returns the default timer instance on the platform based on the setting of PICO_DEFAULT_TIMER.
Definition timer.h:182
bool aon_timer_is_running(void)
Check if the AON timer is running.
Definition aon_timer.c:252
bool aon_timer_start(const struct timespec *ts)
Start the AON timer running using the specified timespec as the current time.
Definition aon_timer.c:195
static absolute_time_t aon_timer_make_timeout_time_ms(uint32_t ms)
Convenience method to get the timestamp a number of milliseconds from the current time of the AON tim...
Definition aon_timer.h:197
@ PICO_OK
No error; the operation succeeded.
Definition error.h:23
int low_power_pstate_until_aon_timer(absolute_time_t until, pstate_bitset_t *pstate, low_power_pstate_resume_func resume_func)
Go to Pstate until time using AON timer.
Definition low_power.c:750
static int low_power_sleep_until_default_timer(absolute_time_t until, const clock_dest_bitset_t *keep_enabled, bool exclusive)
Sleep until time using default timer.
Definition low_power.h:196
static int low_power_set_external_clock_source(__unused uint src_hz, __unused uint gpio_pin)
Set the external clock source for the AON timer.
Definition low_power.h:241
void low_power_set_pins_low_leakage_exclude_mask(uint32_t exclude_mask)
Set all pins to a low leakage state.
Definition low_power.c:227
static int low_power_pstate_for_ms(uint32_t ms, pstate_bitset_t *pstate, low_power_pstate_resume_func resume_func)
Go to Pstate for a number of milliseconds.
Definition low_power.h:439
int low_power_dormant_until_gpio_pin_state(uint gpio_pin, bool edge, bool high, dormant_clock_source_t dormant_clock_source, const clock_dest_bitset_t *keep_enabled)
Go dormant until GPIO pin state changes.
Definition low_power.c:632
pstate_bitset_t * low_power_persistent_pstate_get(pstate_bitset_t *pstate)
Get Pstate which keeps persistent data powered on.
Definition low_power.c:683
static bool low_power_start_aon_timer(void)
Start the AON timer at the current system time.
Definition low_power.h:379
int low_power_sleep_until_gpio_pin_state(uint gpio_pin, bool edge, bool high, const clock_dest_bitset_t *keep_enabled, bool exclusive)
Sleep until GPIO pin state changes.
Definition low_power.c:376
static int low_power_sleep_for_us(timer_hw_t *timer, uint64_t us, const clock_dest_bitset_t *keep_enabled, bool exclusive)
Sleep for a number of microseconds.
Definition low_power.h:394
static bool low_power_start_aon_timer_at_time_ms(uint64_t ms)
Start the AON timer at a specific time in milliseconds.
Definition low_power.h:364
static int low_power_dormant_for_ms(uint32_t ms, dormant_clock_source_t dormant_clock_source, const clock_dest_bitset_t *keep_enabled)
Go dormant for a number of milliseconds.
Definition low_power.h:423
int low_power_pstate_until_gpio_pin_state(uint gpio_pin, bool edge, bool high, pstate_bitset_t *pstate, low_power_pstate_resume_func resume_func)
Go to Pstate until GPIO pin state changes.
Definition low_power.c:769
int low_power_sleep_until_aon_timer(absolute_time_t until, const clock_dest_bitset_t *keep_enabled, bool exclusive)
Sleep until time using AON timer.
Definition low_power.c:322
int low_power_dormant_until_aon_timer(absolute_time_t until, dormant_clock_source_t dormant_clock_source, const clock_dest_bitset_t *keep_enabled)
Go dormant until time using AON timer.
Definition low_power.c:562
int low_power_sleep_until_timer(timer_hw_t *timer, absolute_time_t until, const clock_dest_bitset_t *keep_enabled, bool exclusive)
Sleep until time using timer.
Definition low_power.c:269
static int low_power_sleep_for_ms(uint32_t ms, const clock_dest_bitset_t *keep_enabled, bool exclusive)
Sleep for a number of milliseconds.
Definition low_power.h:408
int low_power_sleep_until_irq(const clock_dest_bitset_t *keep_enabled)
Sleep until an interrupt occurs.
Definition low_power.c:248
static void low_power_set_pins_low_leakage_exclude_mask64(uint64_t exclude_mask)
Set all pins to a low leakage state (64-bit mask version).
Definition low_power.h:155
static absolute_time_t make_timeout_time_us(uint64_t us)
Convenience method to get the timestamp a number of microseconds from the current time.
Definition time.h:148
static absolute_time_t make_timeout_time_ms(uint32_t ms)
Convenience method to get the timestamp a number of milliseconds from the current time.
Definition time.h:158
uint64_t absolute_time_t
An opaque 64 bit timestamp in microseconds.
Definition types.h:43