Rev 1483 | Rev 1525 | Go to most recent revision | 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> |
||
1512 | giacomo | 10 | * Mauro Marinoni |
1151 | giacomo | 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 | #include "kernel/kern.h" |
||
1360 | giacomo | 37 | #include "modules/intdrive.h" |
1151 | giacomo | 38 | #include "modules/edf.h" |
1360 | giacomo | 39 | #include "modules/hardcbs.h" |
1151 | giacomo | 40 | #include "modules/rr.h" |
41 | #include "modules/dummy.h" |
||
42 | |||
43 | #include "modules/sem.h" |
||
44 | #include "modules/hartport.h" |
||
45 | #include "modules/cabs.h" |
||
46 | |||
1360 | giacomo | 47 | #include "drivers/shark_linuxc26.h" |
48 | #include "drivers/shark_input26.h" |
||
49 | #include "drivers/shark_keyb26.h" |
||
1512 | giacomo | 50 | #include "drivers/shark_cpu26.h" |
1151 | giacomo | 51 | |
52 | /*+ sysyem tick in us +*/ |
||
1483 | giacomo | 53 | #define TICK 0 |
1151 | giacomo | 54 | |
55 | /*+ RR tick in us +*/ |
||
56 | #define RRTICK 10000 |
||
57 | |||
1360 | giacomo | 58 | /*+ IntDrive Server +*/ |
59 | #define INTDRIVE_Q 1000 |
||
60 | #define INTDRIVE_T 10000 |
||
61 | #define INTDRIVE_FLAGS 0 |
||
62 | |||
1394 | giacomo | 63 | void call_shutdown_task(void *arg); |
64 | int device_drivers_init(); |
||
65 | int device_drivers_close(); |
||
66 | void set_shutdown_task(); |
||
67 | TASK shutdown_task_body(void *arg); |
||
68 | |||
69 | PID shutdown_task_PID = -1; |
||
70 | |||
1151 | giacomo | 71 | TIME __kernel_register_levels__(void *arg) |
72 | { |
||
73 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
74 | |||
1360 | giacomo | 75 | INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_T, INTDRIVE_FLAGS); |
1151 | giacomo | 76 | EDF_register_level(EDF_ENABLE_ALL); |
1360 | giacomo | 77 | HCBS_register_level(HCBS_ENABLE_ALL, 1); |
1151 | giacomo | 78 | RR_register_level(RRTICK, RR_MAIN_YES, mb); |
79 | dummy_register_level(); |
||
80 | |||
81 | SEM_register_module(); |
||
82 | |||
83 | CABS_register_module(); |
||
84 | |||
85 | return TICK; |
||
86 | } |
||
87 | |||
88 | TASK __init__(void *arg) |
||
89 | { |
||
90 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
91 | |||
92 | HARTPORT_init(); |
||
93 | |||
1394 | giacomo | 94 | /* Create the shutdown task. It will be activated at RUNLEVEL |
95 | SHUTDOWN */ |
||
96 | set_shutdown_task(); |
||
97 | |||
98 | /* Init the drivers */ |
||
99 | device_drivers_init(); |
||
100 | |||
101 | /* Set the shutdown task activation */ |
||
102 | sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN); |
||
1429 | mauro | 103 | |
1431 | mauro | 104 | //sys_set_reboot(EXIT_MODE_HALT); |
1394 | giacomo | 105 | |
1151 | giacomo | 106 | __call_main__(mb); |
107 | |||
1394 | giacomo | 108 | return (void *)0; |
109 | } |
||
110 | |||
111 | void set_shutdown_task() { |
||
112 | |||
113 | /* WARNING: the shutdown task is a background thread. It cannot execute |
||
114 | if the system is overloaded */ |
||
115 | NRT_TASK_MODEL nrt; |
||
116 | |||
117 | nrt_task_default_model(nrt); |
||
118 | nrt_task_def_system(nrt); |
||
119 | |||
120 | shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL); |
||
121 | if (shutdown_task_PID == NIL) { |
||
122 | sys_shutdown_message("Error: Cannot create shutdown task\n"); |
||
123 | sys_end(); |
||
124 | } |
||
125 | |||
126 | } |
||
127 | |||
128 | int device_drivers_init() { |
||
129 | |||
130 | KEYB_PARMS kparms = BASE_KEYB; |
||
131 | |||
132 | LINUXC26_register_module(); |
||
133 | |||
1512 | giacomo | 134 | CPU26_init(); |
135 | |||
136 | CPU26_DVS_init(); |
||
137 | |||
1394 | giacomo | 138 | INPUT26_init(); |
139 | |||
140 | keyb_def_ctrlC(kparms, NULL); |
||
141 | |||
142 | KEYB26_init(&kparms); |
||
143 | |||
144 | return 0; |
||
145 | |||
146 | } |
||
147 | |||
148 | int device_drivers_close() { |
||
149 | |||
150 | KEYB26_close(); |
||
151 | |||
152 | INPUT26_close(); |
||
153 | |||
154 | return 0; |
||
155 | |||
156 | } |
||
157 | |||
158 | #define SHUTDOWN_TIMEOUT_SEC 3 |
||
159 | |||
160 | void call_shutdown_task(void *arg) |
||
161 | { |
||
162 | struct timespec t; |
||
163 | |||
164 | sys_gettime(&t); |
||
165 | t.tv_sec += SHUTDOWN_TIMEOUT_SEC; |
||
166 | |||
167 | /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */ |
||
168 | kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0); |
||
169 | |||
170 | task_activate(shutdown_task_PID); |
||
171 | } |
||
172 | |||
173 | TASK shutdown_task_body(void *arg) { |
||
174 | |||
175 | device_drivers_close(); |
||
176 | |||
177 | sys_shutdown_message("-- S.Ha.R.K. Closed --\n"); |
||
178 | |||
179 | sys_abort_shutdown(0); |
||
180 | |||
1360 | giacomo | 181 | return NULL; |
1394 | giacomo | 182 | |
1151 | giacomo | 183 | } |
184 |