Subversion Repositories shark

Rev

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

/*
 *
 * Project:
 *   Parallel Port S.Ha.R.K. Project
 *
 * Module:
 *   ppDemo.c
 *
 * Description:
 *   file contents description
 *
 * Coordinators:
 *   Giorgio Buttazzo    <giorgio@sssup.it>
 *   Paolo Gai           <pj@gandalf.sssup.it>
 *
 * Authors:
 *   Andrea Battistotti <btandrea@libero.it>
 *   Armando Leggio     <a_leggio@hotmail.com>
 *
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://shark.sssup.it
 *
 */


/**
 ------------
 CVS :        $Id: ppdemo.c,v 1.2 2003-01-07 17:10:18 pj Exp $

 File:        $File$
 Revision:    $Revision: 1.2 $
 Last update: $Date: 2003-01-07 17:10:18 $
 ------------
**/


/*
 * Copyright (C) 2000 Paolo Gai and Giorgio Buttazzo
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


/****************************************************************/
/*      PERIODIC PROCESS TEST                                   */
/****************************************************************/


#include <drivers/parport.h>


#define TSK_PERIOD       250000     /*400000 ok for debug...*/
#define TSK_WCET          70000
 

#define YMENU    10             /* menu level                   */
#define XMIN     10
#define XMAX     630
#define YMIN     10
#define YMAX     470
#define ESC      27             /* ASCII code of ESCAPE key     */
#define X0      
#define GRXWND_COLS 33
#define GRXWND_LINS 15



void ppInitGrxWnd(void)
{
  /* graphic preparation */
  /* graphic card Initialization */
  if (grx_init() < 1) {
    sys_abort(1);
  }
   
  if (grx_open(640, 480, 8) < 0) {
    kern_printf("GRX Err\n");
    sys_abort(1);
  }
  kern_printf("Video card ok!\n");
  /* The scenario */

  // Background
  grx_clear(6);

  // Frame
  grx_rect(XMIN-1, YMIN-1, XMAX+1, YMAX+1, 0);

  // Window 1
  grx_box(XMIN+14,YMIN+14,XMAX-317,YMAX-235,7); //window
  grx_box(XMIN+17,YMIN+17,XMAX-320,YMAX-427,1); //bar
  grx_box(XMIN+17,YMIN+42,XMAX- 320,YMAX-238,0); //workspace
  grx_box(XMIN+286,YMIN+19,XMAX-322,YMAX-429,7);//button
  grx_text("PPDemo", XMIN+30, YMIN+21, 15, 1);  //title
  grx_text("**********************************", XMIN+25, YMIN+55, 10, 0);
  grx_text("*  PARALLEL PORT  DEMONSTRATION  *", XMIN+25, YMIN+70, 10, 0);
  grx_text("**********************************", XMIN+25, YMIN+85, 10, 0);
  grx_text("Press ALT X to exit", XMIN+25, YMIN+115, 10, 0);
  grx_text("other keys to communicate with", XMIN+25, YMIN+130, 10, 0);
  grx_text("remote terminal", XMIN+25, YMIN+145, 10, 0);
  grx_text("(c) Copyright 2002", XMIN+25, YMIN+190, 10, 0);
  grx_text("Andrea Battistotti, Armando Leggio", XMIN+25, YMIN+205, 10, 0);
 
  // Window 2
  grx_box(XMIN+317,YMIN+14,XMAX-14,YMAX-235,7);
  grx_box(XMIN+320,YMIN+17,XMAX-17,YMAX-427,1);
  grx_box(XMIN+320,YMIN+42,XMAX-17,YMAX-238,0);
  grx_box(XMIN+589,YMIN+19,XMAX-19,YMAX-429,7);
  grx_text("Statistics", XMIN+333, YMIN+21, 15, 1);

}


void ppInitGrxWnd_b(void)
{
  // Window 3
  grx_box(XMIN+14,YMIN+243,XMAX-317,YMAX-6,7);
  grx_box(XMIN+17,YMIN+246,XMAX-320,YMAX-198,1);
  grx_box(XMIN+17,YMIN+271,XMAX-320,YMAX-9,0);
  grx_box(XMIN+286,YMIN+248,XMAX-322,YMAX-200,7);
  grx_text("Local Terminal", XMIN+30, YMIN+250, 15, 1);

        // Window 4
  grx_box(XMIN+317,YMIN+243,XMAX-14,YMAX-6,7);
  grx_box(XMIN+320,YMIN+246,XMAX-17,YMAX-198,1);
  grx_box(XMIN+320,YMIN+271,XMAX-17,YMAX-9,0);
  grx_box(XMIN+589,YMIN+248,XMAX-19,YMAX-200,7);
  grx_text("Remote Terminal", XMIN+333, YMIN+250, 15, 1);

}


