Rev 1123 | Rev 1382 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1085 | 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 | ------------ |
||
1377 | giacomo | 21 | CVS : $Id: ego.c,v 1.4 2004-04-17 11:36:13 giacomo Exp $ |
1085 | pj | 22 | |
23 | File: $File$ |
||
1377 | giacomo | 24 | Revision: $Revision: 1.4 $ |
25 | Last update: $Date: 2004-04-17 11:36:13 $ |
||
1085 | pj | 26 | ------------ |
27 | **/ |
||
28 | |||
29 | /* |
||
30 | * Copyright (C) 2000 Paolo Gai and Giorgio Buttazzo |
||
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 | /****************************************************************/ |
||
49 | /* PERIODIC PROCESS TEST */ |
||
50 | /****************************************************************/ |
||
51 | |||
52 | #include <kernel/kern.h> |
||
53 | |||
1377 | giacomo | 54 | #include <drivers/shark_linuxc26.h> |
55 | #include <drivers/shark_pci26.h> |
||
56 | #include <drivers/shark_fb26.h> |
||
57 | #include <drivers/shark_input26.h> |
||
58 | #include <drivers/shark_keyb26.h> |
||
1085 | pj | 59 | |
1377 | giacomo | 60 | #define FRAME_BUFFER_DEVICE 0 |
61 | |||
1085 | pj | 62 | #define X0 10 |
63 | |||
64 | /* task periods */ |
||
65 | #define PERIOD_T1 100000 |
||
66 | #define PERIOD_T2 200000 |
||
67 | #define PERIOD_T3 300000 |
||
68 | |||
69 | /* X position of the text printed by each task */ |
||
70 | int y[3] = {100, 180, 260}; |
||
71 | |||
72 | /* text printed by each task */ |
||
73 | char talk[3][50] = { "I am ego1 and I print a character every 100 ms", |
||
74 | "I am ego2 and I print a character every 200 ms", |
||
75 | "I am ego3 and I print a character every 300 ms"}; |
||
76 | |||
1377 | giacomo | 77 | PID shutdown_task_PID = -1; |
1085 | pj | 78 | |
79 | /***************************************************************/ |
||
80 | |||
1377 | giacomo | 81 | int device_drivers_init() { |
82 | |||
83 | KEYB_PARMS kparms = BASE_KEYB; |
||
84 | |||
85 | LINUXC26_register_module(); |
||
86 | |||
87 | PCI26_init(); |
||
88 | |||
89 | keyb_def_ctrlC(kparms, NULL); |
||
90 | |||
91 | INPUT26_init(); |
||
92 | |||
93 | KEYB26_init(&kparms); |
||
94 | |||
95 | FB26_init(); |
||
96 | |||
97 | FB26_open(FRAME_BUFFER_DEVICE); |
||
98 | |||
99 | FB26_use_grx(FRAME_BUFFER_DEVICE); |
||
100 | |||
101 | FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16"); |
||
102 | |||
103 | return 0; |
||
104 | |||
105 | } |
||
106 | |||
107 | int device_drivers_close() { |
||
108 | |||
109 | FB26_close(FRAME_BUFFER_DEVICE); |
||
110 | |||
111 | KEYB26_close(); |
||
112 | |||
113 | INPUT26_close(); |
||
114 | |||
115 | return 0; |
||
116 | |||
117 | } |
||
118 | |||
119 | TASK shutdown_task_body(void *arg) { |
||
120 | |||
121 | device_drivers_close(); |
||
122 | |||
123 | sys_shutdown_message("-- S.Ha.R.K. Closed --\n"); |
||
124 | |||
125 | sys_end(); |
||
126 | |||
127 | return NULL; |
||
128 | |||
129 | } |
||
130 | |||
131 | void set_shutdown_task() { |
||
132 | |||
133 | NRT_TASK_MODEL nrt; |
||
134 | |||
135 | nrt_task_default_model(nrt); |
||
136 | |||
137 | shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL); |
||
138 | if (shutdown_task_PID == NIL) { |
||
139 | sys_shutdown_message("Error: Cannot create shutdown task\n"); |
||
140 | sys_end(); |
||
141 | } |
||
142 | |||
143 | } |
||
144 | |||
1085 | pj | 145 | TASK ego(void *arg) |
146 | { |
||
147 | int i = (int)arg; |
||
148 | int leng; |
||
149 | char s[2]; |
||
150 | int x; |
||
151 | int j = 0; |
||
152 | |||
153 | /* compute the length of the string to print */ |
||
154 | leng = 0; |
||
155 | while (talk[i][leng] != 0) leng++; |
||
156 | |||
157 | x = X0; |
||
158 | s[1] = 0; |
||
159 | task_endcycle(); |
||
160 | |||
161 | while (1) { |
||
162 | s[0] = talk[i][j]; |
||
163 | grx_text(s,x,y[i],12+i,0); |
||
164 | x += 8; |
||
165 | if (++j == leng) { |
||
166 | j = 0; |
||
167 | x = X0; |
||
168 | y[i] += 8; |
||
169 | if (y[i]>340) y[i]=100; |
||
170 | } |
||
171 | task_endcycle(); |
||
172 | } |
||
173 | } |
||
174 | |||
175 | |||
176 | /****************************************************************/ |
||
177 | |||
178 | /* This function is called when Alt-X is pressed. |
||
179 | */ |
||
180 | void my_end(KEY_EVT* e) |
||
181 | { |
||
1377 | giacomo | 182 | task_activate(shutdown_task_PID); |
1085 | pj | 183 | } |
184 | |||
185 | /******************************************************************/ |
||
186 | |||
187 | /* This function is called when the system exit correctly after Alt-X. |
||
188 | It exits from the graphic mode and then it prints a small greeting. |
||
189 | Note that: |
||
190 | - The function calls grx_exit, so it must be registered using |
||
191 | RUNLEVEL_BEFORE_EXIT (RUNLEVEL_AFTER_EXIT does not work because |
||
192 | at that point the kernel is already returned in real mode!!!) |
||
193 | - When an exception is raised, the exception handler is called. |
||
194 | Since the exception handler already exits from the graphic mode, |
||
195 | this funcion has not to be called. For this reason: |
||
196 | . we registered byebye using the flag NO_AT_ABORT |
||
197 | . the exception handler exits using sys_abort; in that way byebye is |
||
198 | NOT called |
||
199 | */ |
||
200 | |||
201 | /****************************** MAIN ******************************/ |
||
202 | |||
203 | int main(int argc, char **argv) |
||
204 | { |
||
205 | PID pid1, pid2, pid3; |
||
206 | KEY_EVT emerg; |
||
207 | HARD_TASK_MODEL m1, m2, m3; |
||
208 | |||
1377 | giacomo | 209 | set_shutdown_task(); |
1085 | pj | 210 | |
1377 | giacomo | 211 | device_drivers_init(); |
1085 | pj | 212 | |
213 | /* set the keyboard handler to exit correctly */ |
||
214 | emerg.ascii = 'x'; |
||
215 | emerg.scan = KEY_X; |
||
216 | emerg.flag = ALTL_BIT; |
||
1377 | giacomo | 217 | emerg.status = KEY_PRESSED; |
218 | keyb_hook(emerg,my_end,FALSE); |
||
1085 | pj | 219 | |
220 | /* a small banner */ |
||
221 | grx_text("EGO Test",8,8,WHITE,0); |
||
222 | grx_text("Press Alt-X to exit",8,16,WHITE,0); |
||
223 | |||
224 | /* ego1 creation */ |
||
225 | hard_task_default_model(m1); |
||
226 | hard_task_def_ctrl_jet (m1); |
||
227 | hard_task_def_arg (m1, (void *)0); |
||
228 | hard_task_def_wcet (m1, 5000); |
||
229 | hard_task_def_mit (m1, PERIOD_T1); |
||
230 | hard_task_def_group (m1,1); |
||
231 | pid1 = task_create("ego1", ego, &m1, NULL); |
||
232 | if (pid1 == NIL) { |
||
1377 | giacomo | 233 | sys_shutdown_message("Could not create task <ego1>"); |
234 | task_activate(shutdown_task_PID); |
||
235 | return 0; |
||
1085 | pj | 236 | } |
237 | |||
238 | /* ego2 creation */ |
||
239 | hard_task_default_model(m2); |
||
240 | hard_task_def_ctrl_jet (m2); |
||
241 | hard_task_def_arg (m2, (void *)1); |
||
242 | hard_task_def_wcet (m2, 5000); |
||
243 | hard_task_def_mit (m2, PERIOD_T2); |
||
244 | hard_task_def_group (m2,1); |
||
245 | pid2 = task_create("ego2", ego, &m2, NULL); |
||
246 | if (pid2 == NIL) { |
||
1377 | giacomo | 247 | sys_shutdown_message("Could not create task <ego2>"); |
248 | task_activate(shutdown_task_PID); |
||
249 | return 0; |
||
1085 | pj | 250 | } |
251 | |||
252 | /* ego3 creation */ |
||
253 | hard_task_default_model(m3); |
||
254 | hard_task_def_ctrl_jet (m3); |
||
255 | hard_task_def_arg (m3, (void *)2); |
||
256 | hard_task_def_wcet (m3, 5000); |
||
257 | hard_task_def_mit (m3, PERIOD_T3); |
||
258 | hard_task_def_group (m3,1); |
||
259 | pid3 = task_create("ego3", ego, &m3, NULL); |
||
260 | if (pid3 == NIL) { |
||
1377 | giacomo | 261 | sys_shutdown_message("Could not create task <ego3>"); |
262 | task_activate(shutdown_task_PID); |
||
263 | return 0; |
||
1085 | pj | 264 | } |
265 | |||
266 | /* and finally we activate the three threads... */ |
||
267 | group_activate(1); |
||
268 | |||
269 | /* |
||
270 | now the task main ends, but the system does not shutdown because |
||
271 | there are the three task ego1, ego2, and ego3 running. |
||
272 | |||
273 | The demo will finish if a Alt-X key is pressed. |
||
274 | */ |
||
275 | |||
276 | return 0; |
||
277 | } |
||
278 | |||
279 | /****************************************************************/ |