Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

246 lines
6.6 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Copyright (c) 1993 Logitech Inc.
  4. Module Name:
  5. uart.h
  6. Abstract:
  7. Hardware dependent support for the serial port.
  8. Environment:
  9. Kernel mode only.
  10. Notes:
  11. Revision History:
  12. --*/
  13. #ifndef UART_H
  14. #define UART_H
  15. //
  16. // Constants
  17. //
  18. //
  19. // Define the INS8250 ACE Register Offsets And Bit Definitions
  20. //
  21. #define ACE_RBR 0 // Receiver Buffer
  22. #define ACE_THR 0 // Transmit Holding Register
  23. #define ACE_IER 1 // Interrupt Enable
  24. #define ACE_ERBFI 0x01 // Received Data Available 00000001b
  25. #define ACE_ETBEI 0x02 // Transmitter Holding Register Empty 00000010b
  26. #define ACE_ELSI 0x04 // Receiver Line Status 00000100b
  27. #define ACE_EDSSI 0x08 // Modem Status 00001000b
  28. #define ACE_IIDR 2 // Interrupt Identification
  29. #define ACE_IIP 0x01 // Inverted Interrupt Pending (0=int) 00000001b
  30. #define ACE_IID 0x06 // Interrupt ID 00000110b
  31. #define ACE_MSI 0x00 // Modem Status 00000000b
  32. #define ACE_THREI 0x02 // Transmitter Holding Register Empty 00000010b
  33. #define ACE_RDAI 0x04 // Received Data Available 00000100b
  34. #define ACE_RLSI 0x06 // Receiver Line Status 00000110b
  35. #define ACE_LCR 3 // Line Control
  36. #define ACE_WLS 0x03 // Word Length Select Bits 00000011b
  37. #define ACE_WLS0 0x01 // Word Length Select Bit 0 00000001b
  38. #define ACE_WLS1 0x02 // Word Length Select Bit 1 00000010b
  39. #define ACE_5BW 0x00 // 5 Bit Words 00000000b
  40. #define ACE_6BW 0x01 // 6 Bit Words 00000001b
  41. #define ACE_7BW 0x02 // 7 Bit Words 00000010b
  42. #define ACE_8BW 0x03 // 8 Bit Words 00000011b
  43. #define ACE_STB 0x04 // Stop Bits 00000100b
  44. #define ACE_1SB 0x00 // 1 Stop Bits (1.5 for 5 bit words) 00000000b
  45. #define ACE_2SB 0x04 // 2 Stop Bits 00000100b
  46. #define ACE_PEN 0x08 // Parity Enable 00001000b
  47. #define ACE_PSB 0x30 // Parity Select bits 00110000b
  48. #define ACE_EPS 0x10 // Even Parity Select 00010000b
  49. #define ACE_SP 0x20 // Stick Parity 00100000b
  50. #define ACE_SB 0x40 // Set Break 01000000b
  51. #define ACE_DLAB 0x80 // Divisor Latch Access Bit 10000000b
  52. #define ACE_MCR 4 // Modem Control
  53. #define ACE_DTR 0x01 // Data Terminal ready 00000001b
  54. #define ACE_RTS 0x02 // Request To Send 00000010b
  55. #define ACE_OUT1 0x04 // Output Line 1 00000100b
  56. #define ACE_OUT2 0x08 // Output Line 2 00001000b
  57. #define ACE_LOOP 0x10 // Loopback 00010000b
  58. #define ACE_LSR 5 // Line Status
  59. #define ACE_DR 0x01 // Data Ready 00000001b
  60. #define ACE_OR 0x02 // Overrun Error 00000010b
  61. #define ACE_PE 0x04 // Parity Error 00000100b
  62. #define ACE_FE 0x08 // Framing Error 00001000b
  63. #define ACE_BI 0x10 // Break Interrupt 00010000b
  64. #define ACE_THRE 0x20 // Transmitter Holding Register Empty 00100000b
  65. #define ACE_TSRE 0x40 // Transmitter Shift Register Empty 01000000b
  66. #define ACE_LERR (ACE_OR | ACE_PE | ACE_FE | ACE_BI)
  67. #define ACE_MSR 6 // Modem Status
  68. #define ACE_DCTS 0x01 // Delta Clear to Send 00000001b
  69. #define ACE_DDSR 0x02 // Delta Data Set Ready 00000010b
  70. #define ACE_TERI 0x04 // Trailing Edge Ring Indicator 00000100b
  71. #define ACE_DRLSD 0x08 // Delta Receive Line Signal Detect 00001000b
  72. #define ACE_CTS 0x10 // Clear To Send 00010000b
  73. #define ACE_DSR 0x20 // Data Set ready 00100000b
  74. #define ACE_RI 0x40 // Ring Indicator 01000000b
  75. #define ACE_RLSD 0x80 // Receive Line Signal Detect 10000000b
  76. #define ACE_DLL 0 // LSB Baud Rate Divisor
  77. #define ACE_DLM 1 // MSB Baud Rate Divisor
  78. //
  79. // Define the Baud Generator Divisor. BaudClock (a value known via the
  80. // hardware registry) is actually BAUD_GENERATOR_DIVISOR times the baud rate.
  81. // For example, if the output frequency of the Baud Generator is 16 times
  82. // the baud rate, then BAUD_GENERATOR_DIVISOR is 16.
  83. //
  84. // The Baud Rate Factor is BaudClock/BAUD_GENERATOR_DIVISOR.
  85. //
  86. // The Baud Rate Divisor for the DLAB is Baud Rate Factor divided by the
  87. // desired baud rate, where the desired baud rate is 1200, 2400, and so on.
  88. //
  89. #define BAUD_GENERATOR_DIVISOR 16
  90. //
  91. // Type definitions.
  92. //
  93. //
  94. // UART configuration
  95. //
  96. typedef struct _UART {
  97. ULONG BaudRate;
  98. UCHAR LineCtrl;
  99. UCHAR ModemCtrl;
  100. UCHAR InterruptCtrl;
  101. } UART, *PUART;
  102. //
  103. // Function prototypes
  104. //
  105. VOID
  106. UARTSetFifo(
  107. PUCHAR Port,
  108. UCHAR Value
  109. );
  110. UCHAR
  111. UARTGetInterruptCtrl(
  112. PUCHAR Port
  113. );
  114. UCHAR
  115. UARTSetInterruptCtrl(
  116. PUCHAR Port,
  117. UCHAR Value
  118. );
  119. UCHAR
  120. UARTGetLineCtrl(
  121. PUCHAR Port
  122. );
  123. UCHAR
  124. UARTSetLineCtrl(
  125. PUCHAR Port,
  126. UCHAR Value
  127. );
  128. UCHAR
  129. UARTGetModemCtrl(
  130. PUCHAR Port
  131. );
  132. UCHAR
  133. UARTSetModemCtrl(
  134. PUCHAR Port,
  135. UCHAR Value
  136. );
  137. BOOLEAN
  138. UARTSetDlab(
  139. PUCHAR Port,
  140. BOOLEAN Set
  141. );
  142. ULONG
  143. UARTGetBaudRate(
  144. PUCHAR Port,
  145. ULONG BaudClock
  146. );
  147. VOID
  148. UARTSetBaudRate(
  149. PUCHAR Port,
  150. ULONG BaudRate,
  151. ULONG BaudClock
  152. );
  153. VOID
  154. UARTGetState(
  155. PUCHAR Port,
  156. PUART Uart,
  157. ULONG BaudClock
  158. );
  159. VOID
  160. UARTSetState(
  161. PUCHAR Port,
  162. PUART Uart,
  163. ULONG BaudClock
  164. );
  165. BOOLEAN
  166. UARTIsReceiveBufferFull(
  167. PUCHAR Port
  168. );
  169. BOOLEAN
  170. UARTReadCharNoWait(
  171. PUCHAR Port,
  172. PUCHAR Value
  173. );
  174. BOOLEAN
  175. UARTReadChar(
  176. PUCHAR Port,
  177. PUCHAR Value,
  178. ULONG Timeout
  179. );
  180. BOOLEAN
  181. UARTFlushReadBuffer(
  182. PUCHAR Port
  183. );
  184. BOOLEAN
  185. UARTIsTransmitEmpty(
  186. PUCHAR Port
  187. );
  188. BOOLEAN
  189. UARTWriteChar(
  190. PUCHAR Port,
  191. UCHAR Value
  192. );
  193. BOOLEAN
  194. UARTWriteString(
  195. PUCHAR Port,
  196. PSZ Buffer
  197. );
  198. #endif // UART_H