void ppGrxWnd2(char *c) /* sys msg wind */
{
  static int i,j;
  static char sysmsg[GRXWND_LINS+1][GRXWND_COLS+1];
  char    s[2];

  s[1]='\0';
 

  while ((s[0]=*c++)) // *c != 0
    {
      sysmsg[i][j]=s[0] ;
      switch (s[0])
        {
        case '\r': case '\n':
          j=0;i++;
          break;

        case '\b':
          if (j>0)
            {
              j--;s[0]=' ';
              grx_text(s, XMIN+330+8*j, YMIN+49+10*i,10,0);
  //statistics grx_text(s, XMIN+330+8*j, YMIN+49+10*i,10,0);
  //statistics
            }
          break;

        default:
          grx_text(s, XMIN+330+8*j, YMIN+49+10*i,10,0);  //statistics
          j++;
          break;

        }
      if (j>=GRXWND_COLS)
        {i++;
        j=0;}
      if (i>=GRXWND_LINS) {
        s[0]=' ';
        for (i=0;i<GRXWND_LINS;i++){
          for (j=0;j<GRXWND_COLS;j++){
            grx_text(s, XMIN+330+8*j, YMIN+49+10*i,10,0);  //statistics
          };
        };
        i=0; j=0;
      };
    } // end while
}


void ppGrxWnd3(char c)
{
  static int i,j;
  char talk[GRXWND_LINS+1][GRXWND_COLS+1];
  char    s[2];
  s[1]='\0';

  talk[i][j]=c;
  s[0] = c;
  switch (c)
    {
    case '\r': case '\n':
      j=0;i++;
      break;


    case '\b':
      if (j>0)
        {
          j--;s[0]=' ';
          grx_text(s, XMIN+27+8*j, YMIN+278+10*i,10,0);  //local term

        }
      break;

    default:
      grx_text(s, XMIN+27+8*j, YMIN+278+10*i,10,0);  //local term
      j++;
      break;

    }
  if(j==GRXWND_COLS) {i++; j=0;};
  if(i==GRXWND_LINS) {
    s[0]=' ';
    for (i=0;i<GRXWND_LINS;i++){
      for (j=0;j<GRXWND_COLS;j++){
        grx_text(s, XMIN+27+8*j, YMIN+278+10*i,10,0);  //local term
      };
    };
    i=0; j=0;
  }
}
       

void ppGrxWnd4(char c)
{
  static int i,j;
  char talk[GRXWND_LINS][GRXWND_COLS];
  char    s[2];
  s[1]='\0';

  talk[i][j]=c;
  s[0] = c;
  switch (c)
    {
    case '\r': case '\n':
      j=0;i++;break;

    case '\b':
      if (j>0)
        {
          j--;s[0]=' ';
          grx_text(s, XMIN+330+8*j, YMIN+278+10*i,10,0); //remote term
        }
      break;
    default:
      grx_text(s, XMIN+330+8*j, YMIN+278+10*i,10,0); //remote term
      j++;
      break;
    }

  if(j==GRXWND_COLS) {i++; j=0;}
  if(i==GRXWND_LINS) {
    s[0]=' ';
    for (i=0;i<GRXWND_LINS;i++){
      for (j=0;j<GRXWND_COLS;j++){
        grx_text(s, XMIN+330+8*j, YMIN+278+10*i,10,0); //remote term
      };
    };
    i=0; j=0;
  }
}


/***************************************************************/

TASK ppChat(void *arg)
{
  char    sysmsg[SYS_MSG_COLS+1];
  long    xposTx;
  KEY_EVT k;
  BYTE b;
               
       
  k.ascii = 0;
  xposTx=9430 ;  // any 16 bit test value...

  task_endcycle();

  while (1) {
#if PP_DEBUG == 1
                                //kern_printf("ppchat \n");
#endif
                                /* read char buffer */
    if (keyb_getcode(&k,NON_BLOCK))
      {
        /* if any send it to ppDrv ...*/
        b=k.ascii;
#if PP_DEBUG == 1
        kern_printf("Send char: %i , %c \n",b,b);
#endif
        //kern_printf("--- Transmit value for xposTx:  %d \n",xposTx);
        //ppTxBytes( (BYTE *) &xposTx, sizeof(xposTx) );
        ppGrxWnd3(b);
        ppTxOneByte(b);
      }

    if (ppRxOneByte(&b)==PP_COMM_OK)
      //if (ppRxBytes((BYTE *) &xposRx, sizeof(xposRx))==PP_COMM_OK)
      {
        ppGrxWnd4(b);
        //kern_printf("%c",b);
        //kern_printf("--- Received value for xposRx:  %d \n",  xposRx);
      }
               
    if (ppReadSysMsg(sysmsg)==PP_SYSMSG_OK)   ppGrxWnd2(sysmsg);
               

    /* ..and show it in upper screen..*/
               
    task_endcycle();
  }
}


/****************************************************************/

/* This function is called when Alt-X is pressed.
   It simply shutdown the system using sys_end.
   Note that the byebye() function is called only if we exit from
   the system using sys_end()!!!!
*/

void my_end(KEY_EVT* e)
{

  sys_end();
}

/******************************************************************/

