Subversion Repositories shark

Rev

Rev 905 | Rev 1018 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
490 giacomo 1
#include <kernel/int_sem.h>
2
#include <stdlib.h>
496 giacomo 3
#include <kernel/func.h>
4
#include <ll/sys/ll/event.h>
540 giacomo 5
#include <ll/i386/pic.h>
905 mauro 6
#include <tracer.h>
490 giacomo 7
 
526 giacomo 8
#include <linuxcomp.h>
9
 
1007 mauro 10
extern int add_interrupt_job(int no);
11
extern void set_noint_handler(void * new_handler);
540 giacomo 12
 
1007 mauro 13
extern int intr_count;
513 giacomo 14
 
1007 mauro 15
//#define DEBUG_SHARK_GLUE
513 giacomo 16
 
514 giacomo 17
/* 1-15 for IRQ and 16-63 for timers */
1007 mauro 18
void *timer_arg_table[MAX_TIMER_TABLE];
19
void *timer_func_table[MAX_TIMER_TABLE];
20
int  timer_table[MAX_TIMER_TABLE];
21
int  intr_table[NR_IRQS];
513 giacomo 22
 
1007 mauro 23
int use_intdrive = 0;
24
static int current_timer = 0;
514 giacomo 25
 
1007 mauro 26
void shark_internal_sem_create(void **sem, int init) {
27
        *sem = (void *)malloc(sizeof(internal_sem_t));
28
        internal_sem_init((internal_sem_t *)(*sem),init);
29
}
513 giacomo 30
 
1007 mauro 31
void shark_internal_sem_wait(void *sem) {
32
        internal_sem_wait((internal_sem_t *)(sem));
513 giacomo 33
}
34
 
1007 mauro 35
void shark_internal_sem_post(void *sem) {
36
        internal_sem_post((internal_sem_t *)(sem));
513 giacomo 37
}
38
 
1007 mauro 39
/* Timers */
559 giacomo 40
 
514 giacomo 41
int get_free_timer_slot()
42
{
1007 mauro 43
        int i = current_timer;
514 giacomo 44
 
559 giacomo 45
        while(timer_table[i] != -1) {
1007 mauro 46
                if (i < MAX_TIMER_TABLE) {
559 giacomo 47
                        i++;
48
                } else {
1007 mauro 49
                        i = 0;
559 giacomo 50
                }
1007 mauro 51
                if (i == current_timer) return -1;
559 giacomo 52
        }
53
 
54
        current_timer = i+1;
1007 mauro 55
        if (current_timer >= MAX_TIMER_TABLE) current_timer = 0;
559 giacomo 56
 
514 giacomo 57
        return i;
58
}
59
 
1007 mauro 60
void shark_timer_exec(int n)
513 giacomo 61
{
1007 mauro 62
        int no = n - 16;
63
        void(*tmp_func)(void*) = timer_func_table[no];
513 giacomo 64
 
1007 mauro 65
#ifdef DEBUG_SHARK_GLUE
66
        cprintf("(Timer EXEC %d)", no);
67
#endif
513 giacomo 68
 
1007 mauro 69
        if (tmp_func != NULL){
70
                intr_count++;
71
                (tmp_func)(timer_arg_table[no]);
72
                intr_count--;
513 giacomo 73
        }
74
 
1007 mauro 75
        timer_table[no] = -1;
76
        timer_func_table[no] = NULL;
77
        timer_arg_table[no] = NULL;
513 giacomo 78
}
79
 
514 giacomo 80
void fast_call_timer(void *arg)
496 giacomo 81
{
1007 mauro 82
        int no = (int)arg;
83
        int res;
514 giacomo 84
 
1007 mauro 85
#ifdef DEBUG_SHARK_GLUE
86
        cprintf("(Timer fast %d)", no);
87
#endif
514 giacomo 88
 
525 giacomo 89
        timer_table[no] = -2;
90
 
1007 mauro 91
        if (use_intdrive == TRUE) {
92
                res = add_interrupt_job(no+16);
93
        } else {
94
                shark_timer_exec(no+16);
95
        }
490 giacomo 96
}
97
 
