home *** CD-ROM | disk | FTP | other *** search
/ PC Media 7 / PC MEDIA CD07.iso / share / prog / asyncmsc / async.h next >
Encoding:
C/C++ Source or Header  |  1993-03-15  |  6.9 KB  |  189 lines

  1. #ifndef ASYNC_H
  2. #define ASYNC_H
  3.  
  4. #include <timing.h>
  5. #include <vid.h>
  6.  
  7. #ifndef EXTERN
  8. #define EXTERN extern
  9. #endif
  10.  
  11. #ifdef _TURBOC
  12. #define INP inportb
  13. #define OUTP outportb
  14. #endif
  15.  
  16. #ifdef _ZOR
  17. #define INP inp
  18. #define OUTP outp
  19. #endif
  20.  
  21. #ifdef _MSC
  22. #define INP inp
  23. #define OUTP outp
  24. #endif
  25.  
  26. #define MAXPORTS 4
  27.  
  28. #define port1 0              /* COM1                        */
  29. #define port2 1              /* COM2                        */
  30. #define port3 2              /* COM3                        */
  31. #define port4 3              /* COM4                        */
  32.  
  33. /*┌────────────────────────────────────────────────────────────────────┐*/
  34. /*│                                                                    │*/
  35. /*│                 COMMUNICATIONS HARDWARE ADDRESSES                  │*/
  36. /*│                                                                    │*/
  37. /*│       These are specific to IBM PCs and close compatibles.         │*/
  38. /*└────────────────────────────────────────────────────────────────────┘*/
  39.  
  40. #define UART_THR     0x00  /* offset from base of UART Registers for IBM PC */
  41. #define UART_RBR     0x00  /* receive buffer            */
  42. #define UART_IER     0x01  /* interupt enable register  */
  43. #define UART_IIR     0x02  /* interupt identification register */
  44. #define UART_FCR     0x02  /* fifo buffer               */
  45. #define UART_LCR     0x03  /* line control register     */
  46. #define UART_MCR     0x04  /* modem control register    */
  47. #define UART_LSR     0x05  /* line status register      */
  48. #define UART_MSR     0x06  /* modem status register     */
  49. #define UART_SCR     0x07  /* UART scratch buffer on NS16550 type */
  50.  
  51. #define I8088_IMR    0x21  /* port address of the Interrupt Mask Register */
  52.    /*  for the 8059             */
  53.  
  54. #define COM1_Base    0x03F8 /* port addresses for the UART */
  55. #define COM2_Base    0x02F8
  56. #define COM3_Base    0x03E8 /* port addresses for the UART */
  57. #define COM4_Base    0x02E8
  58.  
  59. #define UART_LSR1    0x03FD /* address of line status register for COM1 */
  60. #define UART_LSR2    0x02FD /* address of line status register for COM2 */
  61. #define UART_LSR3    0x03ED /* address of line status register for COM3 */
  62. #define UART_LSR4    0x02ED /* address of line status register for COM4 */
  63.  
  64. #define UART_IIR1    0x03FA /* address of line status register for COM1 */
  65. #define UART_IIR2    0x02FA /* address of line status register for COM2 */
  66. #define UART_IIR3    0x03EA /* address of line status register for COM3 */
  67. #define UART_IIR4    0x02EA /* address of line status register for COM4 */
  68.  
  69. #define COM1_Irq  12          /* Interrupt line for the UART */
  70. #define COM2_Irq  11
  71. #define COM3_Irq  12          /* Interrupt line for the UART */
  72. #define COM4_Irq  11
  73.  
  74. #define MaxInt 65535
  75. #define MAXRECV 32766
  76. #define MAXSEND 65534
  77.  
  78. #define ERR -1
  79. #define FALSE 0
  80. #define TRUE  1
  81. #define TIMEOUT  -1              /* TimeOut value                   */
  82.  
  83. #define RCVERR      6
  84. #define XMITINT     2
  85. #define RCVINT      4
  86. #define FIFOTIMEOUT 0x0c
  87. #define THRE        0x20
  88.  
  89. typedef enum tagBAUD{B110,B150,B300,B600,B1200,B2400,B4800,B9600,B19200,
  90.                           B38400,B57600,B115K,Async_Num_Bauds}BAUD;
  91.                           
  92.  
  93. /*┌────────────────────────────────────────────────────────────────────┐*/
  94. /*│                                                                    │*/
  95. /*│                  COMMUNICATIONS BUFFER VARIABLES                   │*/
  96. /*│                                                                    │*/
  97. /*│    The Communications Buffers are implemented as a circular (ring) │*/
  98. /*│    buffer, or double-ended queue.  The asynchronous I/O routines   │*/
  99. /*│    enter characters in the buffer as they are received.  Higher-   │*/
  100. /*│    level routines may extract characters from the buffer.          │*/
  101. /*│                                                                    │*/
  102. /*│    Note that this buffer is used for input only;  output is done   │*/
  103. /*│    on a character-by-character basis.                              │*/
  104. /*│                                                                    │*/
  105. /*└────────────────────────────────────────────────────────────────────┘*/
  106.  
  107. EXTERN struct BufferDef {
  108.    unsigned *BufferStart;  /* start of communications buffer (receive) */
  109.    unsigned *Buffer_Max;   /* last loc in buffer */
  110.    volatile unsigned *Buffer_Head;  /* Loc in Async_Buffer to put next char */
  111.    volatile unsigned *Buffer_Tail;  /* Loc in Async_Buffer to get next char */
  112.    volatile unsigned Buffer_Used;
  113.    unsigned Buffer_Size;
  114.    unsigned MaxBufferUsed;
  115.  
  116.    unsigned char *SBufferStart; /* start of send buffer */
  117.    unsigned char *SBuffer_Max;  /* last loc in send buffer */
  118.    unsigned char *SBuffer_Head;
  119.    volatile unsigned char *SBuffer_Tail;
  120.    volatile unsigned SBuffer_Used;
  121.    unsigned SBuffer_Size;
  122.    unsigned MaxSBufferUsed;
  123.    int sendints;                        /* flay if send interupts are used */
  124.    unsigned char ier;
  125.    unsigned Base;
  126.    unsigned Irq;
  127.    unsigned Lsr;
  128.    unsigned Iir;
  129.    unsigned Save_Offset, Save_Segment;
  130.    char Open_Flag;         /* true if Open but no Close */
  131.    char Buffer_Overflow;   /* True if buffer overflow   */
  132.    
  133.    unsigned SaveIER;
  134.    unsigned SaveLCR;
  135.    unsigned SaveMCR;
  136.    unsigned SaveDLL;
  137.    unsigned SaveDLM;
  138.    unsigned SaveIMR;
  139. } Async[MAXPORTS];
  140.  
  141. int Async_Init(void);
  142. int Async_Open(int port, unsigned BaudRate, char Parity, int WordSize,
  143.                int StopBits, int BufferSize, unsigned SBufferSize);
  144. void Async_Close(int port);
  145. int Async_Receive(int port, unsigned char *C);
  146. int Async_Send(int port, unsigned char c);
  147. int Async_putc(int port, unsigned char c);
  148. void Async_Send_String(int port, unsigned char *s);
  149. int Async_Buffer_Check(int port);
  150. void Async_Calc_Buffer(int port);
  151. void Async_Putback(int port, unsigned char c);
  152. int Async_DCD(int port);
  153. int Async_CTS(int port);
  154. int Async_DSR(int port);
  155. int Async_RI(int port);
  156. int Async_Carrier_Drop(int port);
  157. void Async_DTR(int port, char Ready_Status);
  158. void Async_RTS(int port, char Ready_Status);
  159. void Async_Isr(int port);
  160. void Async_Send_String_With_Delays(int port, unsigned char *s, 
  161.          int char_Delay, int EOS_Delay);
  162. int Async_Percentage_Used(int port);
  163. int Async_SPercentage_Used(int port);
  164. void Async_Purge_Buffer(int port);
  165. void Async_Send_Brk(int port);
  166. int Async_Receive_With_Timeout(int port, int Hunds, unsigned char *C);
  167. void Async_Signon(int port, char *phone);
  168. void Async_Signoff(int port);
  169. void Async_Ints(int port);
  170. void SaveRegisters(int port);
  171. void RestoreRegisters(int port);
  172.  
  173. void inton    ( void );
  174. void intoff   ( void );
  175. void getvec   ( int, unsigned *, unsigned * );
  176. void setvec   ( int, unsigned  , unsigned );
  177. // void intsetup ( unsigned int, void (*func)() );
  178.  
  179. void intserv0 ( void );
  180. void intserv1 ( void );
  181. void intserv2 ( void );
  182. void intserv3 ( void );
  183.  
  184. void peekw    ( unsigned , unsigned , void *, int);
  185.  
  186. void ProcessInputs( void );
  187.  
  188. #endif /* ASYNC_H */
  189.