Subversion Repositories shark

Rev

Rev 1101 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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