home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / cport13 / cport.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-31  |  7.5 KB  |  325 lines

  1. /*
  2. // CPORT.H
  3. //
  4. // Header file for Cport Communications Library
  5. //
  6. // Copyright (c) 1991 Bri Productions
  7. //
  8. */
  9.  
  10. #if defined  __TURBOC__
  11. #if  __STDC__
  12. #define  _Cdecl
  13. #else
  14. #define  _Cdecl  cdecl
  15. #endif
  16. #elif defined  __ZTC__
  17. #define  _Cdecl
  18. #elif defined  M_I86 && !defined  __ZTC__
  19. #if !defined NO_EXT_KEYS
  20. #define  _Cdecl  cdecl
  21. #else
  22. #define  _Cdecl
  23. #endif
  24. #endif
  25.  
  26.  
  27.  
  28. /*
  29. //-------------------------------------
  30. //
  31. // com ports
  32. //
  33. //-------------------------------------
  34. */
  35.  
  36. #define  PORT0 0x03F8
  37. #define  PORT1 0x02F8
  38. #define  PORT2 0x03E8
  39. #define  PORT3 0x02E8
  40.  
  41. #define  IRQ2  0xA000
  42. #define  IRQ3  0xB000
  43. #define  IRQ4  0xC000
  44. #define  IRQ5  0xD000
  45. #define  IRQ6  0xE000
  46. #define  IRQ7  0xF000
  47.  
  48. #define  COM1  (PORT0 | IRQ4)
  49. #define  COM2  (PORT1 | IRQ3)
  50. #define  COM3  (PORT2 | IRQ4)
  51. #define  COM4  (PORT3 | IRQ3)
  52.  
  53. #define  BIOS0 (*(int far *)0x400000l)
  54. #define  BIOS1 (*(int far *)0x400002l)
  55. #define  BIOS2 (*(int far *)0x400004l)
  56. #define  BIOS3 (*(int far *)0x400006l)
  57.  
  58.  
  59. /*
  60. //-------------------------------------
  61. //
  62. // baud rate divisors
  63. //
  64. //-------------------------------------
  65. */
  66.  
  67. #define  B115200  1
  68. #define  B57600   2
  69. #define  B38400   3
  70. #define  B19200   6
  71. #define  B9600    12
  72. #define  B7200    16
  73. #define  B4800    24
  74. #define  B3600    32
  75. #define  B2400    48
  76. #define  B2000    58
  77. #define  B1800    64
  78. #define  B1200    96
  79. #define  B600     192
  80. #define  B300     384
  81. #define  B150     768
  82. #define  B110     1047
  83. #define  B75      1536
  84. #define  B50      2304
  85.  
  86.  
  87.  
  88. /*
  89. //-------------------------------------
  90. //
  91. // word lengths
  92. //
  93. //-------------------------------------
  94. */
  95.  
  96. #define  W8    3
  97. #define  W7    2
  98. #define  W6    1
  99. #define  W5    0
  100. #define  WMASK 3
  101.  
  102.  
  103.  
  104. /*
  105. //-------------------------------------
  106. //
  107. // stop bits
  108. //
  109. //-------------------------------------
  110. */
  111.  
  112. #define  S1    0
  113. #define  S2    4
  114. #define  SMASK 1
  115.  
  116.  
  117.  
  118. /*
  119. //-------------------------------------
  120. //
  121. // parity
  122. //
  123. //-------------------------------------
  124. */
  125.  
  126. #define  NONE     0x00
  127. #define  ODD      0x08
  128. #define  EVEN     0x18
  129. #define  MARK     0x28
  130. #define  SPACE    0x38
  131. #define  PMASK    0x38
  132.  
  133.  
  134.  
  135. /*
  136. //-------------------------------------
  137. //
  138. // handshaking
  139. //
  140. //-------------------------------------
  141. */
  142.  
  143. #define  DTR      0x01
  144. #define  RTS      0x02
  145. #define  S_RX     0x04
  146. #define  S_TX     0x08
  147. #define  CTS      0x10
  148. #define  DSR      0x20
  149. #define  DCD      0x80
  150.  
  151. #define  SOFT     ((S_RX) | (S_TX))
  152. #define  HARD     ((RTS)| (CTS))
  153. #define  HARD1    ((DTR)| (DSR))
  154. #define  HARD2    ((RTS)| (CTS))
  155.  
  156.  
  157.  
  158. /*
  159. //-------------------------------------
  160. //
  161. // error codes
  162. //
  163. //-------------------------------------
  164. */
  165.  
  166. #define  OVERUN    0x002         /* overrun error           */
  167. #define  PARITY    0x004         /* parity error            */
  168. #define  FRAMING   0x008         /* framing error           */
  169. #define  BREAK     0x010         /* break detect            */
  170. #define  RX_FIFO   0x080         /* error in recieve fifo   */
  171. #define  TXFULL    0x100         /* transmit queue overflow */
  172. #define  RXFULL    0x200         /* receive queue overflow  */
  173.  
  174.  
  175.  
  176. /*
  177. //-------------------------------------
  178. //
  179. // status codes
  180. //
  181. //-------------------------------------
  182. */
  183.  
  184. #define  DCTS  0x01           /* delta clear to send           */
  185. #define  DDSR  0x02           /* delta data set ready          */
  186. #define  TERI  0x04           /* trailing edge ring  indicator */
  187. #define  DDCD  0x08           /* delta data carrier detect     */
  188. #define  CTS   0x10           /* clear to send                 */
  189. #define  DSR   0x20           /* data set ready                */
  190. #define  RI    0x40           /* ring indicator                */
  191. #define  DCD   0x80           /* data carrier detect           */
  192.  
  193.  
  194.  
  195. /*
  196. //-------------------------------------
  197. //
  198. // byte typedef and parameter structure
  199. //
  200. //-------------------------------------
  201. */
  202.  
  203. #ifndef BYTE
  204. #define BYTE
  205. typedef unsigned char byte;
  206. #endif
  207.  
  208.    /** Do not change this structure **/
  209.  
  210. struct C_param{
  211.    unsigned com;              /* com port                         */
  212.    int      baud;             /* baud rate                        */
  213.    byte     mode;             /* word length, stop bits, parity   */
  214.    unsigned rxQ;              /* receive queue size               */
  215.    unsigned txQ;              /* transmit queue size              */
  216.    byte     htype;            /* handshaking type                 */
  217.    unsigned thresh;           /* handshaking threshold (rx queue) */
  218.    };
  219.  
  220.  
  221.  
  222. /*
  223. //-------------------------------------
  224. //
  225. // some other constants
  226. //
  227. //-------------------------------------
  228. */
  229.  
  230. #define  ON    1
  231. #define  OFF   0
  232.  
  233.  
  234.  
  235. /*
  236. //-------------------------------------
  237. //
  238. // ComOpen return codes
  239. //
  240. //-------------------------------------
  241. */
  242.  
  243. #define  NO_ERR   0        /* no error                         */
  244. #define  OPENED   1        /* port already opened              */
  245. #define  BAD_COM  2        /* bad 'com' parameter              */
  246. #define  NO_UART  3        /* no uart chip found               */
  247. #define  RCV_ALC  4        /* receive queue allocation error   */
  248. #define  TX_ALC   5        /* transmit queue allocation error  */
  249. #define  MAX_PORT 6        /* max number of com ports opened   */
  250. #define  IRQ_CTN  7        /* interrupt contention             */
  251. #define  NOT_OPEN 8        /* com not opened (ComActive)       */
  252.  
  253.  
  254. /*
  255. //-------------------------------------
  256. //
  257. // function macros
  258. //
  259. //-------------------------------------
  260. */
  261.  
  262. #define  ComOut1(a)           ComMcr(a, 0x04)
  263. #define  ComRts(a)            ComMcr(a, 0x02)
  264. #define  ComDtr(a)            ComMcr(a, 0x01)
  265.  
  266.  
  267.  
  268. /*
  269. //-------------------------------------
  270. //
  271. // function prototypes
  272. //
  273. //-------------------------------------
  274. */
  275.  
  276.    /* control functions */
  277.  
  278. int      _Cdecl   ComOpen        (unsigned com, int baud, byte mode, unsigned rxQ, unsigned txQ);
  279. int      _Cdecl   ComOpenS       (const struct C_param *param);
  280. void     _Cdecl   ComParam       (const struct C_param *param);
  281. void     _Cdecl   ComClose       (void);
  282. void     _Cdecl   ComBaud        (int baud);
  283. void     _Cdecl   ComMode        (byte mode);
  284. void     _Cdecl   ComHandshake   (byte htype, unsigned thresh);
  285. void     _Cdecl   ComTx          (byte on_off);
  286. int      _Cdecl   ComActive      (unsigned com);
  287. void     _Cdecl   ComCloseAll    (void);
  288.  
  289.    /* input functions    */
  290.  
  291. char     _Cdecl   ComGetc        (void);
  292. char    *_Cdecl   ComGets        (char *str, int max_c, char term_c);
  293. unsigned _Cdecl   ComIn          (void *abyte, unsigned n_byte);
  294. char     _Cdecl   ComPeek        (void);
  295. unsigned _Cdecl   ComLenRx       (void);
  296. void     _Cdecl   ComFlushRx     (void);
  297.  
  298.  
  299.    /* output functions  */
  300.  
  301. int      _Cdecl   ComPutc        (char c);
  302. int      _Cdecl   ComPuts        (const char *str);
  303. unsigned _Cdecl   ComOut         (const void *abyte, unsigned n_byte);
  304. unsigned _Cdecl   ComLenTx       (void);
  305. void     _Cdecl   ComFlushTx     (void);
  306.  
  307.  
  308.    /* status functions  */
  309.  
  310. void     _Cdecl   ComMcr         (byte on_off, byte bits);
  311. unsigned _Cdecl   ComError       (void);
  312. byte     _Cdecl   ComStatus      (void);
  313.  
  314.  
  315.    /* misc fuctions  */
  316.  
  317. void     _Cdecl   ComSetBreak    (void);
  318. void     _Cdecl   ComClrBreak    (void);
  319. void     _Cdecl   ComPutScrtch   (byte abyte);
  320. byte     _Cdecl   ComGetScrtch   (void);
  321.  
  322.  
  323. byte     _Cdecl   ComChecksum    (const void *abyte, unsigned n_byte);
  324. unsigned _Cdecl   ComCrc16       (const void *abyte, unsigned n_byte);
  325.