v2.0.0
Data Structures | Typedefs | Functions
repeating_timer
High Level APIs » pico_time

Repeating Timer functions for simple scheduling of repeated execution. More...

## Data Structures
struct | repeating_timer
| Information about a repeating timer. More...

## Typedefs
typedef bool(* | repeating_timer_callback_t) (repeating_timer_t *rt)
| Callback for a repeating timer. More...

## Functions
bool | alarm_pool_add_repeating_timer_us (alarm_pool_t *pool, int64_t delay_us, repeating_timer_callback_t callback, void *user_data, repeating_timer_t *out)
| Add a repeating timer that is called repeatedly at the specified interval in microseconds. More...
static bool | alarm_pool_add_repeating_timer_ms (alarm_pool_t *pool, int32_t delay_ms, repeating_timer_callback_t callback, void *user_data, repeating_timer_t *out)
| Add a repeating timer that is called repeatedly at the specified interval in milliseconds. More...
static bool | add_repeating_timer_us (int64_t delay_us, repeating_timer_callback_t callback, void *user_data, repeating_timer_t *out)
| Add a repeating timer that is called repeatedly at the specified interval in microseconds. More...
static bool | add_repeating_timer_ms (int32_t delay_ms, repeating_timer_callback_t callback, void *user_data, repeating_timer_t *out)
| Add a repeating timer that is called repeatedly at the specified interval in milliseconds. More...
bool | cancel_repeating_timer (repeating_timer_t *timer)
| Cancel a repeating timer. More...

## Detailed Description

Repeating Timer functions for simple scheduling of repeated execution.

Note
  The regular alarm_ functionality can be used to make repeating alarms (by return non zero from the callback), however these methods abstract that further (at the cost of a user structure to store the repeat delay in (which the alarm framework does not have space for).

## Typedef Documentation

## ◆ repeating_timer_callback_t

typedef bool(* repeating_timer_callback_t) (repeating_timer_t *rt)

Callback for a repeating timer.

Parameters

  rt | repeating time structure containing information about the repeating time. user_data is of primary important to the user

Returns
  true to continue repeating, false to stop.

## Function Documentation

## ◆ add_repeating_timer_ms()

static bool add_repeating_timer_ms | ( | int32_t | delay_ms,
|  | repeating_timer_callback_t | callback,
|  | void * | user_data,
|  | repeating_timer_t * | out
| ) |  |
| inlinestatic

Add a repeating timer that is called repeatedly at the specified interval in milliseconds.

Generally 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.

Note
  It is safe to call this method from an IRQ handler (including alarm callbacks), and from either core.

Parameters

  delay_ms | the repeat delay in milliseconds; if >0 then this is the delay between one callback ending and the next starting; if <0 then this is the negative of the time between the starts of the callbacks. The value of 0 is treated as 1 microsecond
  callback | the repeating timer callback function
  user_data | user data to pass to store in the repeating_timer structure for use by the callback.
  out | the pointer to the user owned structure to store the repeating timer info in. BEWARE this storage location must outlive the repeating timer, so be careful of using stack space

Returns
  false if there were no alarm slots available to create the timer, true otherwise.

## ◆ add_repeating_timer_us()

static bool add_repeating_timer_us | ( | int64_t | delay_us,
|  | repeating_timer_callback_t | callback,
|  | void * | user_data,
|  | repeating_timer_t * | out
| ) |  |
| inlinestatic

Add a repeating timer that is called repeatedly at the specified interval in microseconds.

Generally 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.

Note
  It is safe to call this method from an IRQ handler (including alarm callbacks), and from either core.

Parameters

  delay_us | the repeat delay in microseconds; if >0 then this is the delay between one callback ending and the next starting; if <0 then this is the negative of the time between the starts of the callbacks. The value of 0 is treated as 1
  callback | the repeating timer callback function
  user_data | user data to pass to store in the repeating_timer structure for use by the callback.
  out | the pointer to the user owned structure to store the repeating timer info in. BEWARE this storage location must outlive the repeating timer, so be careful of using stack space

Returns
  false if there were no alarm slots available to create the timer, true otherwise.

## ◆ alarm_pool_add_repeating_timer_ms()

static bool alarm_pool_add_repeating_timer_ms | ( | alarm_pool_t * | pool,
|  | int32_t | delay_ms,
|  | repeating_timer_callback_t | callback,
|  | void * | user_data,
|  | repeating_timer_t * | out
| ) |  |
| inlinestatic

Add a repeating timer that is called repeatedly at the specified interval in milliseconds.

Generally 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.

Note
  It is safe to call this method from an IRQ handler (including alarm callbacks), and from either core.

Parameters

  pool | the alarm pool to use for scheduling the repeating timer (this determines which timer_alarm is used, and which core calls the callback)
  delay_ms | the repeat delay in milliseconds; if >0 then this is the delay between one callback ending and the next starting; if <0 then this is the negative of the time between the starts of the callbacks. The value of 0 is treated as 1 microsecond
  callback | the repeating timer callback function
  user_data | user data to pass to store in the repeating_timer structure for use by the callback.
  out | the pointer to the user owned structure to store the repeating timer info in. BEWARE this storage location must outlive the repeating timer, so be careful of using stack space

Returns
  false if there were no alarm slots available to create the timer, true otherwise.

## ◆ alarm_pool_add_repeating_timer_us()

bool alarm_pool_add_repeating_timer_us | ( | alarm_pool_t * | pool,
|  | int64_t | delay_us,
|  | repeating_timer_callback_t | callback,
|  | void * | user_data,
|  | repeating_timer_t * | out
| ) |  |

Add a repeating timer that is called repeatedly at the specified interval in microseconds.

Generally 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.

Note
  It is safe to call this method from an IRQ handler (including alarm callbacks), and from either core.

Parameters

  pool | the alarm pool to use for scheduling the repeating timer (this determines which timer_alarm is used, and which core calls the callback)
  delay_us | the repeat delay in microseconds; if >0 then this is the delay between one callback ending and the next starting; if <0 then this is the negative of the time between the starts of the callbacks. The value of 0 is treated as 1
  callback | the repeating timer callback function
  user_data | user data to pass to store in the repeating_timer structure for use by the callback.
  out | the pointer to the user owned structure to store the repeating timer info in. BEWARE this storage location must outlive the repeating timer, so be careful of using stack space

Returns
  false if there were no alarm slots available to create the timer, true otherwise.

## ◆ cancel_repeating_timer()

bool cancel_repeating_timer | ( | repeating_timer_t * | timer | ) |

Cancel a repeating timer.

Parameters

  timer | the repeating timer to cancel

Returns
  true if the repeating timer was cancelled, false if it didn't exist

See also
  alarm_id_t for a note on reuse of IDs