514 giacomo 98
int shark_timer_set(const struct timespec *time, void *handler, void *arg)
496 giacomo 99
{
514 giacomo 100
        SYS_FLAGS f;
101
        int i;
102
 
103
        f = kern_fsave();
104
 
1007 mauro 105
#ifdef DEBUG_SHARK_GLUE
106
          cprintf("(Timer Set %d)", no);
107
#endif
540 giacomo 108
 
514 giacomo 109
        i = get_free_timer_slot();
110
 
111
        if (i == -1) {
112
                kern_frestore(f);
113
                return -1;
114
        }
115
 
1007 mauro 116
        timer_func_table[i] = handler;
117
        timer_arg_table[i] = arg;
514 giacomo 118
 
1007 mauro 119
        timer_table[i] = kern_event_post(time, fast_call_timer, (void *)(i));
514 giacomo 120
 
121
        if (timer_table[i] == -1) {
122
                kern_frestore(f);
1007 mauro 123
                return -1;
124
        }
514 giacomo 125
 
126
        kern_frestore(f);
127
 
128
        return i;
496 giacomo 129
}
490 giacomo 130
 
514 giacomo 131
int shark_timer_delete(int index)
513 giacomo 132
{
514 giacomo 133
        SYS_FLAGS f;
522 mauro 134
 
1007 mauro 135
        f = kern_fsave();
514 giacomo 136
 
1007 mauro 137
        if (index <= 0 || index >= MAX_TIMER_TABLE) {
522 mauro 138
                kern_frestore(f);
139
                return -1;
140
        }
141
 
1007 mauro 142
#ifdef DEBUG_SHARK_GLUE
143
          cprintf("(Timer Del %d)", no);
144
#endif
540 giacomo 145
 
525 giacomo 146
        if (timer_table[index] != -1 && timer_table[index] != -2) {
1007 mauro 147
                timer_func_table[index] = NULL;
148
                timer_arg_table[index] = NULL;
525 giacomo 149
 
514 giacomo 150
                kern_event_delete(timer_table[index]);
151
                timer_table[index] = -1;
152
        }                                                                                                        
1007 mauro 153
        kern_frestore(f);
514 giacomo 154
 
155
        return 0;
156
}
157
 
158
/* Interrupt */
1007 mauro 159
int shark_handler_set(int no, void *fast){
514 giacomo 160
 
1007 mauro 161
        if ((no >= 1) && (no < 16) && (intr_table[no] <= 0)) {
162
                if (use_intdrive == TRUE) {
163
                        intr_table[no] = handler_set(no, NULL, TRUE, NIL, fast);
164
#ifdef DEBUG_SHARK_GLUE
165
                        cprintf("(shark_handler_set - INT: %d - %d)", no, intr_table[no]);
166
#endif
167
                } else {
168
                        intr_table[no] = handler_set(no, fast, TRUE, NIL, NULL);
169
#ifdef DEBUG_SHARK_GLUE
170
                        cprintf("(Shark_Handler_Set - NOINT: %d - %d)", no, intr_table[no]);
171
#endif
172
                }
173
                return intr_table[no];
174
        } else {
175
#ifdef DEBUG_SHARK_GLUE
176
                cprintf("(shark_handler_set - ERR: %d - %d)", no, intr_table[no]);
177
#endif
178
                return -1;
179
        }
496 giacomo 180
}
490 giacomo 181
 
1007 mauro 182
int shark_handler_remove(int no){
513 giacomo 183
 
1007 mauro 184
        if (intr_table[no] == 1) {
185
                handler_remove(no);
186
#ifdef DEBUG_SHARK_GLUE
187
                cprintf("(shark_handler_remove: %d)", no);
188
#endif
189
                intr_table[no] = 0;
513 giacomo 190
        }
191
 
1007 mauro 192
        return 0;
513 giacomo 193
}
1007 mauro 194
 
195
/* Boot function */
196
int shark_interrupt_server(int use_intdrv) {
197
        int i;
513 giacomo 198
 
1007 mauro 199
        for(i=0; i<MAX_TIMER_TABLE; i++) {
200
                timer_arg_table[i] = NULL;
201
                timer_func_table[i] = NULL;
202
                timer_table[i] = -1;
203
        }
204
        for(i=0; i<NR_IRQS; i++) {
205
                intr_table[i] = 0;
206
        }
207
 
208
        use_intdrive = use_intdrv;
209
#ifdef DEBUG_SHARK_GLUE
210
        cprintf("(Use_intdrive: %d)", use_intdrive);
211
#endif
212
        if (use_intdrive == TRUE)
213
                set_noint_handler(shark_timer_exec);
514 giacomo 214
 
215
        return 0;
490 giacomo 216
}
496 giacomo 217