Subversion Repositories shark

Rev

Go to most recent revision | Details | 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
 ------------
29
 CVS :        $Id: ppdemo.c,v 1.1 2002-10-28 08:18:27 pj Exp $
30
 
31
 File:        $File$
32
 Revision:    $Revision: 1.1 $
33
 Last update: $Date: 2002-10-28 08:18:27 $
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 is the exception handler. It is called when an exception
333
   is raised.
334
   It exits from the graphical mode, then it prints a message and
335
   shutdown the kernel using sys_abort()
336
*/
337
 
338
void demo_exc_handler(int signo, siginfo_t *info, void *extra)
339
{
340
  struct timespec t;
341
 
342
  grx_close();
343
 
344
  /* Default action for an kern exception is  */
345
  kern_cli();
346
  ll_gettime(TIME_EXACT, &t),
347
    kern_printf("\nS.Ha.R.K. Exception raised!!!"
348
                "\nTime (s:ns)     :%ld:%ld"
349
                "\nException number:%d (numbers in include/bits/errno.h)"
350
                "\nPID             :%d\n",
351
                t.tv_sec, t.tv_nsec, info->si_value.sival_int,
352
                info->si_task);
353
  sys_abort(1);
354
}
355
 
356
/******************************************************************/
357
 
358
/* This function is called when Alt-X is pressed.
359
   It simply shutdown the system using sys_end.
360
   Note that the byebye() function is called only if we exit from
361
   the system using sys_end()!!!!
362
*/
363
void my_end(KEY_EVT* e)
364
{
365
 
366
  sys_end();
367
}
368
 
369
/******************************************************************/
370
 
371
/* This function is called when the system exit correctly after Alt-X.
372
   It exits from the graphic mode and then it prints a small greeting.
373
   Note that:
374
   - The function calls grx_exit, so it must be registered using
375
     RUNLEVEL_BEFORE_EXIT (RUNLEVEL_AFTER_EXIT does not work because
376
     at that point the kernel is already returned in real mode!!!)
377
   - When an exception is raised, the exception handler is called.
378
     Since the exception handler already exits from the graphic mode,
379
     this funcion has not to be called. For this reason:
380
     . we registered byebye using the flag NO_AT_ABORT
381
     . the exception handler exits using sys_abort; in that way byebye is
382
       NOT called
383
*/
384
 
385
void byebye(void *arg)
386
{
387
  grx_close();
388
  kern_printf("Bye Bye!\n");
389
}
390
 
391
/****************************** MAIN ******************************/
392
 
