Rev 1393 | Rev 1552 | 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 | ------------ |
||
1463 | giacomo | 21 | CVS : $Id: iaster6.c,v 1.4 2004-05-24 17:20:44 giacomo Exp $ |
1120 | pj | 22 | |
23 | File: $File$ |
||
1463 | giacomo | 24 | Revision: $Revision: 1.4 $ |
25 | Last update: $Date: 2004-05-24 17:20:44 $ |
||
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 | |
72 | #include "modules/intdrive.h" |
||
1120 | pj | 73 | #include "modules/edf.h" |
74 | #include "modules/cbs.h" |
||
75 | #include "modules/rr.h" |
||
76 | #include "modules/dummy.h" |
||
77 | #include "modules/ps.h" |
||
78 | |||
79 | #include "modules/sem.h" |
||
80 | #include "modules/hartport.h" |
||
81 | #include "modules/cabs.h" |
||
82 | #include "modules/pi.h" |
||
83 | #include "modules/pc.h" |
||
84 | #include "modules/srp.h" |
||
85 | #include "modules/npp.h" |
||
86 | #include "modules/nop.h" |
||
87 | |||
1393 | giacomo | 88 | #include <drivers/shark_linuxc26.h> |
89 | #include <drivers/shark_input26.h> |
||
90 | #include <drivers/shark_keyb26.h> |
||
91 | |||
1120 | pj | 92 | /*+ sysyem tick in us +*/ |
93 | #define TICK 1000 |
||
94 | |||
95 | /*+ RR tick in us +*/ |
||
96 | #define RRTICK 10000 |
||
97 | |||
1377 | giacomo | 98 | /*+ Interrupt Server +*/ |
99 | #define INTDRIVE_Q 1000 |
||
100 | #define INTDRIVE_T 10000 |
||
101 | #define INTDRIVE_FLAG 0 |
||
102 | |||
1393 | giacomo | 103 | void call_shutdown_task(void *arg); |
104 | int device_drivers_init(); |
||
105 | int device_drivers_close(); |
||
106 | void set_shutdown_task(); |
||
107 | TASK shutdown_task_body(void *arg); |
||
108 | |||
1463 | giacomo | 109 | PID shutdown_task_PID = -1; |
1393 | giacomo | 110 | |
1120 | pj | 111 | TIME __kernel_register_levels__(void *arg) |
112 | { |
||
113 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
114 | |||
1377 | giacomo | 115 | INTDRIVE_register_level(INTDRIVE_Q,INTDRIVE_T,INTDRIVE_FLAG); |
1120 | pj | 116 | EDF_register_level(EDF_ENABLE_ALL); |
117 | RR_register_level(RRTICK, RR_MAIN_YES, mb); |
||
1377 | giacomo | 118 | CBS_register_level(CBS_ENABLE_ALL, 1); |
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 | |||
139 | HARTPORT_init(); |
||
140 | |||
1393 | giacomo | 141 | /* Create the shutdown task. It will be activated at RUNLEVEL |
142 | SHUTDOWN */ |
||
143 | set_shutdown_task(); |
||
144 | |||
145 | /* Init the drivers */ |
||
146 | device_drivers_init(); |
||
147 | |||
148 | /* Set the shutdown task activation */ |
||
149 | sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN); |
||
150 | |||
1120 | pj | 151 | __call_main__(mb); |
152 | |||
153 | return (void *)0; |
||
154 | } |
||
155 | |||
1393 | giacomo | 156 | void set_shutdown_task() { |
157 | |||
158 | /* WARNING: the shutdown task is a background thread. It cannot execute |
||
159 | if the system is overloaded */ |
||
160 | NRT_TASK_MODEL nrt; |
||
161 | |||
162 | nrt_task_default_model(nrt); |
||
163 | nrt_task_def_system(nrt); |
||
164 | |||
165 | shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL); |
||
166 | if (shutdown_task_PID == NIL) { |
||
167 | sys_shutdown_message("Error: Cannot create shutdown task\n"); |
||
168 | sys_end(); |
||
169 | } |
||
170 | |||
171 | } |
||
172 | |||
173 | int device_drivers_init() { |
||
174 | |||
175 | KEYB_PARMS kparms = BASE_KEYB; |
||
176 | |||
177 | LINUXC26_register_module(); |
||
178 | |||
179 | INPUT26_init(); |
||
180 | |||
181 | keyb_def_ctrlC(kparms, NULL); |
||
182 | |||
183 | KEYB26_init(&kparms); |
||
184 | |||
185 | return 0; |
||
186 | |||
187 | } |
||
188 | |||
189 | int device_drivers_close() { |
||
190 | |||
191 | KEYB26_close(); |
||
192 | |||
193 | INPUT26_close(); |
||
194 | |||
195 | return 0; |
||
196 | |||
197 | } |
||
198 | |||
199 | #define SHUTDOWN_TIMEOUT_SEC 3 |
||
200 | |||
201 | void call_shutdown_task(void *arg) |
||
202 | { |
||
203 | struct timespec t; |
||
204 | |||
205 | sys_gettime(&t); |
||
206 | t.tv_sec += SHUTDOWN_TIMEOUT_SEC; |
||
207 | |||
208 | /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */ |
||
209 | kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0); |
||
210 | |||
211 | task_activate(shutdown_task_PID); |
||
212 | } |
||
213 | |||
214 | TASK shutdown_task_body(void *arg) { |
||
215 | |||
216 | device_drivers_close(); |
||
217 | |||
218 | sys_shutdown_message("-- S.Ha.R.K. Closed --\n"); |
||
219 | |||
220 | sys_abort_shutdown(0); |
||
221 | |||
222 | return NULL; |
||
223 | |||
224 | } |
||
225 | |||
226 |