Subversion Repositories shark

Rev

Rev 526 | Go to most recent revision | 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
 
526 giacomo 32
extern void *int_arg_table[MAX_INT_TABLE];
33
extern void *int_func_table[MAX_INT_TABLE];
514 giacomo 34
extern int intr_count;
35
 
36
/*
37
 * Generic Linux time handler.
38
 */
39
void linux_timer(int no)
40
{
41
        intr_count++;
42
 
43
        if (int_func_table[no] != NULL)
44
                (*(void (*)(void *arg))int_func_table[no])(int_arg_table[no]);
45
 
46
        intr_count--;
47
 
48
}
49
 
495 giacomo 50
void add_timer(struct timer_list *timer)
51
{
52
        struct timespec timeout;
53
 
54
        jiffies_to_timespec(timer->expires, &timeout);
514 giacomo 55
        if (timer->function) {
56
                timer->event_timer = shark_timer_set(&timeout, (void *)timer->function, (void *)timer->data);
57
        }
495 giacomo 58
 
514 giacomo 59
        #ifdef TIMER_DEBUG
60
          printk("Set to %ld:%ld\n",timeout.tv_sec,timeout.tv_nsec);
61
        #endif
495 giacomo 62
}
63
 
64
 
65
int del_timer(struct timer_list *timer)
66
{
514 giacomo 67
 
68
        shark_timer_delete(timer->event_timer);
69
        return 0;
70
 
495 giacomo 71
}
72
 
73
int mod_timer(struct timer_list *timer, unsigned long expires)
74
{
514 giacomo 75
 
522 mauro 76
        if (timer->event_timer != -1) shark_timer_delete(timer->event_timer);
495 giacomo 77
        timer->expires = expires;
78
        add_timer(timer);
514 giacomo 79
        return 0;
80
 
495 giacomo 81
}
82
 
83
void init_timer(struct timer_list * timer)
84
{
85
        timer->event_timer = -1;
86
        timer->function = NULL;
87
}
88
 
89
int timer_pending(struct timer_list * timer){
90
        return timer->event_timer != -1;
91
}
92