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