libdragon
|
Timer Subsystem. More...
Go to the source code of this file.
Data Structures | |
struct | timer_link_t |
Timer structure. More... | |
union | timer_link_t.__unnamed42__ |
Callback function to call when timer fires. More... | |
Macros | |
#define | TF_ONE_SHOT 0 |
Timer should fire only once. | |
#define | TF_CONTINUOUS 1 |
Timer should fire at a regular interval. | |
#define | TF_DISABLED 2 |
Timer is enabled or not. Can be used to get a new timer that's not started. | |
#define | TIMER_TICKS(us) ((int)TIMER_TICKS_LL(us)) |
Calculate timer ticks based on microseconds. | |
#define | TIMER_MICROS(tk) ((int)TIMER_MICROS_LL(tk)) |
Calculate microseconds based on timer ticks. | |
#define | TIMER_TICKS_LL(us) ((long long)(us) * TICKS_PER_SECOND / 1000000) |
Calculate timer ticks based on microseconds. | |
#define | TIMER_MICROS_LL(tk) ((long long)(tk) * 1000000 / TICKS_PER_SECOND) |
Calculate microseconds based on timer ticks. | |
Typedefs | |
typedef void(* | timer_callback1_t) (int ovfl) |
Timer callback function without context. | |
typedef void(* | timer_callback2_t) (int ovfl, void *ctx) |
Timer callback function with context. | |
Functions | |
void | timer_init (void) |
Initialize the timer subsystem. | |
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_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. | |
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.
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.
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 |