Rev 762 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
495 | giacomo | 1 | /* |
2 | * Linux timer support. |
||
3 | */ |
||
4 | |||
5 | #include <linuxcomp.h> |
||
6 | |||
7 | #include <linux/kernel.h> |
||
8 | #include <linux/timer.h> |
||
9 | #include <asm/param.h> |
||
10 | |||
11 | //#define TIMER_DEBUG |
||
12 | |||
762 | giacomo | 13 | unsigned long long read_jiffies() |
14 | { |
||
15 | struct timespec acttime; |
||
16 | unsigned long long temp; |
||
17 | |||
18 | sys_gettime(&acttime); |
||
19 | temp = (unsigned long long)(acttime.tv_sec) * (unsigned long long)(HZ); |
||
20 | temp += (unsigned long long)(acttime.tv_nsec) * (unsigned long long)(HZ) / 1000000000L; |
||
21 | |||
22 | return temp; |
||
23 | |||
24 | } |
||
25 | |||
495 | giacomo | 26 | static inline void jiffies_to_timespec(unsigned long j, struct timespec *value) |
27 | { |
||
28 | value->tv_nsec = (j % HZ) * (1000000000L / HZ); |
||
29 | value->tv_sec = j / HZ; |
||
30 | } |
||
31 | |||
1007 | mauro | 32 | /*extern void *timer_func_table[MAX_TIMER_TABLE]; |
33 | extern void *timer_arg_table[MAX_TIMER_TABLE]; |
||
514 | giacomo | 34 | extern int intr_count; |
35 | void linux_timer(int no) |
||
36 | { |
||
37 | intr_count++; |
||
38 | |||
1007 | mauro | 39 | if (timer_func_table[no] != NULL) |
40 | (*(void (*)(void *arg))timer_func_table[no])(timer_arg_table[no]); |
||
514 | giacomo | 41 | |
42 | intr_count--; |
||
1007 | mauro | 43 | }*/ |
514 | giacomo | 44 | |
1007 | mauro | 45 | /* |
46 | * Generic Linux time handler. |
||
47 | */ |
||
495 | giacomo | 48 | void add_timer(struct timer_list *timer) |
49 | { |
||
50 | struct timespec timeout; |
||
51 | |||
52 | jiffies_to_timespec(timer->expires, &timeout); |
||
514 | giacomo | 53 | if (timer->function) { |
54 | timer->event_timer = shark_timer_set(&timeout, (void *)timer->function, (void *)timer->data); |
||
55 | } |
||
495 | giacomo | 56 | |
514 | giacomo | 57 | #ifdef TIMER_DEBUG |
58 | printk("Set to %ld:%ld\n",timeout.tv_sec,timeout.tv_nsec); |
||
59 | #endif |
||
495 | giacomo | 60 | } |
61 | |||
62 | |||
63 | int del_timer(struct timer_list *timer) |
||
64 | { |
||
514 | giacomo | 65 | |
66 | shark_timer_delete(timer->event_timer); |
||
67 | return 0; |
||
68 | |||
495 | giacomo | 69 | } |
70 | |||
71 | int mod_timer(struct timer_list *timer, unsigned long expires) |
||
72 | { |
||
514 | giacomo | 73 | |
522 | mauro | 74 | if (timer->event_timer != -1) shark_timer_delete(timer->event_timer); |
495 | giacomo | 75 | timer->expires = expires; |
76 | add_timer(timer); |
||
514 | giacomo | 77 | return 0; |
78 | |||
495 | giacomo | 79 | } |
80 | |||
81 | void init_timer(struct timer_list * timer) |
||
82 | { |
||
83 | timer->event_timer = -1; |
||
84 | timer->function = NULL; |
||
85 | } |
||
86 | |||
87 | int timer_pending(struct timer_list * timer){ |
||
88 | return timer->event_timer != -1; |
||
89 | } |
||
90 |