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