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: iaster7.c,v 1.4 2004-05-24 17:20:45 giacomo Exp $ |
1120 | pj | 22 | |
23 | File: $File$ |
||
1463 | giacomo | 24 | Revision: $Revision: 1.4 $ |
25 | Last update: $Date: 2004-05-24 17:20:45 $ |
||
1120 | pj | 26 | ------------ |
27 | |||
28 | System initialization file |
||
29 | |||
30 | The tick is set to TICK ms. |
||
31 | |||
32 | This file contains the 2 functions needed to initialize the system. |
||
33 | |||
34 | These functions register a set of scheduling modules, in a fixed or |
||
35 | dynamic priority way... |
||
36 | |||
37 | It can accept these task models: |
||
38 | |||
39 | HARD_TASK_MODEL (wcet+mit) at level 0 |
||
40 | SOFT_TASK_MODEL (periodicity=APERIODIC) at level 1 |
||
41 | NRT_TASK_MODEL at level 2 |
||
42 | SOFT_TASK_MODEL (periodicity=APERIODIC, wcet (only if TBS) ) at level 3,4 |
||
43 | |||
44 | **/ |
||
45 | |||
46 | /* |
||
47 | * Copyright (C) 2000 Paolo Gai |
||
48 | * |
||
49 | * This program is free software; you can redistribute it and/or modify |
||
50 | * it under the terms of the GNU General Public License as published by |
||
51 | * the Free Software Foundation; either version 2 of the License, or |
||
52 | * (at your option) any later version. |
||
53 | * |
||
54 | * This program is distributed in the hope that it will be useful, |
||
55 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
56 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
57 | * GNU General Public License for more details. |
||
58 | * |
||
59 | * You should have received a copy of the GNU General Public License |
||
60 | * along with this program; if not, write to the Free Software |
||
61 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
62 | * |
||
63 | */ |
||
64 | |||
65 | |||
66 | |||
67 | #include "kernel/kern.h" |
||
1377 | giacomo | 68 | #include "modules/intdrive.h" |
1120 | pj | 69 | #include "modules/edf.h" |
70 | #include "modules/tbs.h" |
||
71 | |||
72 | #include "modules/rm.h" |
||
73 | #include "modules/rr.h" |
||
74 | #include "modules/ps.h" |
||
75 | |||
76 | #include "modules/dummy.h" |
||
77 | |||
78 | #include "modules/sem.h" |
||
79 | #include "modules/hartport.h" |
||
80 | |||
1393 | giacomo | 81 | #include <drivers/shark_linuxc26.h> |
82 | #include <drivers/shark_input26.h> |
||
83 | #include <drivers/shark_keyb26.h> |
||
84 | |||
1120 | pj | 85 | /*+ sysyem tick in us +*/ |
1377 | giacomo | 86 | #define TICK 0 |
1120 | pj | 87 | |
1377 | giacomo | 88 | #define RRTICK 10000 |
1120 | pj | 89 | |
1377 | giacomo | 90 | /*+ Interrupt Server +*/ |
91 | #define INTDRIVE_Q 1000 |
||
92 | #define INTDRIVE_T 10000 |
||
93 | #define INTDRIVE_FLAG 0 |
||
1120 | pj | 94 | |
1393 | giacomo | 95 | void call_shutdown_task(void *arg); |
96 | int device_drivers_init(); |
||
97 | int device_drivers_close(); |
||
98 | void set_shutdown_task(); |
||
99 | TASK shutdown_task_body(void *arg); |
||
100 | |||
1463 | giacomo | 101 | PID shutdown_task_PID = -1; |
1393 | giacomo | 102 | |
1120 | pj | 103 | TIME __kernel_register_levels__(void *arg) |
104 | { |
||
105 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
106 | |||
1377 | giacomo | 107 | INTDRIVE_register_level(INTDRIVE_Q,INTDRIVE_T,INTDRIVE_FLAG); |
1120 | pj | 108 | RM_register_level(RM_ENABLE_ALL); |
1377 | giacomo | 109 | PS_register_level(PS_ENABLE_ALL_RM,1,1000,100000); |
1120 | pj | 110 | RR_register_level(RRTICK, RR_MAIN_YES, mb); |
1377 | giacomo | 111 | PS_register_level(4,1,10000,100000); |
112 | PS_register_level(4,1,30000,100000); |
||
1120 | pj | 113 | |
114 | dummy_register_level(); |
||
115 | |||
116 | SEM_register_module(); |
||
117 | |||
118 | return TICK; |
||
119 | } |
||
120 | |||
121 | TASK __init__(void *arg) |
||
122 | { |
||
123 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
124 | |||
125 | HARTPORT_init(); |
||
126 | |||
1393 | giacomo | 127 | /* Create the shutdown task. It will be activated at RUNLEVEL |
128 | SHUTDOWN */ |
||
129 | set_shutdown_task(); |
||
130 | |||
131 | /* Init the drivers */ |
||
132 | device_drivers_init(); |
||
133 | |||
134 | /* Set the shutdown task activation */ |
||
135 | sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN); |
||
136 | |||
1120 | pj | 137 | __call_main__(mb); |
138 | |||
139 | return (void *)0; |
||
140 | } |
||
141 | |||
1393 | giacomo | 142 | void set_shutdown_task() { |
143 | |||
144 | /* WARNING: the shutdown task is a background thread. It cannot execute |
||
145 | if the system is overloaded */ |
||
146 | NRT_TASK_MODEL nrt; |
||
147 | |||
148 | nrt_task_default_model(nrt); |
||
149 | nrt_task_def_system(nrt); |
||
150 | |||
151 | shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL); |
||
152 | if (shutdown_task_PID == NIL) { |
||
153 | sys_shutdown_message("Error: Cannot create shutdown task\n"); |
||
154 | sys_end(); |
||
155 | } |
||
156 | |||
157 | } |
||
158 | |||
159 | int device_drivers_init() { |
||
160 | |||
161 | KEYB_PARMS kparms = BASE_KEYB; |
||
162 | |||
163 | LINUXC26_register_module(); |
||
164 | |||
165 | INPUT26_init(); |
||
166 | |||
167 | keyb_def_ctrlC(kparms, NULL); |
||
168 | |||
169 | KEYB26_init(&kparms); |
||
170 | |||
171 | return 0; |
||
172 | |||
173 | } |
||
174 | |||
175 | int device_drivers_close() { |
||
176 | |||
177 | KEYB26_close(); |
||
178 | |||
179 | INPUT26_close(); |
||
180 | |||
181 | return 0; |
||
182 | |||
183 | } |
||
184 | |||
185 | #define SHUTDOWN_TIMEOUT_SEC 3 |
||
186 | |||
187 | void call_shutdown_task(void *arg) |
||
188 | { |
||
189 | struct timespec t; |
||
190 | |||
191 | sys_gettime(&t); |
||
192 | t.tv_sec += SHUTDOWN_TIMEOUT_SEC; |
||
193 | |||
194 | /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */ |
||
195 | kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0); |
||
196 | |||
197 | task_activate(shutdown_task_PID); |
||
198 | } |
||
199 | |||
200 | TASK shutdown_task_body(void *arg) { |
||
201 | |||
202 | device_drivers_close(); |
||
203 | |||
204 | sys_shutdown_message("-- S.Ha.R.K. Closed --\n"); |
||
205 | |||
206 | sys_abort_shutdown(0); |
||
207 | |||
208 | return NULL; |
||
209 | |||
210 | } |
||
211 | |||
212 | |||
213 | |||
214 |