Low-level hardware timer API. More...
Typedefs | |
typedef void(* | hardware_alarm_callback_t) (uint alarm_num) |
Functions | |
static uint32_t | time_us_32 (void) |
Return a 32 bit timestamp value in microseconds. More... | |
uint64_t | time_us_64 (void) |
Return the current 64 bit timestamp value in microseconds. More... | |
void | busy_wait_us_32 (uint32_t delay_us) |
Busy wait wasting cycles for the given (32 bit) number of microseconds. More... | |
void | busy_wait_us (uint64_t delay_us) |
Busy wait wasting cycles for the given (64 bit) number of microseconds. More... | |
void | busy_wait_ms (uint32_t delay_ms) |
Busy wait wasting cycles for the given number of milliseconds. More... | |
void | busy_wait_until (absolute_time_t t) |
Busy wait wasting cycles until after the specified timestamp. More... | |
static bool | time_reached (absolute_time_t t) |
Check if the specified timestamp has been reached. More... | |
void | hardware_alarm_claim (uint alarm_num) |
cooperatively claim the use of this hardware alarm_num More... | |
int | hardware_alarm_claim_unused (bool required) |
cooperatively claim the use of this hardware alarm_num More... | |
void | hardware_alarm_unclaim (uint alarm_num) |
cooperatively release the claim on use of this hardware alarm_num More... | |
bool | hardware_alarm_is_claimed (uint alarm_num) |
Determine if a hardware alarm has been claimed. More... | |
void | hardware_alarm_set_callback (uint alarm_num, hardware_alarm_callback_t callback) |
Enable/Disable a callback for a hardware timer on this core. More... | |
bool | hardware_alarm_set_target (uint alarm_num, absolute_time_t t) |
Set the current target for the specified hardware alarm. More... | |
void | hardware_alarm_cancel (uint alarm_num) |
Cancel an existing target (if any) for a given hardware_alarm. More... | |
void | hardware_alarm_force_irq (uint alarm_num) |
Force and IRQ for a specific hardware alarm. More... | |
Low-level hardware timer API.
This API provides medium level access to the timer HW. See also pico_time which provides higher levels functionality using the hardware timer.
The timer peripheral on RP2040 supports the following features:
By default the timer uses a one microsecond reference that is generated in the Watchdog (see Section 4.8.2) which is derived from the clk_ref.
The timer has 4 alarms, and can output a separate interrupt for each alarm. The alarms match on the lower 32 bits of the 64 bit counter which means they can be fired a maximum of 2^32 microseconds into the future. This is equivalent to:
The timer is expected to be used for short sleeps, if you want a longer alarm see the hardware_rtc functions.
typedef void(* hardware_alarm_callback_t) (uint alarm_num) |
Callback function type for hardware alarms
alarm_num | the hardware alarm number |
void busy_wait_ms | ( | uint32_t | delay_ms | ) |
Busy wait wasting cycles for the given number of milliseconds.
delay_ms | delay amount in milliseconds |
void busy_wait_until | ( | absolute_time_t | t | ) |
Busy wait wasting cycles until after the specified timestamp.
t | Absolute time to wait until |
void busy_wait_us | ( | uint64_t | delay_us | ) |
Busy wait wasting cycles for the given (64 bit) number of microseconds.
delay_us | delay amount in microseconds |
void busy_wait_us_32 | ( | uint32_t | delay_us | ) |
Busy wait wasting cycles for the given (32 bit) number of microseconds.
delay_us | delay amount in microseconds |
Busy wait wasting cycles for the given (32 bit) number of microseconds.
void hardware_alarm_cancel | ( | uint | alarm_num | ) |
Cancel an existing target (if any) for a given hardware_alarm.
alarm_num | the hardware alarm number |
void hardware_alarm_claim | ( | uint | alarm_num | ) |
cooperatively claim the use of this hardware alarm_num
This method hard asserts if the hardware alarm is currently claimed.
alarm_num | the hardware alarm to claim |
int hardware_alarm_claim_unused | ( | bool | required | ) |
cooperatively claim the use of this hardware alarm_num
This method attempts to claim an unused hardware alarm
void hardware_alarm_force_irq | ( | uint | alarm_num | ) |
Force and IRQ for a specific hardware alarm.
This method will forcibly make sure the current alarm callback (if present) for the hardware alarm is called from an IRQ context after this call. If an actual callback is due at the same time then the callback may only be called once.
Calling this method does not otherwise interfere with regular callback operations.
alarm_num | the hardware alarm number |
bool hardware_alarm_is_claimed | ( | uint | alarm_num | ) |
Determine if a hardware alarm has been claimed.
alarm_num | the hardware alarm number |
void hardware_alarm_set_callback | ( | uint | alarm_num, |
hardware_alarm_callback_t | callback | ||
) |
Enable/Disable a callback for a hardware timer on this core.
This method enables/disables the alarm IRQ for the specified hardware alarm on the calling core, and set the specified callback to be associated with that alarm.
This callback will be used for the timeout set via hardware_alarm_set_target
alarm_num | the hardware alarm number |
callback | the callback to install, or NULL to unset |
bool hardware_alarm_set_target | ( | uint | alarm_num, |
absolute_time_t | t | ||
) |
Set the current target for the specified hardware alarm.
This will replace any existing target
alarm_num | the hardware alarm number |
t | the target timestamp |
void hardware_alarm_unclaim | ( | uint | alarm_num | ) |
cooperatively release the claim on use of this hardware alarm_num
alarm_num | the hardware alarm to unclaim |
|
inlinestatic |
Check if the specified timestamp has been reached.
t | Absolute time to compare against current time |
|
inlinestatic |
Return a 32 bit timestamp value in microseconds.
Returns the low 32 bits of the hardware timer.
uint64_t time_us_64 | ( | ) |
Return the current 64 bit timestamp value in microseconds.
Returns the full 64 bits of the hardware timer. The pico_time and other functions rely on the fact that this value monotonically increases from power up. As such it is expected that this value counts upwards and never wraps (we apologize for introducing a potential year 5851444 bug).
Return the current 64 bit timestamp value in microseconds.