Rev 1123 | Rev 1382 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1098 | 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 | * Copyright (C) 2000 Giorgio Buttazzo, Paolo Gai |
||
21 | * |
||
22 | * This program is free software; you can redistribute it and/or modify |
||
23 | * it under the terms of the GNU General Public License as published by |
||
24 | * the Free Software Foundation; either version 2 of the License, or |
||
25 | * (at your option) any later version. |
||
26 | * |
||
27 | * This program is distributed in the hope that it will be useful, |
||
28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
30 | * GNU General Public License for more details. |
||
31 | * |
||
32 | * You should have received a copy of the GNU General Public License |
||
33 | * along with this program; if not, write to the Free Software |
||
34 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
35 | * |
||
36 | * |
||
1377 | giacomo | 37 | * CVS : $Id: cabs.c,v 1.4 2004-04-17 11:36:13 giacomo Exp $ |
1098 | pj | 38 | */ |
39 | |||
1085 | pj | 40 | /*--------------------------------------------------------------*/ |
41 | /* TEST ON CABS */ |
||
42 | /*--------------------------------------------------------------*/ |
||
43 | |||
44 | #include <kernel/kern.h> |
||
45 | #include <modules/cabs.h> |
||
46 | #include <string.h> |
||
47 | |||
1377 | giacomo | 48 | #include <drivers/shark_linuxc26.h> |
49 | #include <drivers/shark_pci26.h> |
||
50 | #include <drivers/shark_fb26.h> |
||
51 | #include <drivers/shark_input26.h> |
||
52 | #include <drivers/shark_keyb26.h> |
||
53 | |||
54 | #define FRAME_BUFFER_DEVICE 0 |
||
55 | |||
1085 | pj | 56 | #define NCAB 4 /* max number of CABs */ |
57 | #define NCAR 26 /* generated characters */ |
||
58 | |||
59 | #define YP 32 /* level of arrows */ |
||
60 | #define R 20 /* task radius */ |
||
61 | #define YY (YP+R+32) /* level of writing */ |
||
62 | #define DELTA (2*R+72) /* total channel hight */ |
||
63 | #define X1 120 /* start column for P1 */ |
||
64 | #define X2 360 /* start column for P2 */ |
||
65 | |||
66 | #define XP1 (X1+64) /* X position of task 1 */ |
||
67 | #define XP2 (X2+64) /* X position of task 2 */ |
||
68 | #define XC (XP1+96) /* X position of CAB */ |
||
69 | #define L 52 /* CAB rectangle length */ |
||
70 | |||
71 | void my_exit(KEY_EVT *k); |
||
72 | void draw_channel(int i); |
||
73 | void create_channel(int i); |
||
74 | void get_data(); |
||
75 | |||
76 | TASK producer(void *arg); |
||
77 | TASK consumer(void *arg); |
||
78 | |||
79 | char *cname[NCAB] = {"cab1", "cab2", "cab3", "cab4"}; |
||
80 | char *pname1[NCAB] = {"wr1", "wr2", "wr3", "wr4"}; |
||
81 | char *pname2[NCAB] = {"rd1", "rd2", "rd3", "rd4"}; |
||
82 | |||
83 | CAB cid[NCAB]; /* CAB identifiers */ |
||
84 | PID p1[NCAB], p2[NCAB]; /* task identifiers */ |
||
85 | |||
86 | /* Task Periods */ |
||
87 | TIME t1[NCAB] = {200000, 100000, 300000, 800000}; |
||
88 | TIME t2[NCAB] = {400000, 400000, 150000, 200000}; |
||
89 | |||
90 | /* Task WCETS */ |
||
91 | TIME w1[NCAB] = {10000, 10000, 10000, 10000}; |
||
92 | TIME w2[NCAB] = {10000, 10000, 10000, 10000}; |
||
93 | |||
1377 | giacomo | 94 | PID shutdown_task_PID = -1; |
1085 | pj | 95 | |
1377 | giacomo | 96 | int device_drivers_init() { |
97 | |||
98 | KEYB_PARMS kparms = BASE_KEYB; |
||
99 | |||
100 | LINUXC26_register_module(); |
||
101 | |||
102 | PCI26_init(); |
||
103 | |||
104 | keyb_def_ctrlC(kparms, NULL); |
||
105 | |||
106 | INPUT26_init(); |
||
107 | |||
108 | KEYB26_init(&kparms); |
||
109 | |||
110 | FB26_init(); |
||
111 | |||
112 | FB26_open(FRAME_BUFFER_DEVICE); |
||
113 | |||
114 | FB26_use_grx(FRAME_BUFFER_DEVICE); |
||
115 | |||
116 | FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16"); |
||
117 | |||
118 | return 0; |
||
119 | |||
120 | } |
||
121 | |||
122 | int device_drivers_close() { |
||
123 | |||
124 | FB26_close(FRAME_BUFFER_DEVICE); |
||
125 | |||
126 | KEYB26_close(); |
||
127 | |||
128 | INPUT26_close(); |
||
129 | |||
130 | return 0; |
||
131 | |||
132 | } |
||
133 | |||
134 | TASK shutdown_task_body(void *arg) { |
||
135 | |||
136 | device_drivers_close(); |
||
137 | |||
138 | sys_shutdown_message("-- S.Ha.R.K. Closed --\n"); |
||
139 | |||
140 | sys_end(); |
||
141 | |||
142 | return NULL; |
||
143 | |||
144 | } |
||
145 | |||
146 | void set_shutdown_task() { |
||
147 | |||
148 | NRT_TASK_MODEL nrt; |
||
149 | |||
150 | nrt_task_default_model(nrt); |
||
151 | |||
152 | shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL); |
||
153 | if (shutdown_task_PID == NIL) { |
||
154 | sys_shutdown_message("Error: Cannot create shutdown task\n"); |
||
155 | sys_end(); |
||
156 | } |
||
157 | |||
158 | } |
||
159 | |||
160 | |||
1085 | pj | 161 | /****************************************************************/ |
162 | |||
163 | /* This function is called when Alt-X is pressed. |
||
164 | */ |
||
165 | void my_end(KEY_EVT* e) |
||
166 | { |
||
1377 | giacomo | 167 | task_activate(shutdown_task_PID); |
1085 | pj | 168 | } |
169 | |||
170 | /******************************************************************/ |
||
171 | |||
172 | /* This function is called when the system exit correctly after Alt-X. |
||
173 | It exits from the graphic mode and then it prints a small greeting. |
||
174 | Note that: |
||
175 | - The function calls grx_exit, so it must be registered using |
||
176 | RUNLEVEL_BEFORE_EXIT (RUNLEVEL_AFTER_EXIT does not work because |
||
177 | at that point the kernel is already returned in real mode!!!) |
||
178 | - When an exception is raised, the exception handler is called. |
||
179 | Since the exception handler already exits from the graphic mode, |
||
180 | this funcion has not to be called. For this reason: |
||
181 | . we registered byebye using the flag NO_AT_ABORT |
||
182 | . the exception handler exits using sys_abort; in that way byebye is |
||
183 | NOT called |
||
184 | */ |
||
185 | |||
186 | /*--------------------------------------------------------------*/ |
||
187 | /* Main task */ |
||
188 | /*--------------------------------------------------------------*/ |
||
189 | |||
190 | /****************************** MAIN ******************************/ |
||
191 | |||
192 | int main(int argc, char **argv) |
||
193 | { |
||
194 | char c = 0; /* character from keyboard */ |
||
195 | |||
1377 | giacomo | 196 | set_shutdown_task(); |
1085 | pj | 197 | |
1377 | giacomo | 198 | device_drivers_init(); |
1085 | pj | 199 | |
200 | grx_clear(BLACK); |
||
201 | |||
202 | grx_text("Press a key [1-4]", 10, 16, 7, 0); |
||
203 | grx_text("to create a pair", 10, 24, 7, 0); |
||
204 | grx_text("ESC to exit demo", 10, 48, 7, 0); |
||
205 | |||
206 | while (c != 27) { |
||
207 | c = keyb_getch(BLOCK); |
||
208 | if ((c >= '1') && (c <= '1'+NCAB-1)) |
||
209 | create_channel(c-'1'); |
||
210 | } |
||
211 | |||
1377 | giacomo | 212 | task_activate(shutdown_task_PID); |
1085 | pj | 213 | |
214 | return 0; |
||
215 | } |
||
216 | |||
217 | |||
218 | /*--------------------------------------------------------------*/ |
||
219 | /* write data in a cab */ |
||
220 | /*--------------------------------------------------------------*/ |
||
221 | |||
222 | TASK producer(void *arg) |
||
223 | { |
||
224 | int i = (int)arg; |
||
225 | char c; /* message character */ |
||
226 | char *p; /* pointer to a cab buffer */ |
||
227 | char s[2]; /* string to display */ |
||
228 | int k = 0; |
||
229 | int x, y; |
||
230 | int col = 13; |
||
231 | int ybase = YY + i*DELTA; |
||
232 | |||
233 | x = X1; |
||
234 | y = ybase; |
||
235 | s[1] = 0; |
||
236 | |||
237 | k = 0; |
||
238 | while (1) { |
||
239 | c = 'A' + k; |
||
240 | p = cab_reserve(cid[i]); |
||
241 | *p = c; |
||
242 | cab_putmes(cid[i], p); |
||
243 | |||
244 | s[0] = c; |
||
245 | k = (k + 1) % NCAR; |
||
246 | grx_text(s,x,y,col,0); |
||
247 | |||
248 | x += 8; |
||
249 | if (x >= (X1 + NCAR*8)) { |
||
250 | x = X1; |
||
251 | y = y + 8; |
||
252 | if (y >= ybase+16) { |
||
253 | y = ybase; |
||
254 | col = col % 15 + 1; |
||
255 | } |
||
256 | } |
||
257 | |||
258 | task_endcycle(); |
||
259 | } |
||
260 | } |
||
261 | |||
262 | /*--------------------------------------------------------------*/ |
||
263 | /* read data from a cab */ |
||
264 | /*--------------------------------------------------------------*/ |
||
265 | |||
266 | TASK consumer(void *arg) |
||
267 | { |
||
268 | int i = (int)arg; |
||
269 | char *p; |
||
270 | char s[2]; |
||
271 | int x, y; |
||
272 | int col = 13; |
||
273 | int ybase = YY + i*DELTA; |
||
274 | |||
275 | x = X2; |
||
276 | y = ybase; |
||
277 | s[1] = 0; |
||
278 | |||
279 | while (1) { |
||
280 | p = cab_getmes(cid[i]); |
||
281 | s[0] = *p - 'A' + 'a'; |
||
282 | cab_unget(cid[i], p); |
||
283 | |||
284 | grx_text(s,x,y,col,0); |
||
285 | x += 8; |
||
286 | |||
287 | if (x >= (X2 + NCAR*8)) { |
||
288 | x = X2; |
||
289 | y = y + 8; |
||
290 | if (y >= ybase+16) { |
||
291 | y = ybase; |
||
292 | col = col % 15 + 1; |
||
293 | } |
||
294 | } |
||
295 | task_endcycle(); |
||
296 | } |
||
297 | } |
||
298 | |||
299 | /*--------------------------------------------------------------*/ |
||
300 | /* create the two tasks and a channel */ |
||
301 | /*--------------------------------------------------------------*/ |
||
302 | |||
303 | void create_channel(int i) |
||
304 | { |
||
305 | HARD_TASK_MODEL m; |
||
306 | |||
307 | draw_channel(i); |
||
308 | cid[i] = cab_create(cname[i], 1, 2); |
||
309 | |||
310 | hard_task_default_model(m); |
||
311 | hard_task_def_ctrl_jet (m); |
||
312 | hard_task_def_arg (m, (void *)i); |
||
313 | hard_task_def_wcet (m, w1[i]); |
||
314 | hard_task_def_mit (m, t1[i]); |
||
315 | hard_task_def_usemath (m); |
||
316 | p1[i] = task_create(pname1[i], producer, &m, NULL); |
||
317 | if (p1[i] == NIL) { |
||
1377 | giacomo | 318 | sys_shutdown_message("Could not create task <producer>"); |
319 | task_activate(shutdown_task_PID); |
||
320 | return; |
||
1085 | pj | 321 | } |
322 | task_activate(p1[i]); |
||
323 | |||
324 | hard_task_default_model(m); |
||
325 | hard_task_def_ctrl_jet (m); |
||
326 | hard_task_def_arg (m, (void *)i); |
||
327 | hard_task_def_wcet (m, w2[i]); |
||
328 | hard_task_def_mit (m, t2[i]); |
||
329 | hard_task_def_usemath (m); |
||
330 | p2[i] = task_create(pname2[i], consumer, &m, NULL); |
||
331 | if (p2[i] == NIL) { |
||
1377 | giacomo | 332 | sys_shutdown_message("Could not create task <consumer>"); |
333 | task_activate(shutdown_task_PID); |
||
334 | return; |
||
1085 | pj | 335 | } |
336 | task_activate(p2[i]); |
||
337 | } |
||
338 | |||
339 | /*--------------------------------------------------------------*/ |
||
340 | /* Disegna i processi e il canale di comunicazione */ |
||
341 | /*--------------------------------------------------------------*/ |
||
342 | |||
343 | void draw_channel(int i) |
||
344 | { |
||
345 | char buffer[32]; /* buffer per sprintf */ |
||
346 | int yc = YP + i*DELTA; /* altezza del canale */ |
||
347 | |||
348 | grx_circle(XP1,yc,R,2); |
||
349 | grx_text("P1",XP1-8,yc-4,12,0); |
||
350 | |||
351 | grx_circle(XP2,yc,R,2); |
||
352 | grx_text("P2",XP2-8,yc-4,12,0); |
||
353 | |||
354 | grx_rect(XC,yc-R,XC+L,yc+R,3); |
||
355 | grx_text("CAB",XC+16,yc-4,12,0); |
||
356 | |||
357 | grx_line(XP1+R,yc,XC,yc,4); |
||
358 | grx_line(XC+L,yc,XP2-R,yc,4); |
||
359 | |||
360 | grx_text("T1 = ms",X1+40,yc+R+16,14,0); |
||
361 | sprintf(buffer,"%ld", t1[i]); |
||
362 | grx_text(buffer,X1+88,yc+R+16,14,0); |
||
363 | |||
364 | grx_text("T2 = ms",X2+40,yc+R+16,14,0); |
||
365 | sprintf(buffer,"%ld", t2[i]); |
||
366 | grx_text(buffer,X2+88,yc+R+16,14,0); |
||
367 | } |
||
368 |