libdragon
|
Timer Subsystem. More...
Functions | |
void | timer_init (void) |
Initialize the timer subsystem. | |
timer_link_t * | new_timer (int ticks, int flags, timer_callback1_t callback) |
Create a new timer and add to list. | |
timer_link_t * | new_timer_context (int ticks, int flags, timer_callback2_t callback, void *ctx) |
Create a new timer with context and add to list. | |
void | start_timer (timer_link_t *timer, int ticks, int flags, timer_callback1_t callback) |
Start a timer (not currently in the list) | |
void | start_timer_context (timer_link_t *timer, int ticks, int flags, timer_callback2_t callback, void *ctx) |
Start a timer (not currently in the list) with context. | |
void | restart_timer (timer_link_t *timer) |
Reset a timer and add to list. | |
void | stop_timer (timer_link_t *timer) |
Stop a timer and remove it from the list. | |
void | delete_timer (timer_link_t *timer) |
Remove a timer from the list and delete it. | |
void | timer_close (void) |
Free and close the timer subsystem. | |
long long | timer_ticks (void) |
Return total ticks since timer was initialized, as a 64-bit counter. | |
Timer Subsystem.
void timer_init | ( | void | ) |
Initialize the timer subsystem.
This function will reset the COP0 ticks counter to 0. Even if you later access the hardware counter directly (via TICKS_READ()), it should not be a problem if you call timer_init() early in the application main.
Do not modify the COP0 ticks counter after calling this function. Doing so will impede functionality of the timer module.
The timer subsystem tracks the number of times timer_init is called and will only initialize the subsystem on the first call. This reference count also applies to timer_close, which will only close the subsystem if it is called the same number of times as timer_init.
timer_link_t * new_timer | ( | int | ticks, |
int | flags, | ||
timer_callback1_t | callback | ||
) |
Create a new timer and add to list.
If you need to associate some data with the timer, consider using new_timer_context to include a pointer in the callback.
[in] | ticks | Number of ticks before the timer should fire |
[in] | flags | Timer flags. See TF_ONE_SHOT, TF_CONTINUOUS and TF_DISABLED |
[in] | callback | Callback function to call when the timer expires |
timer_link_t * new_timer_context | ( | int | ticks, |
int | flags, | ||
timer_callback2_t | callback, | ||
void * | ctx | ||
) |
Create a new timer with context and add to list.
If you don't need the context, consider using new_timer instead.
[in] | ticks | Number of ticks before the timer should fire |
[in] | flags | Timer flags. See TF_ONE_SHOT, TF_CONTINUOUS and TF_DISABLED |
[in] | callback | Callback function to call when the timer expires |
[in] | ctx | Opaque pointer to pass as an argument to callback |
void start_timer | ( | timer_link_t * | timer, |
int | ticks, | ||
int | flags, | ||
timer_callback1_t | callback | ||
) |
Start a timer (not currently in the list)
If you need to associate some data with the timer, consider using start_timer_context to include a pointer in the callback.
[in] | timer | Pointer to timer structure to reinsert and start |
[in] | ticks | Number of ticks before the timer should fire |
[in] | flags | Timer flags. See TF_ONE_SHOT, TF_CONTINUOUS, and TF_DISABLED |
[in] | callback | Callback function to call when the timer expires |
void start_timer_context | ( | timer_link_t * | timer, |
int | ticks, | ||
int | flags, | ||
timer_callback2_t | callback, | ||
void * | ctx | ||
) |
Start a timer (not currently in the list) with context.
If you don't need the context, consider using start_timer instead.
[in] | timer | Pointer to timer structure to reinsert and start |
[in] | ticks | Number of ticks before the timer should fire |
[in] | flags | Timer flags. See TF_ONE_SHOT, TF_CONTINUOUS, and TF_DISABLED |
[in] | callback | Callback function to call when the timer expires |
[in] | ctx | Opaque pointer to pass as an argument to callback |
void restart_timer | ( | timer_link_t * | timer | ) |
Reset a timer and add to list.
[in] | timer | Pointer to timer structure to reinsert and start |
void stop_timer | ( | timer_link_t * | timer | ) |
Stop a timer and remove it from the list.
[in] | timer | Timer structure to stop and remove |
void delete_timer | ( | timer_link_t * | timer | ) |
Remove a timer from the list and delete it.
[in] | timer | Timer structure to stop, remove and free |
void timer_close | ( | void | ) |
Free and close the timer subsystem.
This function will ensure all recurring timers are deleted from the list before closing. One-shot timers that have expired will need to be manually deleted with delete_timer.
The timer subsystem tracks the number of times timer_init is called and will only close the subsystem if timer_close is called the same number of times.
long long timer_ticks | ( | void | ) |
Return total ticks since timer was initialized, as a 64-bit counter.