libdragon
Loading...
Searching...
No Matches
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
42typedef void (*timer_callback1_t)(int ovfl);
44typedef void (*timer_callback2_t)(int ovfl, void *ctx);
45
49typedef struct timer_link
50{
52 uint32_t left;
54 uint32_t set;
56 int ovfl;
58 int flags;
60 union {
61 timer_callback1_t callback;
62 timer_callback2_t callback_with_context;
63 };
65 void *ctx;
67 struct timer_link *next;
69
71#define TF_ONE_SHOT 0
73#define TF_CONTINUOUS 1
75#define TF_DISABLED 2
76
85#define TIMER_TICKS(us) ((int)TIMER_TICKS_LL(us))
94#define TIMER_MICROS(tk) ((int)TIMER_MICROS_LL(tk))
95
104#define TIMER_TICKS_LL(us) ((long long)(us) * TICKS_PER_SECOND / 1000000)
113#define TIMER_MICROS_LL(tk) ((long long)(tk) * 1000000 / TICKS_PER_SECOND)
114
117#ifdef __cplusplus
118extern "C" {
119#endif
120
136void timer_init(void);
137
149void timer_close(void);
150
157long long timer_ticks(void);
158
159
175timer_link_t *new_timer(int ticks, int flags, timer_callback1_t callback);
176
193timer_link_t *new_timer_context(int ticks, int flags, timer_callback2_t callback, void *ctx);
194
195
211void start_timer(timer_link_t *timer, int ticks, int flags, timer_callback1_t callback);
212
229void start_timer_context(timer_link_t *timer, int ticks, int flags, timer_callback2_t callback, void *ctx);
230
231
238void restart_timer(timer_link_t *timer);
239
252void stop_timer(timer_link_t *timer);
253
262void delete_timer(timer_link_t *timer);
263
264#ifdef __cplusplus
265}
266#endif
267
268#endif
int flags
Timer flags. See TF_ONE_SHOT, TF_CONTINUOUS, and TF_DISABLED.
Definition timer.h:58
int ovfl
To correct for drift.
Definition timer.h:56
uint32_t left
Absolute ticks value at which the timer expires.
Definition timer.h:52
uint32_t set
Ticks to set if continuous.
Definition timer.h:54
void * ctx
Callback context parameter.
Definition timer.h:65
struct timer_link * next
Link to next timer.
Definition timer.h:67
void(* timer_callback1_t)(int ovfl)
Timer callback function without context.
Definition timer.h:42
void(* timer_callback2_t)(int ovfl, void *ctx)
Timer callback function with context.
Definition timer.h:44
N64 System Interface.
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:242
void timer_close(void)
Free and close the timer subsystem.
Definition timer.c:355
timer_link_t * new_timer(int ticks, int flags, timer_callback1_t callback)
Create a new timer and add to list.
Definition timer.c:186
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:214
void timer_init(void)
Initialize the timer subsystem.
Definition timer.c:172
void stop_timer(timer_link_t *timer)
Stop a timer and remove it from the list.
Definition timer.c:313
void delete_timer(timer_link_t *timer)
Remove a timer from the list and delete it.
Definition timer.c:345
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:268
long long timer_ticks(void)
Return total ticks since timer was initialized, as a 64-bit counter.
Definition timer.c:390
void restart_timer(timer_link_t *timer)
Reset a timer and add to list.
Definition timer.c:294