Subversion Repositories shark

Rev

Rev 1046 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1004 mauro 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   ...         <......>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/*
20
 * Copyright (C) 2000,2002 Paolo Gai
21
 *
22
 * This program is free software; you can redistribute it and/or modify
23
 * it under the terms of the GNU General Public License as published by
24
 * the Free Software Foundation; either version 2 of the License, or
25
 * (at your option) any later version.
26
 *
27
 * This program is distributed in the hope that it will be useful,
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
 * GNU General Public License for more details.
31
 *
32
 * You should have received a copy of the GNU General Public License
33
 * along with this program; if not, write to the Free Software
34
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
35
 *
36
 */
37
 
38
/* Interrupt Driver Module */
39
 
40
#include <kernel/int_sem.h>
41
#include <stdlib.h>
42
#include <kernel/func.h>
43
#include <ll/sys/ll/event.h>
44
#include <ll/i386/pic.h>
45
#include <tracer.h>
46
 
47
#include <intdrive/intdrive/inttask.h>
48
 
1021 mauro 49
//#define DEBUG_SHARK_GLUE
1004 mauro 50
 
1046 tullio 51
/*
52
 * Moved into intdrive.c
53
 */
54
extern PID intr_server;
55
 
1004 mauro 56
void (*noint_handler)(int n);
57
 
58
#define MAX_INT_LIST 50
59
 
60
int int_list[MAX_INT_LIST];
61
 
62
int next_free_int = 0;
63
int next_execute_int = 0;
64
int n_intact = 0, n_lost = 0;
65
 
66
/* FIFO add job */
67
int add_interrupt_job(int no)
68
{
69
        int old_free_int = next_free_int;
70
 
1021 mauro 71
#ifdef DEBUG_SHARK_GLUE
72
        kern_printf("(add_interrupt_job: %d)", no);
73
#endif
74
 
1004 mauro 75
        if (no<16)
76
                irq_mask(no);
77
 
1033 tullio 78
#ifdef DEBUG_SHARK_GLUE
1004 mauro 79
        TRACER_LOGEVENT(FTrace_EVT_user_event_1, no, 0);
1033 tullio 80
#endif
1004 mauro 81
 
82
        int_list[next_free_int] = no;
83
        next_free_int++;
84
 
85
        if (next_free_int == MAX_INT_LIST) next_free_int = 0;
86
        if (next_free_int == next_execute_int) {
87
                next_free_int = old_free_int;
88
                n_lost++;
89
                //Raise an exception?!?
90
                return -1;
91
        }
92
 
93
        if (intr_server!=NIL)
94
                task_activate(intr_server);
95
 
96
        return 0;
97
}
98
 
99
/* FIFO get job */
100
int get_interrupt_job()
101
{
102
        int res = -1;
103
 
104
        if (next_free_int != next_execute_int) {
105
                res = int_list[next_execute_int];
106
                next_execute_int++;
107
                if (next_execute_int == MAX_INT_LIST) next_execute_int = 0;
108
        }
109
 
1033 tullio 110
#ifdef DEBUG_SHARK_GLUE
1004 mauro 111
        TRACER_LOGEVENT(FTrace_EVT_user_event_2, res, 0);
1033 tullio 112
#endif
1004 mauro 113
 
1021 mauro 114
#ifdef DEBUG_SHARK_GLUE
115
        kern_printf("(get_interrupt_job: %d)", res);
116
#endif
117
 
1004 mauro 118
        return res;
119
}
120
 
121
/* The Interrupt TASK is an aperiodic task designed for
122
        the INTDRIVE module. */
123
 
1018 mauro 124
void interrupt_job()
1004 mauro 125
{
126
        void (*tmp_fast)(int n);
127
        int no;
128
 
1018 mauro 129
        n_intact++;
130
 
131
        no = get_interrupt_job();
132
 
1021 mauro 133
#ifdef DEBUG_SHARK_GLUE
134
        kern_printf("(interrupt_job: no %d)",no);
135
#endif
136
 
1018 mauro 137
        if (no != -1 && no < 16) {
138
                tmp_fast = handler_get_intdrive(no);
1021 mauro 139
 
140
                /*extern void linux_intr(int irq);
141
                linux_intr(no);*/
142
 
1018 mauro 143
                (tmp_fast)(no);
144
                irq_unmask(no);
145
        }
146
 
147
        if (no != -1 && no >= 16) {
148
                (noint_handler)(no);
149
        }
150
}
151
 
1077 fabio 152
/*
153
 * When an handler is removed pending activations have to be removed.
154
 * This may cause interrupt losses, drivers should be aware of that.
155
 */
156
void invalidate_pending_jobs(int no)
157
{
158
        int i;
159
 
160
        i = next_execute_int;
161
        while (i != next_free_int) {
162
                if (int_list[i] == no)
163
                        int_list[i] = -1;
164
                i = (i + 1) % MAX_INT_LIST;
165
        }
166
}
167
 
1018 mauro 168
TASK Interrupt_Server(void *arg)
169
{
1004 mauro 170
        while(1) {
1018 mauro 171
                interrupt_job();
1004 mauro 172
 
1018 mauro 173
                task_endcycle();
174
        }
1004 mauro 175
 
1018 mauro 176
}
1004 mauro 177
 
1018 mauro 178
TASK Interrupt_Server_Prot(void *arg)
179
{
180
        while(1) {
181
                task_nopreempt();
182
                interrupt_job();
183
                task_preempt();
1004 mauro 184
 
185
                task_endcycle();
186
        }
187
 
188
}
189
 
190
void set_noint_handler(void * new_handler)
191
{
192
        noint_handler = new_handler;
1018 mauro 193
}