Timer API
The Timer API provides millisecond-precision timing and a scheduled task queue for periodic operations.System configuration
Clock settings:- System clock: 16 MHz
- Timer resolution: 1 millisecond
- Maximum scheduled tasks: 32
Data structures
TimerScheduledTask_t
Defines a scheduled task that executes periodically.Function pointer to execute
Context pointer passed to the task function
Execution interval in milliseconds
Ticks elapsed since last execution (internal)
Initialization
TimerInit
Initializes the timer system with 1ms resolution.This must be called during system initialization before using any timer functions.
Time functions
TimerGetMillis
Returns milliseconds elapsed since system start.Milliseconds since initialization (wraps after ~49 days)
TimerDelayMicroseconds
Blocking delay for microsecond-precision timing.Delay duration in microseconds
Scheduled tasks
TimerRegisterScheduledTask
Registers a task to execute periodically.Function to execute periodically
Context pointer passed to task function
Execution interval in milliseconds
Task ID (0-31), or TIMER_TASK_DISABLED if queue is full
TimerUnregisterScheduledTask
Unregisters a scheduled task by function pointer.Function pointer of task to remove
1 if task was found and removed, 0 otherwise
TimerUnregisterScheduledTaskById
Unregisters a scheduled task by ID.Task ID returned from TimerRegisterScheduledTask
TimerProcessScheduledTasks
Processes all scheduled tasks (called from main loop).This function is called automatically in the main application loop. You typically don’t need to call it directly.
Task management
TimerResetScheduledTask
Resets the tick counter for a task, restarting its interval.Task ID to reset
TimerSetTaskInterval
Changes the execution interval of a scheduled task.Task ID to modify
New interval in milliseconds
TimerTriggerScheduledTask
Immediately executes a scheduled task without waiting for its interval.Task ID to trigger
The task’s interval timer is not reset by this function.
Constants
See also
- Event API - Event-driven callbacks
- Architecture - System architecture overview