objc

Data Structures | Macros | Typedefs | Functions

Periodic and one-shot timers for scheduling tasks. More...

Collaboration diagram for Timers:

Data Structures

struct  sys_timer_t
 Timer context structure. More...
 

Macros

#define SYS_TIMER_CTX_SIZE   32
 Size of the timer context buffer. More...
 

Typedefs

typedef struct sys_timer_t sys_timer_t
 Timer context structure. More...
 

Functions

sys_timer_t sys_timer_init (uint32_t interval_ms, void *userdata, void(*callback)(sys_timer_t *))
 Initializes a new timer context. More...
 
bool sys_timer_start (sys_timer_t *timer)
 Starts a timer. More...
 
bool sys_timer_finalize (sys_timer_t *timer)
 Cancels and finalizes a timer. More...
 
bool sys_timer_valid (sys_timer_t *timer)
 Checks if a timer is valid, configured and running. More...
 

Detailed Description

Periodic and one-shot timers for scheduling tasks.

This module declares types and functions for creating and managing timers, which are created as periodic timers. A "callback" function is called when the timer matures, and the timer can be configured as a one-shot timer or otherwise cancelled by calling sys_timer_finalize() in the callback function.

The core that the timer callback runs on is determined by the platform's implementation, but on the Pico platform, the timer callback should be implemented to run on the same core that the timer was started on (at the moment this isn't the case, but it will be in the future).

Macro Definition Documentation

◆ SYS_TIMER_CTX_SIZE

#define SYS_TIMER_CTX_SIZE   32

Size of the timer context buffer.

This defines the size of the context buffer used for timer operations. It should be large enough to hold any platform-specific timer context.

Definition at line 39 of file timer.h.

Typedef Documentation

◆ sys_timer_t

typedef struct sys_timer_t sys_timer_t

Timer context structure.

Contains the state and configuration for timer operations.

Function Documentation

◆ sys_timer_finalize()

bool sys_timer_finalize ( sys_timer_t timer)

Cancels and finalizes a timer.

Parameters
timerThe timer context to finalize.
Returns
true on success, false on failure. This function stops the timer and cleans up any resources associated with it. After calling this function, the timer context becomes invalid and should not be used again. To use a timer with the same configuration, initialize a new timer using sys_timer_init().
Examples:
clock/main.c.

◆ sys_timer_init()

sys_timer_t sys_timer_init ( uint32_t  interval_ms,
void *  userdata,
void(*)(sys_timer_t *)  callback 
)

Initializes a new timer context.

Parameters
interval_msThe periodic interval for the timer in milliseconds.
userdataOptional user data to pass to the callback.
callbackThe function to call on each timer event.
Returns
A new sys_timer_t instance initialized with the specified parameters.

This function returns a sys_timer_t instance for the specified timer configuration, ready for use in starting and stopping the timer. Use sys_timer_start() to start the timer and sys_timer_finalize() to stop and clean up the timer. If you want to define a one-shot timer, call sys_timer_finalize() in your callback function.

Examples:
clock/main.c.

◆ sys_timer_start()

bool sys_timer_start ( sys_timer_t timer)

Starts a timer.

Parameters
timerThe timer context to start.
Returns
true on success, false on failure.

This function starts the timer with the specified interval and callback. If the timer is invalid, or cannot be started, the function returns false.

Examples:
clock/main.c.

◆ sys_timer_valid()

bool sys_timer_valid ( sys_timer_t timer)

Checks if a timer is valid, configured and running.

Parameters
timerThe timer context to validate.
Returns
true if the timer is valid and is enabled.