Rev 1569 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1091 | 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 : |
||
1448 | giacomo | 9 | * Giacomo Guidi <giacomo@gandalf.sssup.it> |
1569 | tullio | 10 | * Tullio Facchinetti <tullio.facchinetti@unipv.it> |
1091 | pj | 11 | * (see the web pages for full authors list) |
12 | * |
||
13 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
14 | * |
||
15 | * http://www.sssup.it |
||
16 | * http://retis.sssup.it |
||
17 | * http://shark.sssup.it |
||
18 | */ |
||
19 | |||
20 | /* |
||
21 | * This program is free software; you can redistribute it and/or modify |
||
22 | * it under the terms of the GNU General Public License as published by |
||
23 | * the Free Software Foundation; either version 2 of the License, or |
||
24 | * (at your option) any later version. |
||
25 | * |
||
26 | * This program is distributed in the hope that it will be useful, |
||
27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
29 | * GNU General Public License for more details. |
||
30 | * |
||
31 | * You should have received a copy of the GNU General Public License |
||
32 | * along with this program; if not, write to the Free Software |
||
33 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
34 | * |
||
35 | */ |
||
36 | |||
1448 | giacomo | 37 | #define PI_MUTEX |
1091 | pj | 38 | |
39 | #include "kernel/kern.h" |
||
1552 | pj | 40 | #include "intdrive/intdrive/intdrive.h" |
41 | #include "edf/edf/edf.h" |
||
42 | #include "hardcbs/hardcbs/hardcbs.h" |
||
43 | #include "rr/rr/rr.h" |
||
44 | #include "dummy/dummy/dummy.h" |
||
1448 | giacomo | 45 | |
1552 | pj | 46 | #include "sem/sem/sem.h" |
47 | #include "hartport/hartport/hartport.h" |
||
48 | #include "cabs/cabs/cabs.h" |
||
1091 | pj | 49 | |
1552 | pj | 50 | #include "pi/pi/pi.h" |
51 | #include "nop/nop/nop.h" |
||
1091 | pj | 52 | |
1448 | giacomo | 53 | #include "bca.h" |
54 | |||
55 | #include <drivers/shark_linuxc26.h> |
||
56 | #include <drivers/shark_pci26.h> |
||
57 | #include <drivers/shark_input26.h> |
||
58 | #include <drivers/shark_keyb26.h> |
||
59 | #include <drivers/shark_fb26.h> |
||
60 | |||
61 | #define FRAME_BUFFER_DEVICE 0 |
||
62 | |||
63 | /*+ sysyem tick in us +*/ |
||
64 | #define TICK 0 |
||
65 | |||
1091 | pj | 66 | /*+ RR tick in us +*/ |
1448 | giacomo | 67 | #define RRTICK 2000 |
1091 | pj | 68 | |
1448 | giacomo | 69 | /*+ Interrupt Server +*/ |
70 | #define INTDRIVE_Q 1000 |
||
1569 | tullio | 71 | #define INTDRIVE_U 0.1*MAX_BANDWIDTH |
1448 | giacomo | 72 | #define INTDRIVE_FLAG 0 |
73 | |||
74 | void call_shutdown_task(void *arg); |
||
75 | int device_drivers_init(); |
||
76 | int device_drivers_close(); |
||
77 | void set_shutdown_task(); |
||
78 | TASK shutdown_task_body(void *arg); |
||
79 | |||
80 | PID shutdown_task_PID = -1; |
||
81 | |||
1091 | pj | 82 | TIME __kernel_register_levels__(void *arg) |
83 | { |
||
84 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
1569 | tullio | 85 | LEVEL EDF_level; |
1091 | pj | 86 | |
1567 | mauro | 87 | INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG); |
1569 | tullio | 88 | EDF_level = EDF_register_level(EDF_ENABLE_ALL); |
89 | HCBS_register_level(HCBS_ENABLE_ALL, EDF_level); |
||
1091 | pj | 90 | RR_register_level(RRTICK, RR_MAIN_YES, mb); |
91 | dummy_register_level(); |
||
92 | |||
93 | SEM_register_module(); |
||
94 | CABS_register_module(); |
||
1448 | giacomo | 95 | |
1091 | pj | 96 | PI_register_module(); |
97 | NOP_register_module(); |
||
98 | |||
99 | kern_init_bca(); |
||
100 | |||
101 | return TICK; |
||
102 | } |
||
103 | |||
104 | TASK __init__(void *arg) |
||
105 | { |
||
106 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
107 | |||
108 | HARTPORT_init(); |
||
109 | |||
1448 | giacomo | 110 | /* Create the shutdown task. It will be activated at RUNLEVEL |
111 | SHUTDOWN */ |
||
112 | set_shutdown_task(); |
||
1091 | pj | 113 | |
1448 | giacomo | 114 | /* Init the drivers */ |
115 | device_drivers_init(); |
||
116 | |||
117 | /* Set the shutdown task activation */ |
||
118 | sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN); |
||
119 | |||
1091 | pj | 120 | __call_main__(mb); |
121 | |||
122 | return (void *)0; |
||
123 | } |
||
124 | |||
1448 | giacomo | 125 | #ifdef PI_MUTEX |
1091 | pj | 126 | int app_mutex_init(mutex_t *m) |
127 | { |
||
128 | PI_mutexattr_t attr; |
||
1448 | giacomo | 129 | |
1091 | pj | 130 | PI_mutexattr_default(attr); |
1448 | giacomo | 131 | |
1091 | pj | 132 | return mutex_init(m, &attr); |
133 | } |
||
134 | #else |
||
135 | int app_mutex_init(mutex_t *m) |
||
136 | { |
||
137 | NOP_mutexattr_t attr; |
||
1448 | giacomo | 138 | |
1091 | pj | 139 | NOP_mutexattr_default(attr); |
1448 | giacomo | 140 | |
1091 | pj | 141 | return mutex_init(m, &attr); |
142 | } |
||
143 | #endif |
||
144 | |||
1448 | giacomo | 145 | void set_shutdown_task() { |
146 | |||
147 | /* WARNING: the shutdown task is a background thread. It cannot execute |
||
148 | if the system is overloaded */ |
||
149 | NRT_TASK_MODEL nrt; |
||
150 | |||
151 | nrt_task_default_model(nrt); |
||
152 | nrt_task_def_system(nrt); |
||
153 | |||
154 | shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL); |
||
155 | if (shutdown_task_PID == NIL) { |
||
156 | sys_shutdown_message("Error: Cannot create shutdown task\n"); |
||
1550 | pj | 157 | exit(1); |
1448 | giacomo | 158 | } |
159 | |||
160 | } |
||
161 | |||
162 | int device_drivers_init() { |
||
163 | |||
164 | int res; |
||
165 | KEYB_PARMS kparms = BASE_KEYB; |
||
166 | |||
1567 | mauro | 167 | LINUXC26_register_module(TRUE); |
1448 | giacomo | 168 | |
169 | PCI26_init(); |
||
170 | |||
171 | INPUT26_init(); |
||
172 | |||
173 | keyb_def_ctrlC(kparms, NULL); |
||
174 | |||
175 | KEYB26_init(&kparms); |
||
176 | |||
177 | FB26_init(); |
||
178 | |||
179 | res = FB26_open(FRAME_BUFFER_DEVICE); |
||
180 | if (res) { |
||
181 | cprintf("Error: Cannot open graphical mode\n"); |
||
182 | KEYB26_close(); |
||
183 | INPUT26_close(); |
||
1550 | pj | 184 | exit(1); |
1448 | giacomo | 185 | } |
186 | |||
187 | FB26_use_grx(FRAME_BUFFER_DEVICE); |
||
188 | |||
189 | FB26_setmode(FRAME_BUFFER_DEVICE,"800x600-16"); |
||
190 | |||
191 | return 0; |
||
192 | |||
193 | } |
||
194 | |||
195 | int device_drivers_close() { |
||
196 | |||
197 | FB26_close(FRAME_BUFFER_DEVICE); |
||
198 | |||
199 | KEYB26_close(); |
||
200 | |||
201 | INPUT26_close(); |
||
202 | |||
203 | return 0; |
||
204 | |||
205 | } |
||
206 | |||
207 | #define SHUTDOWN_TIMEOUT_SEC 3 |
||
208 | |||
209 | void call_shutdown_task(void *arg) |
||
210 | { |
||
211 | struct timespec t; |
||
212 | |||
213 | sys_gettime(&t); |
||
214 | t.tv_sec += SHUTDOWN_TIMEOUT_SEC; |
||
215 | |||
216 | /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */ |
||
217 | kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0); |
||
218 | |||
219 | task_activate(shutdown_task_PID); |
||
220 | } |
||
221 | |||
222 | TASK shutdown_task_body(void *arg) { |
||
223 | |||
224 | device_drivers_close(); |
||
225 | |||
226 | sys_shutdown_message("-- S.Ha.R.K. Closed --\n"); |
||
227 | |||
228 | return NULL; |
||
229 | |||
230 | } |