home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-1.ZIP / GCOMM / ASIINIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-14  |  2.7 KB  |  91 lines

  1. /* asiinit.c
  2. *
  3. * The Greenleaf Comm Library
  4. *
  5. * Copyright (C) 1985-1990 Greenleaf Software Inc.  All Rights Reserved.
  6. *
  7. *  int asinit( port, baud, parity, stopbits, wordlength )
  8. *  int port;            - Port 0..MAX_PORT-1
  9. *  long baud;           - Baud Rate: (50L-9600L,19000L, 38400L, 57600L, 115200L)
  10. *  int parity;          - Parity: P_NONE, P_ODD, P_EVEN, P_S_STICK, P_M_STICK
  11. *  int stopbits;        - 1 or 2
  12. *  int wordlength;      - Number of Data Bits: 5,6,7, or 8
  13. *
  14. *  Note:  If wordlength=5 and stopbits=2, actual # stopbits will be 1.5
  15. *
  16. * DESCRIPTION
  17. *  setup operating parameters for an asynchronous communications port.
  18. *
  19. * SIDE EFFECTS
  20. *  none
  21. *
  22. * RETURNS
  23. *
  24. *       Value           Meaning
  25. *     -------          --------
  26. *       ASSUCCESS       port initialized (no error)
  27. *       ASINVPORT       Requested port is out of range
  28. *       ASNOTSETUP      Requested port not setup with asifirst()
  29. *       ASINVPAR        Invalid parameter
  30. *
  31. * MODIFICATIONS
  32. *
  33. *  10-29-85     ""
  34. *               Modified for release 2.0
  35. *
  36. *  Mon 05-Jun-1989 13:55:02
  37. *       Added support for 38, 56 and 115 Kbaud.
  38. */
  39. #include <stdio.h>
  40. #include "gf.h"
  41. #include "asiports.h"
  42.  
  43. int GF_CONV asiinit( port,baud,parity,stopbits,wordlength )
  44. int port;
  45. long baud;
  46. int parity,stopbits,wordlength;
  47. {
  48.         struct PORT_TABLE *p;
  49.         int divisor;
  50.  
  51.         if((p=_aschkcnl(port))==NULL)
  52.                 return(_aserror);
  53.         if(wordlength<5 || wordlength>8)
  54.                 return(ASINVPAR);
  55.         else
  56.                 wordlength-=5;
  57.         switch (parity) {
  58.                 case P_NONE:
  59.                         parity=0;
  60.                         break;
  61.                 case P_ODD:
  62.                         parity=8;               /* odd */
  63.                         break;
  64.                 case P_EVEN:
  65.                         parity=0x18;            /* even */
  66.                         break;
  67.                 case P_S_STICK:
  68.                         parity=0x28;            /* stick space 0 */
  69.                         break;
  70.                 case P_M_STICK:
  71.                         parity=0x38;            /* stick mark 1 */
  72.                         break;
  73.                 default:
  74.                         return(ASINVPAR);
  75.         }
  76.         switch (stopbits) {
  77.                 case 1:
  78.                         stopbits=0;
  79.                         break;
  80.                 case 2:
  81.                         stopbits=4;
  82.                         break;
  83.                 default:
  84.                         return(ASINVPAR);
  85.         }
  86.         if (baud < 10 || baud > 115200L)
  87.             return(ASINVPAR);
  88.         divisor = ( int ) ( 115200L / baud ) ;
  89.         return _asiinit(p->base_8250,divisor,parity|stopbits|wordlength);
  90. }
  91.