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