home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / MCOMM530.ZIP / COMM.H < prev    next >
C/C++ Source or Header  |  1990-07-08  |  11KB  |  201 lines

  1.  
  2. /****************************************************************************
  3.  COMM.H -- header file for C programs using MCOMM5 Async Lib
  4.    Mike Dumdei,  6 Holly Lane,  Texarkana TX  75503    (c) 1989,1990
  5. ****************************************************************************/
  6.  
  7. #if !defined(MCOMM)
  8. #define _C_ cdecl
  9. #define _N_ near
  10. #define _F_ far
  11. #define MCOMM
  12. #endif
  13.  
  14. /*  ---- Return codes ----  */
  15. #define         R_OK           0x0000
  16. #define         R_NOMEM        0x0001
  17. #define         R_BAUDERR      0x0002
  18. #define         R_PARITYERR    0x0004
  19. #define         R_DTABITERR    0x0008
  20. #define         R_STPBITERR    0x0010
  21. #define         R_IRQUSED      0x0020
  22. #define         R_VCTRUSED     0x0040
  23. #define         R_NOPORT       0x0080
  24. #define         R_PORTUSED     0x0100
  25.  
  26. #define         R_TXERR        0xffff
  27.  
  28. /* ---- Interrupt bit masks ---- */
  29. #define         IRQ3         0x08
  30. #define         IRQ4         0x10
  31.  
  32. /* ---- Vector numbers ---- */
  33. #define         VCTR3          11
  34. #define         VCTR4          12
  35.  
  36. /* ---- Standard Comm Ports ---- */
  37. #define         COM1        0x3f8, 0x10, 12
  38. #define         COM2        0x2f8, 0x08, 11
  39.  
  40. /* ---- Defines for Async_regs() ---- */
  41. #define         RXreg       0
  42. #define         TXreg       0
  43. #define         IERreg      1
  44. #define         IIDreg      2
  45. #define         FCRreg      2
  46. #define         LCRreg      3
  47. #define         MCRreg      4
  48. #define         LSRreg      5
  49. #define         MSRreg      6
  50. #define         LObaud      0
  51. #define         HIbaud      1
  52. #define         RDreg      (-1)
  53.  
  54. /* ---- Miscellaneous bits ---- */
  55. #define         B_DTR        0x0001
  56. #define         B_RTS        0x0002
  57.  
  58. /*  ---- Status bit masks ----  */
  59.                         /*    S T A T 2    */
  60. #define         B_XUSE       0x0001         /* using XON/XOFF protocol bit */
  61. #define         B_XRXD       0x0002                   /* XOFF received bit */
  62. #define         B_XSENT      0x0004                       /* XOFF sent bit */
  63. #define         B_TXEMPTY    0x0008             /* nothing to transmit bit */
  64. #define         B_CTS        0x0010                   /* clear to send bit */
  65. #define         B_DSR        0x0020                  /* data set ready bit */
  66. #define         B_FLOWHALT   0x0040             /* flow halt indicator bit */
  67. #define         B_MNTR_CD    0x0080                      /* monitor CD bit */
  68.  
  69.                         /*    S T A T 1    */
  70. #define         B_RXOVF      0x0100        /* rx buffer overflow indic bit */
  71. #define         B_OVERRUN    0x0200              /* char overrun error bit */
  72. #define         B_PARITY     0x0400                    /* parity error bit */
  73. #define         B_FRAMING    0x0800                   /* framing error bit */
  74. #define         B_BREAK      0x1000          /* line break signal detected */
  75. #define         B_BADPORT    0x2000                        /* bad port bit */
  76. #define         B_RXEMPTY    0x4000                 /* rx buffer empty bit */
  77. #define         B_CD         0x8000             /* carrier detect bit mask */
  78.  
  79.                         /*    S T A T 3    */
  80. #define         B_IGNERR     0x0001  /* discard chars with par, frm'g errs */
  81. #define         B_16550      0x0002                      /* 16550 detected */
  82. #define         B_FIFO       0x0004                 /* 16550 FIFOs enabled */
  83. #define         B_ORGFIFO    0x0008  /* FIFOs were on when port was opened */
  84. #define         B_XUSET      0x0020     /* using XON/XOFF on txmt side bit */
  85. #define         B_XUSER      0x0040     /* using XON/XOFF on recv side bit */
  86. #define         B_XONANY     0x0080          /* accept any char for an XON */
  87.  
  88.  
  89. /*  ----  P O R T   S T R U C T U R E   ---- */
  90.  
  91. #pragma pack(1)      /* be sure and use byte align to reference port struc */
  92.  
  93. typedef struct
  94. {
  95.     int ComBase;                     /* base port address of for comm port */
  96.     char IRQMask;                        /* mask for IRQ used by this port */
  97.     char Vector;                     /* interrupt vector used by this port */
  98.     char BPDSstr[10];               /* current baud,parity,data,stop parms */
  99.     int RxSize;                                    /* size of receive bufr */
  100.     int TxSize;                                   /* size of transmit bufr */
  101.     int RingSeg;              /* segment of rx/tx bufrs (leave 0 for NEAR) */
  102.     int RingOfst;                    /* offset of rx/tx bufrs, alias TxTop */
  103.     int RxTop;                     /* ptr to begin of rx bufr, alias TxBtm */
  104.     int RxBtm;                          /* ptr to end of rx bufr (end + 1) */
  105.     int TxIn;                              /* ptr to where next 'put' goes */
  106.     int TxOut;                        /* ptr to where next tx'd comes from */
  107.     int TxFree;                                 /* remaining tx bufr space */
  108.     int RxIn;                           /* pointer to where next rx'd goes */
  109.     int RxOut;                       /* ptr to where next 'get' comes from */
  110.     int RxFree;                        /* remaining bytes in rx bufr space */
  111.     int BaudDvsr;                                     /* baud rate divisor */
  112.     int XoffTrip;          /* send XOFF when this many bytes left in rxbuf */
  113.     int XonTrip;            /* send XON when this many bytes left in rxbuf */
  114.     int OldVctrOfst;          /* OFST address of original interrupt vector */
  115.     int OldVctrSeg;            /* SEG address of original interrupt vector */
  116.     int OldDvsr;                    /* original value of Baud Divisor Regs */
  117.     char Stat2;                                   /* secondary status byte */
  118.     char Stat1;                                     /* primary status byte */
  119.     char TxStat;              /* determines when tx_intrpts need turned on */
  120.     char MSRMask;               /* slcts bits in MSR montrd for flow cntrl */
  121.     char MSRVal;                 /* present value of modem status register */
  122.     char Stat3;                      /* another flag, used for XONANY char */
  123.     char PDSinfo;                       /* parity, # dta bits, # stop bits */
  124.     char StripMask;                         /* mask for high bit stripping */
  125.     char XTxRptInit;              /* initialization value for XTxRpt below */
  126.     char XTxRpt;                   /* countdown val befr repeat tx of XOFF */
  127.     char TxImmedChar;                   /* char to be tx'd 1st opportunity */
  128.     char HdlrUsed;             /* assigned interrupt handler for this port */
  129.     char Old8259Msk;                       /* original 8259 interrupt mask */
  130.     char OldLCR;                        /* original Line Control Reg value */
  131.     char OldMCR;                         /* original Modem Cntrl Reg value */
  132.     char OldIER;                    /* original Interrupt Enable Reg value */
  133.     int TxByteCnt;                /* number bytes to send per tx interrupt */
  134.     char FCRVal;                        /* FIFO control register data byte */
  135. /*
  136.         Anything you want to add to this structure, such as a FILE *
  137.         associated with the port, status flags, buffer pointers, etc.,
  138.         can be added here at the bottom of the primary structure and
  139.         accessed through the same pointer used for the port.
  140. */
  141. } ASYNC;
  142.  
  143. #pragma pack()                      /* back to default structure alignment */
  144.  
  145.  
  146. /* ---- F U N C T I O N   D E C L A R A T I O N S  ---- */
  147. int _C_ async_open(ASYNC *, int, int, int, char *);     /* open async port */
  148. void _C_ async_close(ASYNC *);                         /* close async port */
  149. int _C_ async_tx(ASYNC *, char);                     /* transmit character */
  150. int _C_ async_txblk(ASYNC *, char *, int);             /* transmit a block */
  151. int _C_ async_rx(ASYNC *);                          /* receive a character */
  152. int _C_ async_rxblk(ASYNC *, char *, int);              /* receive a block */
  153. int _C_ async_rxblkch(ASYNC *, char *, int, char, int);/* rx blk till char */
  154. int _C_ async_stat(ASYNC *, int);                 /* get stat1/stat2 bytes */
  155. int _C_ async_setbpds(ASYNC *, char *);          /* change line parameters */
  156. void _C_ async_rxflush(ASYNC *);               /* flush the receive buffer */
  157. void _C_ async_txflush(ASYNC *);              /* flush the transmit buffer */
  158. void _C_ async_msrflow(ASYNC *, int);      /* set MSR related tx flw cntrl */
  159. void _C_ async_xflow(ASYNC *, int);              /* XON/OFF protocl on/off */
  160. void _C_ async_xoffclr(ASYNC *);                 /* manually clr XOFF rx'd */
  161. void _C_ async_xoffset(ASYNC *);                 /* manually set XOFF rx'd */
  162. void _C_ async_dtr(ASYNC *, int);                            /* DTR on/off */
  163. void _C_ async_rts(ASYNC *, int);                            /* RTS on/off */
  164. void _C_ async_sndbrk(ASYNC *, int);          /* Set/clr tx modem brk sgnl */
  165. void _C_ async_stop(ASYNC *);                 /* halts interrupt operation */
  166. void _C_ async_restart(ASYNC *);    /* re-initializes an already open port */
  167. int _C_ async_peek(ASYNC *, int);        /* peek indexed char in rx buffer */
  168. int _C_ async_regs(ASYNC *, int, int);   /* direct read/write of port regs */
  169. void _C_ async_FIFOrxlvl(ASYNC *, int);       /* set rx FIFO trigger level */
  170. void _C_ async_FIFOtxlvl(ASYNC *, int);/* set max bytes sent per tx intrpt */
  171. int _C_ AllocRingBuffer(ASYNC *, int, int, int);     /* alloc ring buffers */
  172.  
  173. /* ---- M A C R O   I M P L E M E N T E D   F U N C T I O N S   ---- */
  174.  /* Stat1 is also high byte of async_rx() return value for chks while rx'g */
  175. #define async_breakrxd(x) ((x)->Stat1 & '\x10')       /* rx'd break signal */
  176. #define async_reset(x)   ((x)->Stat1 &= '\xe0') /* rset rx error condition */
  177. #define async_rxerr(x)   ((x)->Stat1 & '\x0f')     /* rx err cond detected */
  178.  
  179. #define async_rxcnt(x)   ((x)->RxSize - (x)->RxFree) /* get bytes in rxbuf */
  180. #define async_txfree(x)  ((x)->TxFree)          /* get bytes free in txbuf */
  181. #define async_txempty(x) ((x)->TxStat & '\x08')           /* tx bufr empty */
  182.  
  183. #define async_strip(x,y) ((x)->StripMask = (y))  /* set bit stripping mask */
  184.  
  185. #define async_xuse(x)    ((x)->Stat2 & '\x01')   /* test if using XON/XOFF */
  186. #define async_xuset(x)   ((x)->Stat3 & '\x20') /* tst using XON/XOFF on tx */
  187. #define async_xuser(x)   ((x)->Stat3 & '\x40') /* tst using XON/XOFF on rx */
  188. #define async_xany(x)    ((x)->Stat3 & '\x80')       /* all chars are XONs */
  189. #define async_xtxd(x)    ((x)->Stat2 & '\x04')                /* XOFF sent */
  190. #define async_xrxd(x)    ((x)->TxStat & '\x02')           /* XOFF received */
  191.  
  192. #define async_msr(x)     ((x)->MSRVal)        /* get modem status register */
  193. #define async_cts(x)     ((x)->MSRVal & '\x10')   /* Clear to Send is high */
  194. #define async_dsr(x)     ((x)->MSRVal & '\x20')    /* Data Set Rdy is high */
  195. #define async_carrier(x) ((x)->MSRVal & '\x80')    /* fast chk for carrier */
  196. #define async_16550(x)   ((x)->Stat3 & '\x02')           /* 16550 detected */
  197.  
  198.  /* set/clr bit that controls handling of chars with parity or frame errs */
  199. #define async_ignerr(x,y) ((y) ? ((x)->Stat3 |= 1) : ((x)->Stat3 &= '\xfe'))
  200.      
  201.