pcConsole.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:6k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* pcConsole.c - Compaq DeskPro 386 console handler */
  2. /* Copyright 1993-2001 Wind River System, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. modification history
  6. --------------------
  7. 01d,06dec01,jlb  added option to send scan codes and set LEDs
  8. 01c,11jun96,wlf  doc: cleanup.
  9. 01b,14jun95,hdn  removed function declarations defined in sysLib.h.
  10. 01a,09sep93,vin  created.
  11. */
  12. /*
  13. DESCRIPTION
  14. This file is used to link the keyboard driver and the vga driver.
  15. USER CALLABLE ROUTINES
  16. Most of the routines in this driver are accessible only through the I/O
  17. system.  Two routines, however, must be called directly: pcConDrv() to
  18. initialize the driver, and pcConDevCreate() to create devices.
  19. Before using the driver, it must be initialized by calling pcConDrv ()
  20. This routine should be called exactly once, before any reads, writes, or
  21. calls to pcConDevCreate().  Normally, it is called from usrRoot() in 
  22. usrConfig.c.
  23. Before a console can be used, it must be created using pcConDevCreate().
  24. IOCTL FUNCTIONS
  25. This driver responds to the same ioctl codes as a normal ty driver.
  26. SEE ALSO: tyLib
  27. NOTES
  28. The macro N_VIRTUAL_CONSOLES should be defined in config.h file.
  29. */
  30. /* includes */
  31. #include "vxWorks.h"
  32. #include "iv.h"
  33. #include "ioLib.h"
  34. #include "iosLib.h"
  35. #include "memLib.h"
  36. #include "tyLib.h"
  37. #include "intLib.h"
  38. #include "errnoLib.h"
  39. #include "config.h"
  40. #include "drv/serial/pcConsole.h"
  41. /* globals */
  42. PC_CON_DEV pcConDv [N_VIRTUAL_CONSOLES] ; /* device descriptors */
  43. /* locals */
  44. LOCAL int pcConDrvNum; /* driver number assigned to this driver */
  45. /* forward declarations */
  46. LOCAL int pcConDrvOpen ();
  47. LOCAL STATUS pcConDrvIoctl (PC_CON_DEV * pPcCoDv, int request, int arg);
  48. LOCAL void pcConDrvHrdInit ();
  49. /******************************************************************************
  50. *
  51. * pcConDrv - initialize the console driver 
  52. *
  53. * This routine initializes the console driver, sets up interrupt vectors,
  54. * and performs hardware initialization of the keybord and display.
  55. *
  56. * RETURNS: OK, or ERROR if the driver cannot be installed.
  57. */
  58. STATUS pcConDrv (void)
  59.     {
  60.     /* check if driver already installed */
  61.     if (pcConDrvNum > 0)
  62. return (OK);
  63.     pcConDrvHrdInit ();
  64.     pcConDrvNum = iosDrvInstall (pcConDrvOpen, (FUNCPTR) NULL, pcConDrvOpen,
  65. (FUNCPTR) NULL, tyRead, tyWrite, pcConDrvIoctl
  66.  );
  67.     return (pcConDrvNum == ERROR ? ERROR : OK);
  68.     }
  69. /******************************************************************************
  70. *
  71. * pcConDevCreate - create a device for the on-board ports
  72. *
  73. * This routine creates a device on one of the pcConsole ports.  Each port
  74. * to be used should have only one device associated with it, by calling
  75. * this routine.
  76. *
  77. * RETURNS: OK, or ERROR if there is no driver or one already exists for the
  78. * specified port.
  79. */
  80. STATUS pcConDevCreate 
  81.     (
  82.     char * name, /* name to use for this device */
  83.     FAST int channel,        /* virtual console number */
  84.     int rdBufSize, /* read buffer size, in bytes */
  85.     int wrtBufSize /* write buffer size in bytes */
  86.     )
  87.     {
  88.     FAST PC_CON_DEV *pPcCoDv;
  89.     if (pcConDrvNum <= 0)
  90. {
  91. errnoSet (S_ioLib_NO_DRIVER);
  92. return (ERROR);
  93. }
  94.     /* if this device already exists, don't create it */
  95.     if (channel < 0 || channel >= N_VIRTUAL_CONSOLES)
  96.         return (ERROR);
  97.     pPcCoDv = &pcConDv [channel];
  98.     if (pPcCoDv->created)
  99. return (ERROR);
  100.     if (tyDevInit (&pPcCoDv->tyDev, rdBufSize, wrtBufSize, vgaWriteString)
  101. != OK)
  102. {
  103. return (ERROR);
  104. }
  105.     /* enable the keybord interrupt */
  106.     
  107.     sysIntEnablePIC (KBD_INT_LVL);
  108.     /* mark the device as created, and add the device to the I/O system */
  109.     pPcCoDv->created = TRUE;
  110.     return (iosDevAdd (&pPcCoDv->tyDev.devHdr, name, pcConDrvNum));
  111.     }
  112. /******************************************************************************
  113. *
  114. * pcConDrvHrdInit - initialize the Keyboard and VGA
  115. */
  116. LOCAL void pcConDrvHrdInit (void)
  117.     {
  118.     FAST int  oldlevel; /* to hold the oldlevel of interrupt */
  119.     oldlevel= intLock ();
  120.     /* Keyboard initialization */
  121.     kbdHrdInit ();
  122.     /* (VGA) Display initialization */
  123.     vgaHrdInit ();
  124.     /* interrupt is masked out: the keyboard interrupt will be enabled
  125.      * in the pcConDevCreate 
  126.      */
  127.     intUnlock (oldlevel);
  128.     } 
  129. /*******************************************************************************
  130. *
  131. * pcConDrvOpen - open file to Console
  132. *
  133. */
  134. LOCAL int pcConDrvOpen 
  135.     (
  136.     PC_CON_DEV * pPcCoDv,
  137.     char * name,
  138.     int  mode
  139.     )
  140.     {
  141.     return ((int) pPcCoDv);
  142.     }
  143. /*******************************************************************************
  144. *
  145. * pcConDrvIoctl - special device control
  146. *
  147. * This routine handles FIOGETOPT requests and passes all others to tyIoctl.
  148. *
  149. * RETURNS: OK or ERROR if invalid baud rate, or whatever tyIoctl returns.
  150. */
  151. LOCAL STATUS pcConDrvIoctl 
  152.     (
  153.     PC_CON_DEV * pPcCoDv, /* device to control */
  154.     int  request, /* request code */
  155.     int  arg /* some argument */
  156.     )
  157.     {
  158.     int  status = OK;
  159.     switch (request)
  160. {
  161.         case CONIOSETATRB:
  162.             pPcCoDv->vs->curAttrib = arg ;
  163.     break;
  164.         case CONIOGETATRB:
  165.             status = pPcCoDv->vs->curAttrib;
  166.     break;
  167.         case CONIOSETKBD:
  168.             if (arg == 0 || arg == 1)
  169.                 pPcCoDv->ks->kbdMode = arg;
  170.             else
  171.                 status = ERROR;
  172.     break;
  173.         case CONIOSCREENREV:
  174.     pPcCoDv->vs->rev = (pPcCoDv->vs->rev) ? FALSE : TRUE;
  175.     pPcCoDv->vs->vgaHook (pPcCoDv->vs, arg, 0); /* reverse screen */
  176.             break;
  177.         case CONIOBEEP:
  178.     pPcCoDv->vs->vgaHook (pPcCoDv->vs, arg, 1); /* produce beep */
  179.     break;
  180.         case CONIOCURSORON:
  181.     pPcCoDv->vs->vgaHook (pPcCoDv->vs, arg, 2); /* vgaCursor on */
  182.     break;
  183.         case CONIOCURSOROFF:
  184.     pPcCoDv->vs->vgaHook (pPcCoDv->vs, arg, 3); /* vgaCursor off */
  185.     break;
  186.         case CONIOCURSORMOVE:
  187.     pPcCoDv->vs->vgaHook (pPcCoDv->vs, arg, 4); /* position cursor */
  188.     break;
  189.     
  190. case CONIOCURCONSOLE: /* change current console */
  191.     if ((arg >= 0) && (arg < N_VIRTUAL_CONSOLES))
  192.        pPcCoDv->ks->currCon = arg;
  193.     break;
  194. case CONIOCONVERTSCAN:  /* send scan codes or ASCII */
  195.     pPcCoDv->ks->convertChar = arg;
  196.     break;
  197. case CONIOLEDS: /* change LEDs */
  198.     pPcCoDv->ks->kbdFlags &= ~7;
  199.     pPcCoDv->ks->kbdFlags |= (arg & 7);
  200.     pPcCoDv->ks->kbdHook (1);
  201.     break;
  202. default:
  203.     status = tyIoctl (&pPcCoDv->tyDev, request, arg);
  204.     break;
  205. }
  206.     return (status);
  207.     }