Subversion Repositories shark

Rev

Rev 1004 | Rev 1021 | 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
 
1018 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
 
67
        if (no<16)
68
                irq_mask(no);
69
 
70
        TRACER_LOGEVENT(FTrace_EVT_user_event_1, no, 0);
71
 
72
        int_list[next_free_int] = no;
73
        next_free_int++;
74
 
75
        if (next_free_int == MAX_INT_LIST) next_free_int = 0;
76
        if (next_free_int == next_execute_int) {
77
                next_free_int = old_free_int;
78
                n_lost++;
79
                //Raise an exception?!?
80
                return -1;
81
        }
82
 
83
        if (intr_server!=NIL)
84
                task_activate(intr_server);
85
 
86
        return 0;
87
}
88
 
89
/* FIFO get job */
90
int get_interrupt_job()
91
{
92
        int res = -1;
93
 
94
        if (next_free_int != next_execute_int) {
95
                res = int_list[next_execute_int];
96
                next_execute_int++;
97
                if (next_execute_int == MAX_INT_LIST) next_execute_int = 0;
98
        }
99
 
100
        TRACER_LOGEVENT(FTrace_EVT_user_event_2, res, 0);
101
 
102
        return res;
103
}
104
 
105
/* The Interrupt TASK is an aperiodic task designed for
106
        the INTDRIVE module. */
107
 
1018 mauro 108
void interrupt_job()
1004 mauro 109
{
110
        void (*tmp_fast)(int n);
111
        int no;
112
 
1018 mauro 113
        n_intact++;
114
 
115
        no = get_interrupt_job();
116
 
117
        if (no != -1 && no < 16) {
118
                tmp_fast = handler_get_intdrive(no);
119
                (tmp_fast)(no);
120
                irq_unmask(no);
121
        }
122
 
123
        if (no != -1 && no >= 16) {
124
                (noint_handler)(no);
125
        }
126
}
127
 
128
TASK Interrupt_Server(void *arg)
129
{
1004 mauro 130
        while(1) {
1018 mauro 131
                interrupt_job();
1004 mauro 132
 
1018 mauro 133
                task_endcycle();
134
        }
1004 mauro 135
 
1018 mauro 136
}
1004 mauro 137
 
1018 mauro 138
TASK Interrupt_Server_Prot(void *arg)
139
{
140
        while(1) {
141
                task_nopreempt();
142
                interrupt_job();
143
                task_preempt();
1004 mauro 144
 
145
                task_endcycle();
146
        }
147
 
148
}
149
 
1018 mauro 150
int intdrive_taskinit(int level, int wcet)
1004 mauro 151
{
152
        HARD_TASK_MODEL ht;
153
 
1018 mauro 154
 
1004 mauro 155
        hard_task_default_model(ht);
156
        hard_task_def_wcet(ht, wcet);
157
        hard_task_def_interrupt(ht);
158
        hard_task_def_system(ht);
159
        hard_task_def_nokill(ht);
160
 
1018 mauro 161
        if (level >= 0)
162
                intr_server = task_create("Interrupt Server (Protected)",Interrupt_Server_Prot,&ht,NULL);
163
        else
164
                intr_server = task_create("Interrupt Server",Interrupt_Server,&ht,NULL);
165
 
1004 mauro 166
        if (intr_server == NIL)
167
                return -1;
1018 mauro 168
 
169
        return 0;
1004 mauro 170
}
171
 
172
void set_noint_handler(void * new_handler)
173
{
174
        noint_handler = new_handler;
1018 mauro 175
}