Rev 1381 | Rev 1550 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1158 | 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 | ------------ |
||
1384 | giacomo | 21 | CVS : $Id: ecp.c,v 1.5 2004-04-19 13:45:15 giacomo Exp $ |
1158 | pj | 22 | |
23 | File: $File$ |
||
1384 | giacomo | 24 | Revision: $Revision: 1.5 $ |
25 | Last update: $Date: 2004-04-19 13:45:15 $ |
||
1158 | pj | 26 | ------------ |
27 | **/ |
||
28 | |||
29 | /* |
||
30 | * Copyright (C) 2003 Paolo Gai |
||
31 | * |
||
32 | * This program is free software; you can redistribute it and/or modify |
||
33 | * it under the terms of the GNU General Public License as published by |
||
34 | * the Free Software Foundation; either version 2 of the License, or |
||
35 | * (at your option) any later version. |
||
36 | * |
||
37 | * This program is distributed in the hope that it will be useful, |
||
38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
40 | * GNU General Public License for more details. |
||
41 | * |
||
42 | * You should have received a copy of the GNU General Public License |
||
43 | * along with this program; if not, write to the Free Software |
||
44 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
45 | * |
||
46 | */ |
||
47 | |||
48 | #include "kernel/kern.h" |
||
1379 | giacomo | 49 | #include "modules/intdrive.h" |
1158 | pj | 50 | #include "modules/edf.h" |
51 | #include "modules/cbs.h" |
||
52 | #include "modules/rr.h" |
||
53 | #include "modules/dummy.h" |
||
54 | |||
55 | #include "modules/sem.h" |
||
56 | #include "modules/hartport.h" |
||
57 | #include "modules/cabs.h" |
||
58 | |||
1380 | giacomo | 59 | #include "modules/pi.h" |
60 | |||
1381 | giacomo | 61 | #include <drivers/shark_linuxc26.h> |
62 | #include <drivers/shark_pci26.h> |
||
63 | #include <drivers/shark_input26.h> |
||
64 | #include <drivers/shark_keyb26.h> |
||
65 | #include <drivers/shark_fb26.h> |
||
66 | |||
67 | #define FRAME_BUFFER_DEVICE 0 |
||
68 | |||
1158 | pj | 69 | /*+ sysyem tick in us +*/ |
70 | #define TICK 0 |
||
71 | |||
72 | /*+ RR tick in us +*/ |
||
73 | #define RRTICK 2000 |
||
74 | |||
1379 | giacomo | 75 | /*+ Interrupt Server +*/ |
76 | #define INTDRIVE_Q 1000 |
||
77 | #define INTDRIVE_T 10000 |
||
78 | #define INTDRIVE_FLAG 0 |
||
79 | |||
1384 | giacomo | 80 | void call_shutdown_task(void *arg); |
81 | int device_drivers_init(); |
||
82 | int device_drivers_close(); |
||
83 | void set_shutdown_task(); |
||
84 | TASK shutdown_task_body(void *arg); |
||
85 | |||
1381 | giacomo | 86 | PID shutdown_task_PID = -1; |
87 | |||
1158 | pj | 88 | TIME __kernel_register_levels__(void *arg) |
89 | { |
||
90 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
91 | |||
1379 | giacomo | 92 | INTDRIVE_register_level(INTDRIVE_Q,INTDRIVE_T,INTDRIVE_FLAG); |
1158 | pj | 93 | EDF_register_level(EDF_ENABLE_ALL); |
1379 | giacomo | 94 | CBS_register_level(CBS_ENABLE_ALL, 1); |
1158 | pj | 95 | RR_register_level(RRTICK, RR_MAIN_YES, mb); |
96 | dummy_register_level(); |
||
97 | |||
98 | SEM_register_module(); |
||
99 | CABS_register_module(); |
||
1380 | giacomo | 100 | PI_register_module(); |
1158 | pj | 101 | |
102 | return TICK; |
||
103 | } |
||
104 | |||
1384 | giacomo | 105 | TASK __init__(void *arg) |
106 | { |
||
107 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
108 | |||
109 | HARTPORT_init(); |
||
110 | |||
111 | set_shutdown_task(); |
||
112 | |||
113 | device_drivers_init(); |
||
114 | |||
115 | sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN); |
||
116 | |||
117 | __call_main__(mb); |
||
118 | |||
119 | return (void *)0; |
||
1381 | giacomo | 120 | } |
121 | |||
1384 | giacomo | 122 | void set_shutdown_task() { |
123 | |||
124 | NRT_TASK_MODEL nrt; |
||
125 | |||
126 | nrt_task_default_model(nrt); |
||
127 | nrt_task_def_system(nrt); |
||
128 | |||
129 | shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL); |
||
130 | if (shutdown_task_PID == NIL) { |
||
131 | sys_shutdown_message("Error: Cannot create shutdown task\n"); |
||
132 | sys_end(); |
||
133 | } |
||
134 | |||
135 | } |
||
136 | |||
1381 | giacomo | 137 | int device_drivers_init() { |
138 | |||
139 | int res; |
||
140 | KEYB_PARMS kparms = BASE_KEYB; |
||
141 | |||
142 | LINUXC26_register_module(); |
||
143 | |||
144 | PCI26_init(); |
||
145 | |||
146 | INPUT26_init(); |
||
147 | |||
148 | keyb_def_ctrlC(kparms, NULL); |
||
149 | |||
150 | KEYB26_init(&kparms); |
||
151 | |||
152 | FB26_init(); |
||
153 | |||
154 | res = FB26_open(FRAME_BUFFER_DEVICE); |
||
155 | if (res) { |
||
156 | cprintf("Error: Cannot open graphical mode\n"); |
||
157 | KEYB26_close(); |
||
158 | INPUT26_close(); |
||
159 | sys_end(); |
||
160 | } |
||
161 | |||
162 | FB26_use_grx(FRAME_BUFFER_DEVICE); |
||
163 | |||
164 | FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16"); |
||
165 | |||
166 | return 0; |
||
167 | |||
168 | } |
||
169 | |||
1384 | giacomo | 170 | int device_drivers_close() { |
171 | |||
172 | FB26_close(FRAME_BUFFER_DEVICE); |
||
173 | |||
174 | KEYB26_close(); |
||
175 | |||
176 | INPUT26_close(); |
||
177 | |||
178 | return 0; |
||
179 | |||
1381 | giacomo | 180 | } |
181 | |||
1384 | giacomo | 182 | #define SHUTDOWN_TIMEOUT_SEC 3 |
1381 | giacomo | 183 | |
1384 | giacomo | 184 | void call_shutdown_task(void *arg) |
185 | { |
||
186 | struct timespec t; |
||
1381 | giacomo | 187 | |
1384 | giacomo | 188 | sys_gettime(&t); |
189 | t.tv_sec += SHUTDOWN_TIMEOUT_SEC; |
||
1381 | giacomo | 190 | |
1384 | giacomo | 191 | /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */ |
192 | kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0); |
||
1381 | giacomo | 193 | |
194 | task_activate(shutdown_task_PID); |
||
195 | } |
||
196 | |||
1384 | giacomo | 197 | TASK shutdown_task_body(void *arg) { |
1158 | pj | 198 | |
1384 | giacomo | 199 | device_drivers_close(); |
1158 | pj | 200 | |
1384 | giacomo | 201 | sys_shutdown_message("-- S.Ha.R.K. Closed --\n"); |
1381 | giacomo | 202 | |
1384 | giacomo | 203 | sys_abort_shutdown(0); |
1381 | giacomo | 204 | |
1384 | giacomo | 205 | return NULL; |
1381 | giacomo | 206 | |
1158 | pj | 207 | } |
1380 | giacomo | 208 | |
209 | void app_mutex_init(mutex_t *m) |
||
210 | { |
||
211 | PI_mutexattr_t attr; |
||
212 | |||
213 | PI_mutexattr_default(attr); |
||
214 | |||
215 | mutex_init(m, &attr); |
||
216 | } |