Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 * Copyright (c) 1996 The University of Utah and
3
 * the Computer Systems Laboratory at the University of Utah (CSL).
4
 * All rights reserved.
5
 *
6
 * Permission to use, copy, modify and distribute this software is hereby
7
 * granted provided that (1) source code retains these copyright, permission,
8
 * and disclaimer notices, and (2) redistributions including binaries
9
 * reproduce the notices in supporting documentation, and (3) all advertising
10
 * materials mentioning features or use of this software display the following
11
 * acknowledgement: ``This product includes software developed by the
12
 * Computer Systems Laboratory at the University of Utah.''
13
 *
14
 * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
15
 * IS" CONDITION.  THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
16
 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17
 *
18
 * CSL requests users of this software to return to csl-dist@cs.utah.edu any
19
 * improvements that they make and grant CSL redistribution rights.
20
 */
21
/*
22
 * Linux timer support.
23
 */
24
 
25
#include<hartik.h>
26
#include<linux/timer.h>
27
 
28
#define N_MAX_TIMER 50
29
 
30
struct timer_entry {
31
        unsigned long data;
32
        void (*function)(unsigned long);
33
        PID pid;
34
        char Signat;
35
};
36
 
37
struct timer_entry timer_table[N_MAX_TIMER];
38
 
39
 
40
TASK timer_task(int i)
41
{
42
                void (*fn)(unsigned long) = timer_table[i].function;
43
                unsigned long data = timer_table[i].data;
44
 
45
 
46
                if (timer_table[i].Signat != 'L') {
47
                                sys_abort(200);
48
                }
49
cprintf("Delay 1\n");
50
                task_endcycle();                /* 1st of all, sleep!!! */
51
 
52
cprintf("Delay 2\n");
53
                /* Ok, now the timer is expired... */
54
                fn(data);
55
 
56
                /* The timer task now can die... */
57
 
58
cprintf("Delay 3\n");
59
        task_abort();
60
}
61
 
62
int add_timer(struct timer_list *timer)
63
{
64
        SYS_FLAGS flags;
65
        PID p;
66
        MODEL m = BASE_MODEL;
67
        int done = 0;
68
        int i = 0;
69
 
70
        flags = kern_fsave();
71
        while (!done) {
72
                done = ((i = N_MAX_TIMER) || (timer_table[i].Signat != 'L'));
73
                if (!done) {
74
                        i++;
75
                } else {
76
                        timer_table[i].Signat = 'L';
77
                }
78
        }
79
        kern_frestore(flags);
80
 
81
        if (i == N_MAX_TIMER) {
82
                return -1;
83
        }
84
 
85
        timer_table[i].function = timer->function;
86
        timer_table[i].data = timer->data;
87
        task_set_arg(m,i);
88
        task_set_wcet(m, 2000);
89
        p = task_create("Timer", timer_task, SOFT, PERIODIC, timer->expires,&m);
90
        if (p != -1) {
91
                timer_table[i].pid = p;
92
                task_activate(p);
93
                return 1;
94
        } else {
95
                timer_table[i].Signat = ' ';
96
                return -1;
97
        }
98
}
99
 
100
void del_timer(struct timer_list *timer)
101
{
102
        int done = 0;
103
        int i = 0;
104
 
105
        while (!done) {
106
                done = ((i = N_MAX_TIMER) || (timer_table[i].function = timer->function));
107
                if (!done) {
108
                        i++;
109
                } else {
110
                        timer_table[i].Signat = ' ';
111
                        task_kill(timer_table[i].pid);
112
                }
113
        }
114
}
115