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 / ASIOPEN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-14  |  3.2 KB  |  93 lines

  1. /* asiopen.c
  2. *
  3. * The Greenleaf Comm Library
  4. *
  5. * Copyright (C) 1985-1990 Greenleaf Software Inc.  All Rights Reserved.
  6. *
  7. *  int asiopen( port, mode, rxlen, txlen, baud, parity, stopbits,
  8. *            wordlength, dtr, rts)
  9. *
  10. *  int  port;   - Port 0..MAX_PORT-1
  11. *  unsigned mode;       - Merged options for mode (see below)
  12. *  int rxlen;           - Length of Rx Buffer in bytes
  13. *  int txlen;           - Length of Tx Buffer in bytes
  14. *  long baud;           - Baud Rate (50L-9600L,19000L, 38400L, 57600L, 115200L)
  15. *  int parity;          - P_NONE,P_ODD,P_EVEN,P_S_STICK, P_M_STICK
  16. *  int stopbits;        - Number of stop bits:  1 or 2
  17. *  int wordlength;      - Number of Data Bits:  5,6,7, or 8
  18. *  int dtr;             - Initial State for DTR (ON or OFF)
  19. *  int rts;             - Initial State for RTS (ON or OFF)
  20. *
  21. *  "mode" specifies five different kinds of operational parameters.
  22. *  Choose one from each of the following five categories.  See documentation
  23. *  for further details:
  24. *       1.  Direction (ASIN, ASOUT, ASINOUT)
  25. *       2.  Data Type (BINARY, ASCII)
  26. *       3.  Receive Buffer Width (NORMALRX, WIDETRACKRX)
  27. *
  28. * DESCRIPTION
  29. *  This function performs all operations required to initialize a
  30. *  port, including the following:
  31. *       asifirst()      - Setup the buffers for the port, allocation
  32. *       asiinit()       - Initialize UART
  33. *       asdtr()         - Setup DTR initial state
  34. *       asrts()         - Setup RTS initial state
  35. *       asistart()      - Start interrupts running
  36. *
  37. *  The above functions are called internally in this "one-stop" combination
  38. *  function.
  39. *
  40. * SIDE EFFECTS
  41. *  None.
  42. *
  43. * RETURNS
  44. *
  45. *       Value           Meaning
  46. *     -------          --------
  47. *       ASSUCCESS       port opened (no errors)
  48. *       ASNOMEMORY      Cannot allocate dynamic memory needed
  49. *       ASINVPORT       Requested logical port number too high or too low
  50. *       ASINUSE         port has already been setup with asifirst()
  51. *       ASINVBUFSIZE    Buffer size is out of range
  52. *       ASNO8250        No 8250 installed at requested i/o address
  53. *
  54. * MODIFICATIONS
  55. *  10-29-85     ""
  56. *               Modified for new structure members, also moved static
  57. *               data items to this file.
  58. */
  59. #include <stdio.h>
  60. #include "gf.h"
  61. #include "asiports.h"
  62.  
  63. int GF_CONV asiopen(port,mode,size_rx_buf,size_tx_buf,baud,parity,stopbits,
  64.             wordlength,dtr,rts)
  65. int port;
  66. long baud;
  67. int parity,stopbits,wordlength,dtr,rts;
  68. unsigned size_tx_buf,size_rx_buf,mode;
  69. {
  70.         int terror;
  71.  
  72.         if((terror=asifirst(port,mode,size_rx_buf,size_tx_buf))!=ASSUCCESS)
  73.                 return(terror);
  74.         if((terror=asiinit(port,baud,parity,stopbits,wordlength))!=ASSUCCESS){
  75.                 (void)asiquit(port);
  76.                 return(terror);
  77.         }
  78.         if((terror=asistart(port,mode&(ASIN|ASOUT|ASINOUT)) )!=ASSUCCESS) {
  79.                 (void)asiquit(port);
  80.                 return(terror);
  81.         }
  82.         if((terror=asdtr(port,dtr)) < ASSUCCESS) {
  83.                 (void)asiquit(port);
  84.                 return(terror);
  85.         }
  86.         if((terror=asrts(port,rts)) < ASSUCCESS) {
  87.                 (void)asiquit(port);
  88.                 return(terror);
  89.         }
  90.         return(ASSUCCESS);
  91. }
  92.  
  93.