Subversion Repositories shark

Rev

Rev 1018 | Go to most recent revision | Details | 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
 
49
//#define DEBUG_SHARK_GLUE
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
 
108
TASK Interrupt_Server(void *arg)
109
{
110
        void (*tmp_fast)(int n);
111
        int no;
112
 
113
        while(1) {
114
                n_intact++;
115
 
116
                no = get_interrupt_job();
117
 
118
                if (no != -1 && no < 16) {
119
                        tmp_fast = handler_get_intdrive(no);
120
                        (tmp_fast)(no);
121
                        irq_unmask(no);
122
                }
123
 
124
                if (no != -1 && no >= 16) {
125
                        (noint_handler)(no);
126
                }
127
 
128
                task_endcycle();
129
        }
130
 
131
}
132
 
133
int intdrive_taskinit(int wcet)
134
{
135
        HARD_TASK_MODEL ht;
136
 
137
        hard_task_default_model(ht);
138
        hard_task_def_wcet(ht, wcet);
139
        hard_task_def_interrupt(ht);
140
        hard_task_def_system(ht);
141
        hard_task_def_nokill(ht);
142
 
143
        intr_server = task_create("Interrupt Server",Interrupt_Server,&ht,NULL);
144
        if (intr_server == NIL)
145
                return -1;
146
}
147
 
148
void set_noint_handler(void * new_handler)
149
{
150
        noint_handler = new_handler;
151
}