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