libdragon
timer.h
Go to the documentation of this file.
1
6#ifndef __LIBDRAGON_TIMER_H
7#define __LIBDRAGON_TIMER_H
8
9#include <stdint.h>
10#include "n64sys.h"
11
18typedef void (*timer_callback1_t)(int ovfl);
20typedef void (*timer_callback2_t)(int ovfl, void *ctx);
21
25typedef struct timer_link
26{
28 uint32_t left;
30 uint32_t set;
32 int ovfl;
34 int flags;
36 union {
37 timer_callback1_t callback;
38 timer_callback2_t callback_with_context;
39 };
41 void *ctx;
43 struct timer_link *next;
45
47#define TF_ONE_SHOT 0
49#define TF_CONTINUOUS 1
51#define TF_DISABLED 2
52
61#define TIMER_TICKS(us) ((int)TIMER_TICKS_LL(us))
70#define TIMER_MICROS(tk) ((int)TIMER_MICROS_LL(tk))
71
80#define TIMER_TICKS_LL(us) ((long long)(us) * TICKS_PER_SECOND / 1000000)
89#define TIMER_MICROS_LL(tk) ((long long)(tk) * 1000000 / TICKS_PER_SECOND)
90
93#ifdef __cplusplus
94extern "C" {
95#endif
96
97/* initialize timer subsystem */
98void timer_init(void);
99/* delete all timers in list */
100void timer_close(void);
101/* return total ticks since timer was initialized */
102long long timer_ticks(void);
103
104/* create a new timer and add to list */
105timer_link_t *new_timer(int ticks, int flags, timer_callback1_t callback);
106/* create a new timer and add to list */
107timer_link_t *new_timer_context(int ticks, int flags, timer_callback2_t callback, void *ctx);
108
109/* start a timer not currently in the list */
110void start_timer(timer_link_t *timer, int ticks, int flags, timer_callback1_t callback);
111/* start a timer not currently in the list */
112void start_timer_context(timer_link_t *timer, int ticks, int flags, timer_callback2_t callback, void *ctx);
113
114/* reset a timer and add to list */
115void restart_timer(timer_link_t *timer);
116/* remove a timer from the list */
117void stop_timer(timer_link_t *timer);
118/* remove a timer from the list and delete it */
119void delete_timer(timer_link_t *timer);
120
121#ifdef __cplusplus
122}
123#endif
124
125#endif
int flags
Timer flags. See TF_ONE_SHOT, TF_CONTINUOUS, and TF_DISABLED.
Definition: timer.h:34
int ovfl
To correct for drift.
Definition: timer.h:32
uint32_t left
Absolute ticks value at which the timer expires.
Definition: timer.h:28
uint32_t set
Ticks to set if continuous.
Definition: timer.h:30
void * ctx
Callback context parameter.
Definition: timer.h:41
struct timer_link * next
Link to next timer.
Definition: timer.h:43
void start_timer(timer_link_t *timer, int ticks, int flags, timer_callback1_t callback)
Start a timer (not currently in the list)
Definition: timer.c:358
void timer_close(void)
Free and close the timer subsystem.
Definition: timer.c:520
timer_link_t * new_timer(int ticks, int flags, timer_callback1_t callback)
Create a new timer and add to list.
Definition: timer.c:271
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.
Definition: timer.c:315
void timer_init(void)
Initialize the timer subsystem.
Definition: timer.c:226
void stop_timer(timer_link_t *timer)
Stop a timer and remove it from the list.
Definition: timer.c:463
void(* timer_callback1_t)(int ovfl)
Timer callback function without context.
Definition: timer.h:18
void delete_timer(timer_link_t *timer)
Remove a timer from the list and delete it.
Definition: timer.c:503
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.
Definition: timer.c:400
long long timer_ticks(void)
Return total ticks since timer was initialized, as a 64-bit counter.
Definition: timer.c:557
void(* timer_callback2_t)(int ovfl, void *ctx)
Timer callback function with context.
Definition: timer.h:20
void restart_timer(timer_link_t *timer)
Reset a timer and add to list.
Definition: timer.c:432
N64 System Interface.