393
int main(int argc, char **argv)
394
{
395
  PID               pid2, pid;
396
  KEY_EVT           emerg;
397
 
398
  HARD_TASK_MODEL   m2;
399
  SOFT_TASK_MODEL mp;
400
 
401
  struct sigaction action;
402
 
403
 
404
  /* Init the standard S.Ha.R.K. exception handler */
405
  action.sa_flags = SA_SIGINFO;            /* Set the signal action */
406
  action.sa_sigaction = demo_exc_handler;
407
  action.sa_handler = 0;
408
  sigfillset(&action.sa_mask); /* we block all the other signals... */
409
 
410
  if (sigaction(SIGHEXC, &action, NULL) == -1) {  /* set the signal */
411
    perror("Error initializing signals..."); sys_end();}
412
 
413
  /* Set the closing function */
414
  sys_atrunlevel(byebye, NULL, RUNLEVEL_BEFORE_EXIT|NO_AT_ABORT);
415
 
416
 
417
 
418
 
419
  keyb_set_map(itaMap);
420
  /* set the keyboard handler to exit correctly */
421
  emerg.ascii = 'x';
422
  emerg.scan = KEY_X;
423
  emerg.flag = ALTL_BIT;
424
  keyb_hook(emerg,my_end);
425
 
426
  emerg.ascii = 'x';
427
  emerg.scan = KEY_X;
428
  emerg.flag = ALTR_BIT;
429
  keyb_hook(emerg,my_end);
430
 
431
  /* a small banner */
432
  kern_printf("ppChat Demo\n");
433
  kern_printf("Press Alt-X to exit\n");
434
 
435
  /* graphics */
436
  ppInitGrxWnd();
437
 
438
 
439
  /* graphic card Initialization */
440
  //kern_printf("Video card ok!\n");
441
 
442
 
443
 
444
  /* ppDrv creation */
445
  ppGrxWnd2("Initing Drv...\n");
446
  ppInitDrv(ppGrxWnd2); /* pass output fnc for init debug...*/
447
 
448
  ppInitGrxWnd_b();
449
 
450
 
451
  /* MODEL TASK EXAMPLES */
452
  soft_task_default_model(mp);
453
  soft_task_def_level(mp,1);
454
  soft_task_def_ctrl_jet(mp);
455
  soft_task_def_arg(mp, (void *)0);
456
  soft_task_def_group(mp, 1);
457
  soft_task_def_met(mp, PPDRV_WCET);
458
  soft_task_def_period(mp,PPDRV_PERIOD);
459
  soft_task_def_usemath(mp);
460
  pid = task_create("ppDrv", ppPollingSvr, &mp, NULL);
461
  if (pid != NIL) task_activate(pid);
462
  /**/
463
 
464
  //hard_task_default_model(m1);
465
  //hard_task_def_ctrl_jet (m1);
466
  //hard_task_def_arg      (m1, (void *)0);
467
  //hard_task_def_wcet     (m1, PPDRV_WCET);
468
  //hard_task_def_mit      (m1, PPDRV_PERIOD);
469
  //hard_task_def_group    (m1,1);
470
  //pid1 = task_create("ppDrv", ppPollingSvr, &m1, NULL);
471
  //if (pid1 == NIL) {/*grx_close();*/ perror("Could not create task <ppDrv>");sys_abort(1);}
472
  //if(task_activate(pid1)==-1) {/*grx_close();*/ perror("Could not create task <ppDrv>");sys_abort(1);};
473
 
474
  //(" Task ppDrv Activate...PID: %i\n",pid1);
475
  //        kern_printf("---------------------\n");
476
 
477
 
478
  /* ppChat creation */
479
  hard_task_default_model(m2);
480
  hard_task_def_ctrl_jet (m2);
481
  hard_task_def_arg      (m2, (void *)1);
482
  hard_task_def_wcet     (m2, TSK_WCET);
483
  hard_task_def_mit      (m2, TSK_PERIOD);
484
  hard_task_def_group    (m2,2);
485
  pid2 = task_create("ppChat", ppChat, &m2, NULL);
486
  if (pid2 == NIL) {/*grx_close();*/ perror("Could not create task <ppChat>");sys_abort(1);}
487
  task_activate(pid2);
488
  //kern_printf("Task Chat Activate...PID: %i\n",pid2);
489
 
490
  //kern_printf("---------------------\n");
491
 
492
 
493
  /*
494
    now the task main ends, but the system does not shutdown because
495
    there are the three task ego1, ego2, and ego3 running.
496
    The demo will finish if a Alt-X key is pressed.
497
  */
498
 
499
  return 0;
500
}
501
 
502
/* MODEL TASK EXAMPLES (from jumpball demo)
503
 
504
   SOFT_TASK_MODEL mp;
505
 
506
   soft_task_default_model(mp);
507
   soft_task_def_level(mp,1);
508
   soft_task_def_ctrl_jet(mp);
509
   soft_task_def_arg(mp, (void *)rgb16(r,g,b));
510
   soft_task_def_group(mp, BALL_GROUP);
511
   soft_task_def_met(mp, WCET_BALL);
512
   soft_task_def_period(mp,PERIOD_BALL);
513
   soft_task_def_usemath(mp);
514
   pid = task_create(palla_str, palla, &mp, NULL);
515
 
516
   if (pid != NIL) task_activate(pid);
517
 
518
 
519
   HARD TASK EXAMPLES
520
 
521
   HARD_TASK_MODEL mp;
522
 
523
   hard_task_default_model(mp);
524
   hard_task_def_ctrl_jet(mp);
525
   hard_task_def_arg(mp, (void *)rgb16(r,g,b));
526
   hard_task_def_wcet(mp, 380);
527
   hard_task_def_mit(mp,PERIOD_BALL);
528
   hard_task_def_usemath(mp);
529
   pid = task_create("pallaEDF", palla, &mp, NULL);
530
 
531
   if (pid != NIL) task_activate(pid);
532
*/