Subversion Repositories shark

Rev

Rev 1018 | Rev 1023 | Go to most recent revision | 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
 
51
PID intr_server = NIL;
52
void (*noint_handler)(int n);
53
 
54
#define MAX_INT_LIST 50
55
 
56
int int_list[MAX_INT_LIST];
57
 
58
int next_free_int = 0;
59
int next_execute_int = 0;
60
int n_intact = 0, n_lost = 0;
61
 
62
/* FIFO add job */
63
int add_interrupt_job(int no)
64
{
65
        int old_free_int = next_free_int;
66
 
1021 mauro 67
#ifdef DEBUG_SHARK_GLUE
68
        kern_printf("(add_interrupt_job: %d)", no);
69
#endif
70
 
1004 mauro 71
        if (no<16)
72
                irq_mask(no);
73
 
74
        TRACER_LOGEVENT(FTrace_EVT_user_event_1, no, 0);
75
 
76
        int_list[next_free_int] = no;
77
        next_free_int++;
78
 
79
        if (next_free_int == MAX_INT_LIST) next_free_int = 0;
80
        if (next_free_int == next_execute_int) {
81
                next_free_int = old_free_int;
82
                n_lost++;
83
                //Raise an exception?!?
84
                return -1;
85
        }
86
 
87
        if (intr_server!=NIL)
88
                task_activate(intr_server);
89
 
90
        return 0;
91
}
92
 
93
/* FIFO get job */
94
int get_interrupt_job()
95
{
96
        int res = -1;
97
 
98
        if (next_free_int != next_execute_int) {
99
                res = int_list[next_execute_int];
100
                next_execute_int++;
101
                if (next_execute_int == MAX_INT_LIST) next_execute_int = 0;
102
        }
103
 
104
        TRACER_LOGEVENT(FTrace_EVT_user_event_2, res, 0);
105
 
1021 mauro 106
#ifdef DEBUG_SHARK_GLUE
107
        kern_printf("(get_interrupt_job: %d)", res);
108
#endif
109
 
1004 mauro 110
        return res;
111
}
112
 
113
/* The Interrupt TASK is an aperiodic task designed for
114
        the INTDRIVE module. */
115
 
1018 mauro 116
void interrupt_job()
1004 mauro 117
{
118
        void (*tmp_fast)(int n);
119
        int no;
120
 
1018 mauro 121
        n_intact++;
122
 
123
        no = get_interrupt_job();
124
 
1021 mauro 125
#ifdef DEBUG_SHARK_GLUE
126
        kern_printf("(interrupt_job: no %d)",no);
127
#endif
128
 
1018 mauro 129
        if (no != -1 && no < 16) {
130
                tmp_fast = handler_get_intdrive(no);
1021 mauro 131
 
132
                /*extern void linux_intr(int irq);
133
                linux_intr(no);*/
134
 
1018 mauro 135
                (tmp_fast)(no);
136
                irq_unmask(no);
137
        }
138
 
139
        if (no != -1 && no >= 16) {
140
                (noint_handler)(no);
141
        }
142
}
143
 
144
TASK Interrupt_Server(void *arg)
145
{
1004 mauro 146
        while(1) {
1018 mauro 147
                interrupt_job();
1004 mauro 148
 
1018 mauro 149
                task_endcycle();
150
        }
1004 mauro 151
 
1018 mauro 152
}
1004 mauro 153
 
1018 mauro 154
TASK Interrupt_Server_Prot(void *arg)
155
{
156
        while(1) {
157
                task_nopreempt();
158
                interrupt_job();
159
                task_preempt();
1004 mauro 160
 
161
                task_endcycle();
162
        }
163
 
164
}
165
 
1018 mauro 166
int intdrive_taskinit(int level, int wcet)
1004 mauro 167
{
168
        HARD_TASK_MODEL ht;
169
 
1018 mauro 170
 
1004 mauro 171
        hard_task_default_model(ht);
172
        hard_task_def_wcet(ht, wcet);
173
        hard_task_def_interrupt(ht);
174
        hard_task_def_system(ht);
175
        hard_task_def_nokill(ht);
176
 
1021 mauro 177
        if (level > 0)
1018 mauro 178
                intr_server = task_create("Interrupt Server (Protected)",Interrupt_Server_Prot,&ht,NULL);
179
        else
180
                intr_server = task_create("Interrupt Server",Interrupt_Server,&ht,NULL);
181
 
1004 mauro 182
        if (intr_server == NIL)
183
                return -1;
1018 mauro 184
 
185
        return 0;
1004 mauro 186
}
187
 
188
void set_noint_handler(void * new_handler)
189
{
190
        noint_handler = new_handler;
1018 mauro 191
}