home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / asycnch / asynch.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-01  |  3.3 KB  |  120 lines

  1. #if !defined(ASYNCH_INCLUDED)    /* Prevent multiple includes */
  2. #define ASYNCH_INCLUDED
  3. #include "circleq.h"
  4. typedef    unsigned char    byte;
  5. typedef unsigned short  word;
  6. typedef unsigned long    dword;
  7. typedef struct _lcr
  8. {
  9.     word    databits    : 2;
  10.     word    stopbits    : 1;
  11.     word    parity        : 2;
  12.     word    stuckparity    : 1;
  13.     word    breakenable     : 1;
  14.     word    dlab         : 1;
  15. } lcr;
  16. typedef struct _uart
  17. {
  18.     word     addr;
  19.     byte     irqline;
  20.     word     baud;
  21.     byte     lstat;
  22.  
  23.     byte     mstat;
  24.     byte     status;
  25.     byte    break_length;
  26.     byte    parms;
  27.     CircleQ *InBuffer;
  28.     CircleQ *OutBuffer;
  29.     void interrupt (*oldisr)();
  30. } uart;
  31. #define LineStatus(n) ((n >= 0 && n <4)  ? cports[n].lstat : EINVPORT)
  32. #define ModemStatus(n) ((n >= 0 && n <4)  ? cports[n].mstat : EINVPORT)
  33.  
  34. extern uart cports[4];
  35. #define COM1_DEFAULTS\
  36.     {0x3F8,4,0,0,0,0,250,\
  37.     DATA8|STOP1|NONE,\
  38.     NULL,NULL}
  39.  
  40. #define COM2_DEFAULTS \
  41.     {0x2F8,3,0,0,0,0,250,\
  42.     DATA8|STOP1|NONE,\
  43.     NULL,NULL}
  44.  
  45. #define PIC    0x20            /* 8259A PIC Address */
  46. #define IRQINT(n) ((n < 9) ? n+8 : (n-9)+0x70)
  47.                     /* Make int value from IRQ */
  48. #define IID(n)    (n & 7)         /* Get Interrupt ID from reg val */
  49. /*
  50.  * Define Interrupt ID values from the interrupt ID register
  51. */
  52. #define IID_PENDING    0x01
  53. #define IID_LSTAT    0x00            /* Line status change */
  54. #define IID_DATA    0x02            /* Data is available from 8250 */
  55. #define IID_TEMPTY    0x04            /* Transmitter buffer empty */
  56. #define IID_MSTAT    0x06            /* New modem status */
  57. #define IID_MASK    0x07
  58.  
  59. #define IIV_LSTAT    0x01
  60. #define IIV_XMITE    0x02
  61. #define IIV_RDATA    0x04
  62. #define IIV_MSTAT    0x08
  63. /*
  64.  * Define some offsets from the UART base address for various registers
  65. */
  66. #define XMT_REG        0x00        /* Transmitter holding buffer */
  67. #define RCV_REG        0x00        /* Reciever holding buffer */
  68. #define DIV_LOW        0x00        /* Divisor low byte when DLAB=1 */
  69. #define DIV_HI        0x01        /* Devisor high byte when DLAB=1 */
  70.  
  71. #define IE_REG        0x01        /* Interrupt enable register */
  72. #define IID_REG        0x02        /* Interrupt ID register */
  73. #define LCR_REG        0x03        /* line control register */
  74. #define MCR_REG        0x04        /* Modem control register */
  75. #define LSR_REG        0x05        /* line status register */
  76. #define MSR_REG        0x06        /* modem status register */
  77.  
  78. /*
  79.  *    Stuff for the line control register
  80. */
  81. #define NONE    0x00            /* No Parity */
  82. #define ODD    0x08            /* Odd Parity */
  83. #define EVEN    0x18            /* Even Parity */
  84. #define STOP1    0x00            /* Need I explain these? */
  85. #define STOP2    0x04
  86. #define DATA5    0x00
  87. #define DATA6    0x01
  88. #define DATA7    0x02
  89. #define DATA8    0x03
  90. #define DLAB    0x80
  91.  
  92. #define UARTIEMASK    0x08        /* Mask used to enable interrupts on
  93.                        the 8250 OUT2 line */
  94. #define PS_ENABLED    0x01
  95. #define PS_INTERRUPT    0x02        /* Not used */
  96.  
  97. enum errors {EPORTNOTOPEN=1,EPORTALREADYOPEN,EINVBAUDRATE,EINVPORT,EMEMALLOC};
  98. #define COM1    0
  99. #define COM2    1
  100. #define ON    1
  101. #define OFF    0
  102. #define HIBYTE(n) ((n >> 8) & 0xFF)
  103. #define LOBYTE(n) (n & 0xFF)
  104.  
  105. #if !defined(dim)
  106. #define dim(x) (sizeof(x)/sizeof(x[0]))
  107. #endif
  108. int SetPortParms(int PortNo, int Baud, int Parity, int Data, int Stop,
  109.           int Base, int IRQ, int BreakLength);
  110. int copen(int PortNo, int BufSiz, int Baud, int Parity, int Data, int Stop,
  111.           int Base, int IRQ, int BreakLength);
  112. int cclose(int PortNo);
  113. int InitBaud(int PortNo);
  114. SetPIC(int PortNo, int State);
  115. cgetc(int PortNo);
  116. cputc(int PortNo, char Ch);
  117.  
  118. #endif
  119.  
  120.