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

VxWorks

开发平台:

C/C++

  1. /* usrSerial.c - serial device configuration file */
  2. /* Copyright 1984-1998 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01c,24feb99,pr   added control for PC_CONSOLE in IO initialization (SPR#23075)
  7. 01b,11oct97,ms   use itos instead of sprintf to break dependecy on fioLib
  8. 01a,09oct97,ms   taken from usrConfig.c
  9. */
  10. /*
  11. DESCRIPTION
  12. User configurable serial device intialization.
  13. */
  14. #define TY_NAME_BASE "/tyCo/"
  15. /******************************************************************************
  16. *
  17. * itos - given an integer, return a string representing it.
  18. */
  19. static char * itos (int val)
  20.     {
  21.     static char str [20];
  22.     char strtmp [20];
  23.     str [0] = '';
  24.     if (val == 0)
  25. return "0";
  26.     while (val != 0)
  27. {
  28. strcpy (strtmp, str);
  29. str[0] = '0' + (val % 10);
  30. str[1] = '';
  31. strcat (str, strtmp);
  32. val = val - (val %= 10);
  33. }
  34.     return str;
  35.     }
  36. /******************************************************************************
  37. *
  38. * usrSerialInit - initialize the serial ports
  39. */
  40. STATUS usrSerialInit (void)
  41.     {
  42.     char tyName [20];
  43.     int ix;
  44.     if (NUM_TTY > 0)
  45. {
  46. ttyDrv(); /* install console driver */
  47. for (ix = 0; ix < NUM_TTY; ix++) /* create serial devices */
  48.     {
  49. #if     (defined(INCLUDE_WDB) && defined(INCLUDE_WDB_COMM_SERIAL))
  50.     if (ix == WDB_TTY_CHANNEL) /* don't use WDBs channel */
  51. continue;
  52. #endif
  53.     tyName[0] = '';
  54.     strcat (tyName, TY_NAME_BASE);
  55.     strcat (tyName, itos (ix));
  56.     (void) ttyDevCreate (tyName, sysSerialChanGet(ix), 512, 512);
  57. #if  (!(defined(INCLUDE_PC_CONSOLE)))
  58.     if (ix == CONSOLE_TTY) /* init the tty console */
  59. {
  60. consoleFd = open (tyName, O_RDWR, 0);
  61. (void) ioctl (consoleFd, FIOBAUDRATE, CONSOLE_BAUD_RATE);
  62. (void) ioctl (consoleFd, FIOSETOPTIONS, OPT_TERMINAL);
  63. }
  64. #endif /* INCLUDE_PC_CONSOLE */
  65.     }
  66. }
  67.     ioGlobalStdSet (STD_IN,  consoleFd);
  68.     ioGlobalStdSet (STD_OUT, consoleFd);
  69.     ioGlobalStdSet (STD_ERR, consoleFd);
  70.     return (OK);
  71.     }