Alarm functions for scheduling future execution. More...
Macros | |
#define | PICO_TIME_DEFAULT_ALARM_POOL_DISABLED 0 |
If 1 then the default alarm pool is disabled (so no hardware alarm is claimed for the pool) More... | |
#define | PICO_TIME_DEFAULT_ALARM_POOL_HARDWARE_ALARM_NUM 3 |
Selects which hardware alarm is used for the default alarm pool. More... | |
#define | PICO_TIME_DEFAULT_ALARM_POOL_MAX_TIMERS 16 |
Selects the maximum number of concurrent timers in the default alarm pool. More... | |
Typedefs | |
typedef int32_t | alarm_id_t |
The identifier for an alarm. More... | |
typedef int64_t(* | alarm_callback_t) (alarm_id_t id, void *user_data) |
User alarm callback. More... | |
Functions | |
void | alarm_pool_init_default (void) |
Create the default alarm pool (if not already created or disabled) | |
alarm_pool_t * | alarm_pool_get_default (void) |
The default alarm pool used when alarms are added without specifying an alarm pool, and also used by the SDK to support lower power sleeps and timeouts. More... | |
alarm_pool_t * | alarm_pool_create (uint hardware_alarm_num, uint max_timers) |
Create an alarm pool. More... | |
alarm_pool_t * | alarm_pool_create_with_unused_hardware_alarm (uint max_timers) |
Create an alarm pool, claiming an used hardware alarm to back it. More... | |
uint | alarm_pool_hardware_alarm_num (alarm_pool_t *pool) |
Return the hardware alarm used by an alarm pool. More... | |
uint | alarm_pool_core_num (alarm_pool_t *pool) |
Return the core number the alarm pool was initialized on (and hence callbacks are called on) More... | |
void | alarm_pool_destroy (alarm_pool_t *pool) |
Destroy the alarm pool, cancelling all alarms and freeing up the underlying hardware alarm. More... | |
alarm_id_t | alarm_pool_add_alarm_at (alarm_pool_t *pool, absolute_time_t time, alarm_callback_t callback, void *user_data, bool fire_if_past) |
Add an alarm callback to be called at a specific timeGenerally the callback is called as soon as possible after the time specified from an IRQ handler on the core the alarm pool was created on. If the callback is in the past or happens before the alarm setup could be completed, then this method will optionally call the callback itself and then return a return code to indicate that the target time has passed. More... | |
alarm_id_t | alarm_pool_add_alarm_at_force_in_context (alarm_pool_t *pool, absolute_time_t time, alarm_callback_t callback, void *user_data) |
Add an alarm callback to be called at or after a specific timeThe callback is called as soon as possible after the time specified from an IRQ handler on the core the alarm pool was created on. Unlike alarm_pool_add_alarm_at, this method guarantees to call the callback from that core even if the time is during this method call or in the past. More... | |
static alarm_id_t | alarm_pool_add_alarm_in_us (alarm_pool_t *pool, uint64_t us, alarm_callback_t callback, void *user_data, bool fire_if_past) |
Add an alarm callback to be called after a delay specified in microsecondsGenerally the callback is called as soon as possible after the time specified from an IRQ handler on the core the alarm pool was created on. If the callback is in the past or happens before the alarm setup could be completed, then this method will optionally call the callback itself and then return a return code to indicate that the target time has passed. More... | |
static alarm_id_t | alarm_pool_add_alarm_in_ms (alarm_pool_t *pool, uint32_t ms, alarm_callback_t callback, void *user_data, bool fire_if_past) |
Add an alarm callback to be called after a delay specified in millisecondsGenerally the callback is called as soon as possible after the time specified from an IRQ handler on the core the alarm pool was created on. If the callback is in the past or happens before the alarm setup could be completed, then this method will optionally call the callback itself and then return a return code to indicate that the target time has passed. More... | |
bool | alarm_pool_cancel_alarm (alarm_pool_t *pool, alarm_id_t alarm_id) |
Cancel an alarm. More... | |
static alarm_id_t | add_alarm_at (absolute_time_t time, alarm_callback_t callback, void *user_data, bool fire_if_past) |
Add an alarm callback to be called at a specific timeGenerally the callback is called as soon as possible after the time specified from an IRQ handler on the core of the default alarm pool (generally core 0). If the callback is in the past or happens before the alarm setup could be completed, then this method will optionally call the callback itself and then return a return code to indicate that the target time has passed. More... | |
static alarm_id_t | add_alarm_in_us (uint64_t us, alarm_callback_t callback, void *user_data, bool fire_if_past) |
Add an alarm callback to be called after a delay specified in microsecondsGenerally the callback is called as soon as possible after the time specified from an IRQ handler on the core of the default alarm pool (generally core 0). If the callback is in the past or happens before the alarm setup could be completed, then this method will optionally call the callback itself and then return a return code to indicate that the target time has passed. More... | |
static alarm_id_t | add_alarm_in_ms (uint32_t ms, alarm_callback_t callback, void *user_data, bool fire_if_past) |
Add an alarm callback to be called after a delay specified in millisecondsGenerally the callback is called as soon as possible after the time specified from an IRQ handler on the core of the default alarm pool (generally core 0). If the callback is in the past or happens before the alarm setup could be completed, then this method will optionally call the callback itself and then return a return code to indicate that the target time has passed. More... | |
static bool | cancel_alarm (alarm_id_t alarm_id) |
Cancel an alarm from the default alarm pool. More... | |
Alarm functions for scheduling future execution.
Alarms are added to alarm pools, which may hold a certain fixed number of active alarms. Each alarm pool utilizes one of four underlying hardware alarms, thus you may have up to four alarm pools. An alarm pool calls (except when the callback would happen before or during being set) the callback on the core from which the alarm pool was created. Callbacks are called from the hardware alarm IRQ handler, so care must be taken in their implementation.
A default pool is created the core specified by PICO_TIME_DEFAULT_ALARM_POOL_HARDWARE_ALARM_NUM on core 0, and may be used by the method variants that take no alarm pool parameter.
#define PICO_TIME_DEFAULT_ALARM_POOL_DISABLED 0 |
If 1 then the default alarm pool is disabled (so no hardware alarm is claimed for the pool)
#define PICO_TIME_DEFAULT_ALARM_POOL_HARDWARE_ALARM_NUM 3 |
Selects which hardware alarm is used for the default alarm pool.
#define PICO_TIME_DEFAULT_ALARM_POOL_MAX_TIMERS 16 |
Selects the maximum number of concurrent timers in the default alarm pool.
typedef int64_t(* alarm_callback_t) (alarm_id_t id, void *user_data) |
User alarm callback.
id | the alarm_id as returned when the alarm was added |
user_data | the user data passed when the alarm was added |
typedef int32_t alarm_id_t |
The identifier for an alarm.
|
inlinestatic |
Add an alarm callback to be called at a specific timeGenerally the callback is called as soon as possible after the time specified from an IRQ handler on the core of the default alarm pool (generally core 0). If the callback is in the past or happens before the alarm setup could be completed, then this method will optionally call the callback itself and then return a return code to indicate that the target time has passed.
time | the timestamp when (after which) the callback should fire |
callback | the callback function |
user_data | user data to pass to the callback function |
fire_if_past | if true, and the alarm time falls before or during this call before the alarm can be set, then the callback should be called during (by) this function instead |
|
inlinestatic |
Add an alarm callback to be called after a delay specified in millisecondsGenerally the callback is called as soon as possible after the time specified from an IRQ handler on the core of the default alarm pool (generally core 0). If the callback is in the past or happens before the alarm setup could be completed, then this method will optionally call the callback itself and then return a return code to indicate that the target time has passed.
ms | the delay (from now) in milliseconds when (after which) the callback should fire |
callback | the callback function |
user_data | user data to pass to the callback function |
fire_if_past | if true, and the alarm time falls during this call before the alarm can be set, then the callback should be called during (by) this function instead |
|
inlinestatic |
Add an alarm callback to be called after a delay specified in microsecondsGenerally the callback is called as soon as possible after the time specified from an IRQ handler on the core of the default alarm pool (generally core 0). If the callback is in the past or happens before the alarm setup could be completed, then this method will optionally call the callback itself and then return a return code to indicate that the target time has passed.
us | the delay (from now) in microseconds when (after which) the callback should fire |
callback | the callback function |
user_data | user data to pass to the callback function |
fire_if_past | if true, and the alarm time falls during this call before the alarm can be set, then the callback should be called during (by) this function instead |
alarm_id_t alarm_pool_add_alarm_at | ( | alarm_pool_t * | pool, |
absolute_time_t | time, | ||
alarm_callback_t | callback, | ||
void * | user_data, | ||
bool | fire_if_past | ||
) |
Add an alarm callback to be called at a specific timeGenerally the callback is called as soon as possible after the time specified from an IRQ handler on the core the alarm pool was created on. If the callback is in the past or happens before the alarm setup could be completed, then this method will optionally call the callback itself and then return a return code to indicate that the target time has passed.
pool | the alarm pool to use for scheduling the callback (this determines which hardware alarm is used, and which core calls the callback) |
time | the timestamp when (after which) the callback should fire |
callback | the callback function |
user_data | user data to pass to the callback function |
fire_if_past | if true, and the alarm time falls before or during this call before the alarm can be set, then the callback should be called during (by) this function instead |
alarm_id_t alarm_pool_add_alarm_at_force_in_context | ( | alarm_pool_t * | pool, |
absolute_time_t | time, | ||
alarm_callback_t | callback, | ||
void * | user_data | ||
) |
Add an alarm callback to be called at or after a specific timeThe callback is called as soon as possible after the time specified from an IRQ handler on the core the alarm pool was created on. Unlike alarm_pool_add_alarm_at, this method guarantees to call the callback from that core even if the time is during this method call or in the past.
pool | the alarm pool to use for scheduling the callback (this determines which hardware alarm is used, and which core calls the callback) |
time | the timestamp when (after which) the callback should fire |
callback | the callback function |
user_data | user data to pass to the callback function |
|
inlinestatic |
Add an alarm callback to be called after a delay specified in millisecondsGenerally the callback is called as soon as possible after the time specified from an IRQ handler on the core the alarm pool was created on. If the callback is in the past or happens before the alarm setup could be completed, then this method will optionally call the callback itself and then return a return code to indicate that the target time has passed.
pool | the alarm pool to use for scheduling the callback (this determines which hardware alarm is used, and which core calls the callback) |
ms | the delay (from now) in milliseconds when (after which) the callback should fire |
callback | the callback function |
user_data | user data to pass to the callback function |
fire_if_past | if true, and the alarm time falls before or during this call before the alarm can be set, then the callback should be called during (by) this function instead |
|
inlinestatic |
Add an alarm callback to be called after a delay specified in microsecondsGenerally the callback is called as soon as possible after the time specified from an IRQ handler on the core the alarm pool was created on. If the callback is in the past or happens before the alarm setup could be completed, then this method will optionally call the callback itself and then return a return code to indicate that the target time has passed.
pool | the alarm pool to use for scheduling the callback (this determines which hardware alarm is used, and which core calls the callback) |
us | the delay (from now) in microseconds when (after which) the callback should fire |
callback | the callback function |
user_data | user data to pass to the callback function |
fire_if_past | if true, and the alarm time falls during this call before the alarm can be set, then the callback should be called during (by) this function instead |
bool alarm_pool_cancel_alarm | ( | alarm_pool_t * | pool, |
alarm_id_t | alarm_id | ||
) |
Cancel an alarm.
pool | the alarm_pool containing the alarm |
alarm_id | the alarm |
uint alarm_pool_core_num | ( | alarm_pool_t * | pool | ) |
Return the core number the alarm pool was initialized on (and hence callbacks are called on)
pool | the pool |
alarm_pool_t* alarm_pool_create | ( | uint | hardware_alarm_num, |
uint | max_timers | ||
) |
Create an alarm pool.
The alarm pool will call callbacks from an alarm IRQ Handler on the core of this function is called from.
In many situations there is never any need for anything other than the default alarm pool, however you might want to create another if you want alarm callbacks on core 1 or require alarm pools of different priority (IRQ priority based preemption of callbacks)
hardware_alarm_num | the hardware alarm to use to back this pool |
max_timers | the maximum number of timers |
alarm_pool_t* alarm_pool_create_with_unused_hardware_alarm | ( | uint | max_timers | ) |
Create an alarm pool, claiming an used hardware alarm to back it.
The alarm pool will call callbacks from an alarm IRQ Handler on the core of this function is called from.
In many situations there is never any need for anything other than the default alarm pool, however you might want to create another if you want alarm callbacks on core 1 or require alarm pools of different priority (IRQ priority based preemption of callbacks)
max_timers | the maximum number of timers |
void alarm_pool_destroy | ( | alarm_pool_t * | pool | ) |
Destroy the alarm pool, cancelling all alarms and freeing up the underlying hardware alarm.
pool | the pool |
alarm_pool_t* alarm_pool_get_default | ( | void | ) |
The default alarm pool used when alarms are added without specifying an alarm pool, and also used by the SDK to support lower power sleeps and timeouts.
uint alarm_pool_hardware_alarm_num | ( | alarm_pool_t * | pool | ) |
Return the hardware alarm used by an alarm pool.
pool | the pool |
|
inlinestatic |
Cancel an alarm from the default alarm pool.
alarm_id | the alarm |