/* This function is called when the system exit correctly after Alt-X.
   It exits from the graphic mode and then it prints a small greeting.
   Note that:
   - The function calls grx_exit, so it must be registered using
     RUNLEVEL_BEFORE_EXIT (RUNLEVEL_AFTER_EXIT does not work because
     at that point the kernel is already returned in real mode!!!)
   - When an exception is raised, the exception handler is called.
     Since the exception handler already exits from the graphic mode,
     this funcion has not to be called. For this reason:
     . we registered byebye using the flag NO_AT_ABORT
     . the exception handler exits using sys_abort; in that way byebye is
       NOT called
*/


void byebye(void *arg)
{
  grx_close();
  kern_printf("Bye Bye!\n");
}

/****************************** MAIN ******************************/

int main(int argc, char **argv)
{
  PID               pid2, pid;
  KEY_EVT           emerg;

  HARD_TASK_MODEL   m2;
  SOFT_TASK_MODEL mp;

  /* Set the closing function */
  sys_atrunlevel(byebye, NULL, RUNLEVEL_BEFORE_EXIT);

       

               
  keyb_set_map(itaMap);
  /* set the keyboard handler to exit correctly */
  emerg.ascii = 'x';
  emerg.scan = KEY_X;
  emerg.flag = ALTL_BIT;
  keyb_hook(emerg,my_end);
               
  emerg.ascii = 'x';
  emerg.scan = KEY_X;
  emerg.flag = ALTR_BIT;
  keyb_hook(emerg,my_end);

  /* a small banner */
  kern_printf("ppChat Demo\n");
  kern_printf("Press Alt-X to exit\n");

  /* graphics */
  ppInitGrxWnd();

       
  /* graphic card Initialization */
  //kern_printf("Video card ok!\n");


               
  /* ppDrv creation */
  ppGrxWnd2("Initing Drv...\n");
  ppInitDrv(ppGrxWnd2); /* pass output fnc for init debug...*/

  ppInitGrxWnd_b();


  /* MODEL TASK EXAMPLES */
  soft_task_default_model(mp);
  soft_task_def_level(mp,1);
  soft_task_def_ctrl_jet(mp);
  soft_task_def_arg(mp, (void *)0);
  soft_task_def_group(mp, 1);
  soft_task_def_met(mp, PPDRV_WCET);
  soft_task_def_period(mp,PPDRV_PERIOD);
  soft_task_def_usemath(mp);
  pid = task_create("ppDrv", ppPollingSvr, &mp, NULL);
  if (pid != NIL) task_activate(pid);
  /**/
       
  //hard_task_default_model(m1);
  //hard_task_def_ctrl_jet (m1);
  //hard_task_def_arg      (m1, (void *)0);
  //hard_task_def_wcet     (m1, PPDRV_WCET);
  //hard_task_def_mit      (m1, PPDRV_PERIOD);
  //hard_task_def_group    (m1,1);
  //pid1 = task_create("ppDrv", ppPollingSvr, &m1, NULL);
  //if (pid1 == NIL) {/*grx_close();*/ perror("Could not create task <ppDrv>");sys_abort(1);}
  //if(task_activate(pid1)==-1) {/*grx_close();*/ perror("Could not create task <ppDrv>");sys_abort(1);};
       
  //(" Task ppDrv Activate...PID: %i\n",pid1);
  //        kern_printf("---------------------\n");
       

  /* ppChat creation */
  hard_task_default_model(m2);
  hard_task_def_ctrl_jet (m2);
  hard_task_def_arg      (m2, (void *)1);
  hard_task_def_wcet     (m2, TSK_WCET);
  hard_task_def_mit      (m2, TSK_PERIOD);
  hard_task_def_group    (m2,2);
  pid2 = task_create("ppChat", ppChat, &m2, NULL);
  if (pid2 == NIL) {/*grx_close();*/ perror("Could not create task <ppChat>");sys_abort(1);}
  task_activate(pid2);
  //kern_printf("Task Chat Activate...PID: %i\n",pid2);
       
  //kern_printf("---------------------\n");


  /*
    now the task main ends, but the system does not shutdown because
    there are the three task ego1, ego2, and ego3 running.
    The demo will finish if a Alt-X key is pressed.
  */


  return 0;
}

/* MODEL TASK EXAMPLES (from jumpball demo)

   SOFT_TASK_MODEL mp;
 
   soft_task_default_model(mp);
   soft_task_def_level(mp,1);
   soft_task_def_ctrl_jet(mp);
   soft_task_def_arg(mp, (void *)rgb16(r,g,b));
   soft_task_def_group(mp, BALL_GROUP);
   soft_task_def_met(mp, WCET_BALL);
   soft_task_def_period(mp,PERIOD_BALL);
   soft_task_def_usemath(mp);
   pid = task_create(palla_str, palla, &mp, NULL);

   if (pid != NIL) task_activate(pid);


   HARD TASK EXAMPLES

   HARD_TASK_MODEL mp;

   hard_task_default_model(mp);
   hard_task_def_ctrl_jet(mp);
   hard_task_def_arg(mp, (void *)rgb16(r,g,b));
   hard_task_def_wcet(mp, 380);
   hard_task_def_mit(mp,PERIOD_BALL);
   hard_task_def_usemath(mp);
   pid = task_create("pallaEDF", palla, &mp, NULL);
 
   if (pid != NIL) task_activate(pid);
*/