Rev 1655 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1655 | giacomo | 1 | /* |
2 | * |
||
3 | * Project: |
||
4 | * Parallel Port S.Ha.R.K. Project |
||
5 | * |
||
6 | * Module: |
||
7 | * ppDemo.c |
||
8 | * |
||
9 | * Description: |
||
10 | * file contents description |
||
11 | * |
||
12 | * Coordinators: |
||
13 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
14 | * Paolo Gai <pj@gandalf.sssup.it> |
||
15 | * |
||
16 | * Authors: |
||
17 | * Andrea Battistotti <btandrea@libero.it> |
||
18 | * Armando Leggio <a_leggio@hotmail.com> |
||
19 | * |
||
20 | * |
||
21 | * http://www.sssup.it |
||
22 | * http://retis.sssup.it |
||
23 | * http://shark.sssup.it |
||
24 | * |
||
25 | */ |
||
26 | |||
27 | /** |
||
28 | ------------ |
||
29 | CVS : $Id: ppdemo.c,v 1.1.1.1 2004-05-24 18:03:47 giacomo Exp $ |
||
30 | |||
31 | File: $File$ |
||
32 | Revision: $Revision: 1.1.1.1 $ |
||
33 | Last update: $Date: 2004-05-24 18:03:47 $ |
||
34 | ------------ |
||
35 | **/ |
||
36 | |||
37 | /* |
||
38 | * Copyright (C) 2000 Paolo Gai and Giorgio Buttazzo |
||
39 | * |
||
40 | * This program is free software; you can redistribute it and/or modify |
||
41 | * it under the terms of the GNU General Public License as published by |
||
42 | * the Free Software Foundation; either version 2 of the License, or |
||
43 | * (at your option) any later version. |
||
44 | * |
||
45 | * This program is distributed in the hope that it will be useful, |
||
46 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
47 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
48 | * GNU General Public License for more details. |
||
49 | * |
||
50 | * You should have received a copy of the GNU General Public License |
||
51 | * along with this program; if not, write to the Free Software |
||
52 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
53 | * |
||
54 | */ |
||
55 | |||
56 | /****************************************************************/ |
||
57 | /* PERIODIC PROCESS TEST */ |
||
58 | /****************************************************************/ |
||
59 | |||
60 | |||
61 | #include <drivers/parport.h> |
||
62 | #include <drivers/keyb.h> |
||
63 | #include <drivers/glib.h> |
||
64 | |||
65 | #define TSK_PERIOD 250000 /*400000 ok for debug...*/ |
||
66 | #define TSK_WCET 70000 |
||
67 | |||
68 | |||
69 | #define YMENU 10 /* menu level */ |
||
70 | #define XMIN 10 |
||
71 | #define XMAX 630 |
||
72 | #define YMIN 10 |
||
73 | #define YMAX 470 |
||
74 | #define ESC 27 /* ASCII code of ESCAPE key */ |
||
75 | #define X0 |
||
76 | #define GRXWND_COLS 33 |
||
77 | #define GRXWND_LINS 15 |
||
78 | |||
79 | |||
80 | |||
81 | void ppInitGrxWnd(void) |
||
82 | { |
||
83 | /* graphic preparation */ |
||
84 | /* graphic card Initialization */ |
||
85 | if (grx_init() < 1) { |
||
86 | sys_abort(1); |
||
87 | } |
||
88 | |||
89 | if (grx_open(640, 480, 8) < 0) { |
||
90 | kern_printf("GRX Err\n"); |
||
91 | sys_abort(1); |
||
92 | } |
||
93 | kern_printf("Video card ok!\n"); |
||
94 | /* The scenario */ |
||
95 | |||
96 | // Background |
||
97 | grx_clear(6); |
||
98 | |||
99 | // Frame |
||
100 | grx_rect(XMIN-1, YMIN-1, XMAX+1, YMAX+1, 0); |
||
101 | |||
102 | // Window 1 |
||
103 | grx_box(XMIN+14,YMIN+14,XMAX-317,YMAX-235,7); //window |
||
104 | grx_box(XMIN+17,YMIN+17,XMAX-320,YMAX-427,1); //bar |
||
105 | grx_box(XMIN+17,YMIN+42,XMAX- 320,YMAX-238,0); //workspace |
||
106 | grx_box(XMIN+286,YMIN+19,XMAX-322,YMAX-429,7);//button |
||
107 | grx_text("PPDemo", XMIN+30, YMIN+21, 15, 1); //title |
||
108 | grx_text("**********************************", XMIN+25, YMIN+55, 10, 0); |
||
109 | grx_text("* PARALLEL PORT DEMONSTRATION *", XMIN+25, YMIN+70, 10, 0); |
||
110 | grx_text("**********************************", XMIN+25, YMIN+85, 10, 0); |
||
111 | grx_text("Press ALT X to exit", XMIN+25, YMIN+115, 10, 0); |
||
112 | grx_text("other keys to communicate with", XMIN+25, YMIN+130, 10, 0); |
||
113 | grx_text("remote terminal", XMIN+25, YMIN+145, 10, 0); |
||
114 | grx_text("(c) Copyright 2002", XMIN+25, YMIN+190, 10, 0); |
||
115 | grx_text("Andrea Battistotti, Armando Leggio", XMIN+25, YMIN+205, 10, 0); |
||
116 | |||
117 | // Window 2 |
||
118 | grx_box(XMIN+317,YMIN+14,XMAX-14,YMAX-235,7); |
||
119 | grx_box(XMIN+320,YMIN+17,XMAX-17,YMAX-427,1); |
||
120 | grx_box(XMIN+320,YMIN+42,XMAX-17,YMAX-238,0); |
||
121 | grx_box(XMIN+589,YMIN+19,XMAX-19,YMAX-429,7); |
||
122 | grx_text("Statistics", XMIN+333, YMIN+21, 15, 1); |
||
123 | |||
124 | } |
||
125 | |||
126 | |||
127 | void ppInitGrxWnd_b(void) |
||
128 | { |
||
129 | // Window 3 |
||
130 | grx_box(XMIN+14,YMIN+243,XMAX-317,YMAX-6,7); |
||
131 | grx_box(XMIN+17,YMIN+246,XMAX-320,YMAX-198,1); |
||
132 | grx_box(XMIN+17,YMIN+271,XMAX-320,YMAX-9,0); |
||
133 | grx_box(XMIN+286,YMIN+248,XMAX-322,YMAX-200,7); |
||
134 | grx_text("Local Terminal", XMIN+30, YMIN+250, 15, 1); |
||
135 | |||
136 | // Window 4 |
||
137 | grx_box(XMIN+317,YMIN+243,XMAX-14,YMAX-6,7); |
||
138 | grx_box(XMIN+320,YMIN+246,XMAX-17,YMAX-198,1); |
||
139 | grx_box(XMIN+320,YMIN+271,XMAX-17,YMAX-9,0); |
||
140 | grx_box(XMIN+589,YMIN+248,XMAX-19,YMAX-200,7); |
||
141 | grx_text("Remote Terminal", XMIN+333, YMIN+250, 15, 1); |
||
142 | |||
143 | } |
||
144 | |||
145 | |||
146 | void ppGrxWnd2(char *c) /* sys msg wind */ |
||
147 | { |
||
148 | static int i,j; |
||
149 | static char sysmsg[GRXWND_LINS+1][GRXWND_COLS+1]; |
||
150 | char s[2]; |
||
151 | |||
152 | s[1]='\0'; |
||
153 | |||
154 | |||
155 | while ((s[0]=*c++)) // *c != 0 |
||
156 | { |
||
157 | sysmsg[i][j]=s[0] ; |
||
158 | switch (s[0]) |
||
159 | { |
||
160 | case '\r': case '\n': |
||
161 | j=0;i++; |
||
162 | break; |
||
163 | |||
164 | case '\b': |
||
165 | if (j>0) |
||
166 | { |
||
167 | j--;s[0]=' '; |
||
168 | grx_text(s, XMIN+330+8*j, YMIN+49+10*i,10,0); |
||
169 | //statistics grx_text(s, XMIN+330+8*j, YMIN+49+10*i,10,0); |
||
170 | //statistics |
||
171 | } |
||
172 | break; |
||
173 | |||
174 | default: |
||
175 | grx_text(s, XMIN+330+8*j, YMIN+49+10*i,10,0); //statistics |
||
176 | j++; |
||
177 | break; |
||
178 | |||
179 | } |
||
180 | if (j>=GRXWND_COLS) |
||
181 | {i++; |
||
182 | j=0;} |
||
183 | if (i>=GRXWND_LINS) { |
||
184 | s[0]=' '; |
||
185 | for (i=0;i<GRXWND_LINS;i++){ |
||
186 | for (j=0;j<GRXWND_COLS;j++){ |
||
187 | grx_text(s, XMIN+330+8*j, YMIN+49+10*i,10,0); //statistics |
||
188 | }; |
||
189 | }; |
||
190 | i=0; j=0; |
||
191 | }; |
||
192 | } // end while |
||
193 | } |
||
194 | |||
195 | |||
196 | void ppGrxWnd3(char c) |
||
197 | { |
||
198 | static int i,j; |
||
199 | char talk[GRXWND_LINS+1][GRXWND_COLS+1]; |
||
200 | char s[2]; |
||
201 | s[1]='\0'; |
||
202 | |||
203 | talk[i][j]=c; |
||
204 | s[0] = c; |
||
205 | switch (c) |
||
206 | { |
||
207 | case '\r': case '\n': |
||
208 | j=0;i++; |
||
209 | break; |
||
210 | |||
211 | |||
212 | case '\b': |
||
213 | if (j>0) |
||
214 | { |
||
215 | j--;s[0]=' '; |
||
216 | grx_text(s, XMIN+27+8*j, YMIN+278+10*i,10,0); //local term |
||
217 | |||
218 | } |
||
219 | break; |
||
220 | |||
221 | default: |
||
222 | grx_text(s, XMIN+27+8*j, YMIN+278+10*i,10,0); //local term |
||
223 | j++; |
||
224 | break; |
||
225 | |||
226 | } |
||
227 | if(j==GRXWND_COLS) {i++; j=0;}; |
||
228 | if(i==GRXWND_LINS) { |
||
229 | s[0]=' '; |
||
230 | for (i=0;i<GRXWND_LINS;i++){ |
||
231 | for (j=0;j<GRXWND_COLS;j++){ |
||
232 | grx_text(s, XMIN+27+8*j, YMIN+278+10*i,10,0); //local term |
||
233 | }; |
||
234 | }; |
||
235 | i=0; j=0; |
||
236 | } |
||
237 | } |
||
238 | |||
239 | |||
240 | void ppGrxWnd4(char c) |
||
241 | { |
||
242 | static int i,j; |
||
243 | char talk[GRXWND_LINS][GRXWND_COLS]; |
||
244 | char s[2]; |
||
245 | s[1]='\0'; |
||
246 | |||
247 | talk[i][j]=c; |
||
248 | s[0] = c; |
||
249 | switch (c) |
||
250 | { |
||
251 | case '\r': case '\n': |
||
252 | j=0;i++;break; |
||
253 | |||
254 | case '\b': |
||
255 | if (j>0) |
||
256 | { |
||
257 | j--;s[0]=' '; |
||
258 | grx_text(s, XMIN+330+8*j, YMIN+278+10*i,10,0); //remote term |
||
259 | } |
||
260 | break; |
||
261 | default: |
||
262 | grx_text(s, XMIN+330+8*j, YMIN+278+10*i,10,0); //remote term |
||
263 | j++; |
||
264 | break; |
||
265 | } |
||
266 | |||
267 | if(j==GRXWND_COLS) {i++; j=0;} |
||
268 | if(i==GRXWND_LINS) { |
||
269 | s[0]=' '; |
||
270 | for (i=0;i<GRXWND_LINS;i++){ |
||
271 | for (j=0;j<GRXWND_COLS;j++){ |
||
272 | grx_text(s, XMIN+330+8*j, YMIN+278+10*i,10,0); //remote term |
||
273 | }; |
||
274 | }; |
||
275 | i=0; j=0; |
||
276 | } |
||
277 | } |
||
278 | |||
279 | |||
280 | /***************************************************************/ |
||
281 | |||
282 | TASK ppChat(void *arg) |
||
283 | { |
||
284 | char sysmsg[SYS_MSG_COLS+1]; |
||
285 | long xposTx; |
||
286 | KEY_EVT k; |
||
287 | BYTE b; |
||
288 | |||
289 | |||
290 | k.ascii = 0; |
||
291 | xposTx=9430 ; // any 16 bit test value... |
||
292 | |||
293 | task_endcycle(); |
||
294 | |||
295 | while (1) { |
||
296 | #if PP_DEBUG == 1 |
||
297 | //kern_printf("ppchat \n"); |
||
298 | #endif |
||
299 | /* read char buffer */ |
||
300 | if (keyb_getcode(&k,NON_BLOCK)) |
||
301 | { |
||
302 | /* if any send it to ppDrv ...*/ |
||
303 | b=k.ascii; |
||
304 | #if PP_DEBUG == 1 |
||
305 | kern_printf("Send char: %i , %c \n",b,b); |
||
306 | #endif |
||
307 | //kern_printf("--- Transmit value for xposTx: %d \n",xposTx); |
||
308 | //ppTxBytes( (BYTE *) &xposTx, sizeof(xposTx) ); |
||
309 | ppGrxWnd3(b); |
||
310 | ppTxOneByte(b); |
||
311 | } |
||
312 | |||
313 | if (ppRxOneByte(&b)==PP_COMM_OK) |
||
314 | //if (ppRxBytes((BYTE *) &xposRx, sizeof(xposRx))==PP_COMM_OK) |
||
315 | { |
||
316 | ppGrxWnd4(b); |
||
317 | //kern_printf("%c",b); |
||
318 | //kern_printf("--- Received value for xposRx: %d \n", xposRx); |
||
319 | } |
||
320 | |||
321 | if (ppReadSysMsg(sysmsg)==PP_SYSMSG_OK) ppGrxWnd2(sysmsg); |
||
322 | |||
323 | |||
324 | /* ..and show it in upper screen..*/ |
||
325 | |||
326 | task_endcycle(); |
||
327 | } |
||
328 | } |
||
329 | |||
330 | |||
331 | /****************************************************************/ |
||
332 | |||
333 | /* This function is called when Alt-X is pressed. |
||
334 | It simply shutdown the system using sys_end. |
||
335 | Note that the byebye() function is called only if we exit from |
||
336 | the system using sys_end()!!!! |
||
337 | */ |
||
338 | void my_end(KEY_EVT* e) |
||
339 | { |
||
340 | |||
341 | sys_end(); |
||
342 | } |
||
343 | |||
344 | /******************************************************************/ |
||
345 | |||
346 | /* This function is called when the system exit correctly after Alt-X. |
||
347 | It exits from the graphic mode and then it prints a small greeting. |
||
348 | Note that: |
||
349 | - The function calls grx_exit, so it must be registered using |
||
350 | RUNLEVEL_BEFORE_EXIT (RUNLEVEL_AFTER_EXIT does not work because |
||
351 | at that point the kernel is already returned in real mode!!!) |
||
352 | - When an exception is raised, the exception handler is called. |
||
353 | Since the exception handler already exits from the graphic mode, |
||
354 | this funcion has not to be called. For this reason: |
||
355 | . we registered byebye using the flag NO_AT_ABORT |
||
356 | . the exception handler exits using sys_abort; in that way byebye is |
||
357 | NOT called |
||
358 | */ |
||
359 | |||
360 | void byebye(void *arg) |
||
361 | { |
||
362 | grx_close(); |
||
363 | kern_printf("Bye Bye!\n"); |
||
364 | } |
||
365 | |||
366 | /****************************** MAIN ******************************/ |
||
367 | |||
368 | int main(int argc, char **argv) |
||
369 | { |
||
370 | PID pid2, pid; |
||
371 | KEY_EVT emerg; |
||
372 | |||
373 | HARD_TASK_MODEL m2; |
||
374 | SOFT_TASK_MODEL mp; |
||
375 | |||
376 | /* Set the closing function */ |
||
377 | sys_atrunlevel(byebye, NULL, RUNLEVEL_BEFORE_EXIT); |
||
378 | |||
379 | |||
380 | |||
381 | |||
382 | keyb_set_map(itaMap); |
||
383 | /* set the keyboard handler to exit correctly */ |
||
384 | emerg.ascii = 'x'; |
||
385 | emerg.scan = KEY_X; |
||
386 | emerg.flag = ALTL_BIT; |
||
387 | keyb_hook(emerg,my_end); |
||
388 | |||
389 | emerg.ascii = 'x'; |
||
390 | emerg.scan = KEY_X; |
||
391 | emerg.flag = ALTR_BIT; |
||
392 | keyb_hook(emerg,my_end); |
||
393 | |||
394 | /* a small banner */ |
||
395 | kern_printf("ppChat Demo\n"); |
||
396 | kern_printf("Press Alt-X to exit\n"); |
||
397 | |||
398 | /* graphics */ |
||
399 | ppInitGrxWnd(); |
||
400 | |||
401 | |||
402 | /* graphic card Initialization */ |
||
403 | //kern_printf("Video card ok!\n"); |
||
404 | |||
405 | |||
406 | |||
407 | /* ppDrv creation */ |
||
408 | ppGrxWnd2("Initing Drv...\n"); |
||
409 | ppInitDrv(ppGrxWnd2); /* pass output fnc for init debug...*/ |
||
410 | |||
411 | ppInitGrxWnd_b(); |
||
412 | |||
413 | |||
414 | /* MODEL TASK EXAMPLES */ |
||
415 | soft_task_default_model(mp); |
||
416 | soft_task_def_level(mp,1); |
||
417 | soft_task_def_ctrl_jet(mp); |
||
418 | soft_task_def_arg(mp, (void *)0); |
||
419 | soft_task_def_group(mp, 1); |
||
420 | soft_task_def_met(mp, PPDRV_WCET); |
||
421 | soft_task_def_period(mp,PPDRV_PERIOD); |
||
422 | soft_task_def_usemath(mp); |
||
423 | pid = task_create("ppDrv", ppPollingSvr, &mp, NULL); |
||
424 | if (pid != NIL) task_activate(pid); |
||
425 | /**/ |
||
426 | |||
427 | //hard_task_default_model(m1); |
||
428 | //hard_task_def_ctrl_jet (m1); |
||
429 | //hard_task_def_arg (m1, (void *)0); |
||
430 | //hard_task_def_wcet (m1, PPDRV_WCET); |
||
431 | //hard_task_def_mit (m1, PPDRV_PERIOD); |
||
432 | //hard_task_def_group (m1,1); |
||
433 | //pid1 = task_create("ppDrv", ppPollingSvr, &m1, NULL); |
||
434 | //if (pid1 == NIL) {/*grx_close();*/ perror("Could not create task <ppDrv>");sys_abort(1);} |
||
435 | //if(task_activate(pid1)==-1) {/*grx_close();*/ perror("Could not create task <ppDrv>");sys_abort(1);}; |
||
436 | |||
437 | //(" Task ppDrv Activate...PID: %i\n",pid1); |
||
438 | // kern_printf("---------------------\n"); |
||
439 | |||
440 | |||
441 | /* ppChat creation */ |
||
442 | hard_task_default_model(m2); |
||
443 | hard_task_def_ctrl_jet (m2); |
||
444 | hard_task_def_arg (m2, (void *)1); |
||
445 | hard_task_def_wcet (m2, TSK_WCET); |
||
446 | hard_task_def_mit (m2, TSK_PERIOD); |
||
447 | hard_task_def_group (m2,2); |
||
448 | pid2 = task_create("ppChat", ppChat, &m2, NULL); |
||
449 | if (pid2 == NIL) {/*grx_close();*/ perror("Could not create task <ppChat>");sys_abort(1);} |
||
450 | task_activate(pid2); |
||
451 | //kern_printf("Task Chat Activate...PID: %i\n",pid2); |
||
452 | |||
453 | //kern_printf("---------------------\n"); |
||
454 | |||
455 | |||
456 | /* |
||
457 | now the task main ends, but the system does not shutdown because |
||
458 | there are the three task ego1, ego2, and ego3 running. |
||
459 | The demo will finish if a Alt-X key is pressed. |
||
460 | */ |
||
461 | |||
462 | return 0; |
||
463 | } |
||
464 | |||
465 | /* MODEL TASK EXAMPLES (from jumpball demo) |
||
466 | |||
467 | SOFT_TASK_MODEL mp; |
||
468 | |||
469 | soft_task_default_model(mp); |
||
470 | soft_task_def_level(mp,1); |
||
471 | soft_task_def_ctrl_jet(mp); |
||
472 | soft_task_def_arg(mp, (void *)rgb16(r,g,b)); |
||
473 | soft_task_def_group(mp, BALL_GROUP); |
||
474 | soft_task_def_met(mp, WCET_BALL); |
||
475 | soft_task_def_period(mp,PERIOD_BALL); |
||
476 | soft_task_def_usemath(mp); |
||
477 | pid = task_create(palla_str, palla, &mp, NULL); |
||
478 | |||
479 | if (pid != NIL) task_activate(pid); |
||
480 | |||
481 | |||
482 | HARD TASK EXAMPLES |
||
483 | |||
484 | HARD_TASK_MODEL mp; |
||
485 | |||
486 | hard_task_default_model(mp); |
||
487 | hard_task_def_ctrl_jet(mp); |
||
488 | hard_task_def_arg(mp, (void *)rgb16(r,g,b)); |
||
489 | hard_task_def_wcet(mp, 380); |
||
490 | hard_task_def_mit(mp,PERIOD_BALL); |
||
491 | hard_task_def_usemath(mp); |
||
492 | pid = task_create("pallaEDF", palla, &mp, NULL); |
||
493 | |||
494 | if (pid != NIL) task_activate(pid); |
||
495 | */ |