Rev 1567 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1120 | pj | 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 | * Paolo Gai <pj@gandalf.sssup.it> |
||
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 | ------------ |
||
1586 | tullio | 21 | CVS : $Id: iaster6.c,v 1.8 2006-07-03 13:12:06 tullio Exp $ |
1120 | pj | 22 | |
23 | File: $File$ |
||
1586 | tullio | 24 | Revision: $Revision: 1.8 $ |
25 | Last update: $Date: 2006-07-03 13:12:06 $ |
||
1120 | pj | 26 | ------------ |
27 | |||
28 | System initialization file |
||
29 | |||
30 | h3pips.c |
||
31 | |||
32 | These functions register the following levels: |
||
33 | |||
34 | an EDF (Earliest Deadline First) level |
||
35 | a RR (Round Robin) level |
||
36 | a CBS (Costant Bandwidth Server) level |
||
37 | a PS (Polling Server) level |
||
38 | a Dummy level |
||
39 | |||
40 | It can accept these task models: |
||
41 | |||
42 | HARD_TASK_MODEL (wcet+mit) at level 0 |
||
43 | NRT_TASK_MODEL at level 1 |
||
44 | SOFT_TASK_MODEL (met, period) at level 2 |
||
45 | SOFT_TASK_MODEL (periodicity=APERIODIC) at level 3 |
||
46 | |||
47 | **/ |
||
48 | |||
49 | /* |
||
50 | * Copyright (C) 2000 Paolo Gai |
||
51 | * |
||
52 | * This program is free software; you can redistribute it and/or modify |
||
53 | * it under the terms of the GNU General Public License as published by |
||
54 | * the Free Software Foundation; either version 2 of the License, or |
||
55 | * (at your option) any later version. |
||
56 | * |
||
57 | * This program is distributed in the hope that it will be useful, |
||
58 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
59 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
60 | * GNU General Public License for more details. |
||
61 | * |
||
62 | * You should have received a copy of the GNU General Public License |
||
63 | * along with this program; if not, write to the Free Software |
||
64 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
65 | * |
||
66 | */ |
||
67 | |||
68 | |||
69 | |||
70 | #include "kernel/kern.h" |
||
1377 | giacomo | 71 | |
1552 | pj | 72 | #include "intdrive/intdrive/intdrive.h" |
73 | #include "edf/edf/edf.h" |
||
74 | #include "cbs/cbs/cbs.h" |
||
75 | #include "rr/rr/rr.h" |
||
76 | #include "dummy/dummy/dummy.h" |
||
77 | #include "ps/ps/ps.h" |
||
1120 | pj | 78 | |
1552 | pj | 79 | #include "sem/sem/sem.h" |
80 | #include "cabs/cabs/cabs.h" |
||
81 | #include "pi/pi/pi.h" |
||
82 | #include "pc/pc/pc.h" |
||
83 | #include "srp/srp/srp.h" |
||
84 | #include "npp/npp/npp.h" |
||
85 | #include "nop/nop/nop.h" |
||
1120 | pj | 86 | |
1393 | giacomo | 87 | #include <drivers/shark_linuxc26.h> |
88 | #include <drivers/shark_input26.h> |
||
89 | #include <drivers/shark_keyb26.h> |
||
90 | |||
1120 | pj | 91 | /*+ sysyem tick in us +*/ |
92 | #define TICK 1000 |
||
93 | |||
94 | /*+ RR tick in us +*/ |
||
95 | #define RRTICK 10000 |
||
96 | |||
1377 | giacomo | 97 | /*+ Interrupt Server +*/ |
98 | #define INTDRIVE_Q 1000 |
||
1586 | tullio | 99 | #define INTDRIVE_U 0.1*MAX_BANDWIDTH |
1377 | giacomo | 100 | #define INTDRIVE_FLAG 0 |
101 | |||
1393 | giacomo | 102 | void call_shutdown_task(void *arg); |
103 | int device_drivers_init(); |
||
104 | int device_drivers_close(); |
||
105 | void set_shutdown_task(); |
||
106 | TASK shutdown_task_body(void *arg); |
||
107 | |||
1463 | giacomo | 108 | PID shutdown_task_PID = -1; |
1393 | giacomo | 109 | |
1120 | pj | 110 | TIME __kernel_register_levels__(void *arg) |
111 | { |
||
112 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
1586 | tullio | 113 | LEVEL EDF_level; |
1120 | pj | 114 | |
1567 | mauro | 115 | INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG); |
1586 | tullio | 116 | EDF_level = EDF_register_level(EDF_ENABLE_ALL); |
1120 | pj | 117 | RR_register_level(RRTICK, RR_MAIN_YES, mb); |
1586 | tullio | 118 | CBS_register_level(CBS_ENABLE_ALL, EDF_level); |
1377 | giacomo | 119 | PS_register_level(2 /*PS_ENABLE_ALL_EDF*/,1,500,100000); |
1120 | pj | 120 | dummy_register_level(); |
121 | |||
122 | SEM_register_module(); |
||
123 | |||
124 | CABS_register_module(); |
||
125 | |||
126 | PI_register_module(); |
||
127 | PC_register_module(); |
||
128 | NPP_register_module(); |
||
129 | SRP_register_module(); |
||
130 | NOP_register_module(); |
||
131 | |||
132 | return TICK; |
||
133 | } |
||
134 | |||
135 | TASK __init__(void *arg) |
||
136 | { |
||
137 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
138 | |||
1393 | giacomo | 139 | /* Create the shutdown task. It will be activated at RUNLEVEL |
140 | SHUTDOWN */ |
||
141 | set_shutdown_task(); |
||
142 | |||
143 | /* Init the drivers */ |
||
144 | device_drivers_init(); |
||
145 | |||
146 | /* Set the shutdown task activation */ |
||
147 | sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN); |
||
148 | |||
1120 | pj | 149 | __call_main__(mb); |
150 | |||
151 | return (void *)0; |
||
152 | } |
||
153 | |||
1393 | giacomo | 154 | void set_shutdown_task() { |
155 | |||
156 | /* WARNING: the shutdown task is a background thread. It cannot execute |
||
157 | if the system is overloaded */ |
||
158 | NRT_TASK_MODEL nrt; |
||
159 | |||
160 | nrt_task_default_model(nrt); |
||
161 | nrt_task_def_system(nrt); |
||
162 | |||
163 | shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL); |
||
164 | if (shutdown_task_PID == NIL) { |
||
165 | sys_shutdown_message("Error: Cannot create shutdown task\n"); |
||
1547 | pj | 166 | exit(1); |
1393 | giacomo | 167 | } |
168 | |||
169 | } |
||
170 | |||
171 | int device_drivers_init() { |
||
172 | |||
173 | KEYB_PARMS kparms = BASE_KEYB; |
||
174 | |||
1567 | mauro | 175 | LINUXC26_register_module(TRUE); |
1393 | giacomo | 176 | |
177 | INPUT26_init(); |
||
178 | |||
179 | keyb_def_ctrlC(kparms, NULL); |
||
180 | |||
181 | KEYB26_init(&kparms); |
||
182 | |||
183 | return 0; |
||
184 | |||
185 | } |
||
186 | |||
187 | int device_drivers_close() { |
||
188 | |||
189 | KEYB26_close(); |
||
190 | |||
191 | INPUT26_close(); |
||
192 | |||
193 | return 0; |
||
194 | |||
195 | } |
||
196 | |||
197 | #define SHUTDOWN_TIMEOUT_SEC 3 |
||
198 | |||
199 | void call_shutdown_task(void *arg) |
||
200 | { |
||
201 | struct timespec t; |
||
202 | |||
203 | sys_gettime(&t); |
||
204 | t.tv_sec += SHUTDOWN_TIMEOUT_SEC; |
||
205 | |||
206 | /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */ |
||
207 | kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0); |
||
208 | |||
209 | task_activate(shutdown_task_PID); |
||
210 | } |
||
211 | |||
212 | TASK shutdown_task_body(void *arg) { |
||
213 | |||
214 | device_drivers_close(); |
||
215 | |||
216 | sys_shutdown_message("-- S.Ha.R.K. Closed --\n"); |
||
217 | |||
218 | return NULL; |
||
219 | |||
220 | } |
||
221 | |||
222 |