XenevaOS
Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1struct timer_list {
2 void (*function)(struct timer_list* t);
3 unsigned long expires; /* in jiffies */
4 void* data; /* private context */
5 int pending;
6};
7
8/* Jiffies — you need to provide this from your system counter */
9extern volatile unsigned long jiffies; /* increment at HZ rate */
10
11#define HZ 250 /* ticks per second — tune to your timer IRQ */
12#define msecs_to_jiffies(ms) ((ms) * HZ / 1000)
13#define jiffies_to_msecs(j) ((j) * 1000 / HZ)
14#define time_after(a, b) ((long)((b) - (a)) < 0)
15#define time_before(a, b) time_after(b, a)
16#define time_after_eq(a, b) ((long)((a) - (b)) >= 0)
17
18#define timer_setup(t, fn, flags) do { \
19 (t)->function = (fn); \
20 (t)->pending = 0; \
21 (t)->data = NULL; \
22 (t)->expires = 0; \
23} while (0)
24
25/* Legacy init form DWC2 may use */
26#define setup_timer(t, fn, data) do { \
27 (t)->function = (void(*)(struct timer_list*))(fn); \
28 (t)->data = (void*)(data); \
29 (t)->pending = 0; \
30} while (0)
31
32/* On bare metal — you need a real timer queue for these */
33/* Stub for bring-up: call immediately */
34static inline void add_timer(struct timer_list* t) {
35 t->pending = 1;
36 /* TODO: insert into your timer queue */
37}
38
39static inline int mod_timer(struct timer_list* t, unsigned long expires) {
40 t->expires = expires;
41 t->pending = 1;
42 /* TODO: update in your timer queue */
43 return 0;
44}
45
46static inline int del_timer(struct timer_list* t) {
47 int was_pending = t->pending;
48 t->pending = 0;
49 return was_pending;
50}
51
52static inline int del_timer_sync(struct timer_list* t) {
53 return del_timer(t);
54}
55
56static inline int timer_pending(const struct timer_list* t) {
57 return t->pending;
58}
59
60/* Helper to get owning struct from timer pointer */
61#define from_timer(var, callback_timer, timer_fieldname) \
62 container_of(callback_timer, typeof(*var), timer_fieldname)
XETime t
Definition main.cpp:53
volatile unsigned long jiffies
Definition timer.h:1
void * data
Definition timer.h:4
int pending
Definition timer.h:5
void(* function)(struct timer_list *t)
Definition timer.h:2
unsigned long expires
Definition timer.h:3