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.

262 lines
8.5 KiB

  1. /******************************************************************************
  2. *
  3. * $Workfile: 16c95x.h $
  4. *
  5. * $Author: Psmith $
  6. *
  7. * $Revision: 9 $
  8. *
  9. * $Modtime: 6/06/00 11:41 $
  10. *
  11. * Description: Contains private 16C95X UART Library structures,
  12. * macros & prototypes.
  13. *
  14. ******************************************************************************/
  15. #if !defined(_16C95X_H) /* 16C95X.H */
  16. #define _16C95X_H
  17. #include "os.h"
  18. #include "uartlib.h"
  19. #include "uartprvt.h"
  20. #include "16cx5x.h"
  21. #if ACCESS_16C95X_IN_IO_SPACE
  22. #define UL_READ_BYTE UL_READ_BYTE_IO
  23. #define UL_WRITE_BYTE UL_WRITE_BYTE_IO
  24. #else
  25. #define UL_READ_BYTE UL_READ_BYTE_MEM
  26. #define UL_WRITE_BYTE UL_WRITE_BYTE_MEM
  27. #endif
  28. #define MAX_95X_TX_FIFO_SIZE 128
  29. #define MAX_95X_RX_FIFO_SIZE 128
  30. #define DEFAULT_95X_HI_FC_TRIG_LEVEL 96 /* = 75% of FIFO */
  31. #define DEFAULT_95X_LO_FC_TRIG_LEVEL 32 /* = 25% of FIFO */
  32. /* 16C95X UART Data */
  33. typedef struct _UART_DATA_16C95X
  34. {
  35. BYTE CurrentFCR;
  36. BYTE CurrentIER;
  37. BYTE CurrentMCR;
  38. BYTE CurrentLCR;
  39. BYTE CurrentACR;
  40. BOOLEAN ASRChanged;
  41. BOOLEAN FIFOEnabled;
  42. BYTE TxFIFOSize;
  43. BYTE RxFIFOSize;
  44. BYTE TxFIFOTrigLevel;
  45. BYTE RxFIFOTrigLevel;
  46. BOOLEAN RTSToggle;
  47. BOOLEAN DSRSensitive;
  48. BYTE UART_Type;
  49. BYTE UART_Rev;
  50. DWORD UART_ID;
  51. BOOLEAN Verified;
  52. BOOLEAN StripNULLs;
  53. } UART_DATA_16C95X, *PUART_DATA_16C95X;
  54. /******************************************************************************
  55. * FUNCTIONS TO READ & WRITE BYTES TO REGISTERS
  56. ******************************************************************************/
  57. /* Reads a byte from a Register at offset RegOffset. */
  58. #define READ_BYTE_REG_95X(pUart, RegOffset) \
  59. (UL_READ_BYTE((pUart)->BaseAddress, (RegOffset * (pUart)->RegisterStride)))
  60. /* Writes a byte to a Register at offset RegOffset. */
  61. #define WRITE_BYTE_REG_95X(pUart, RegOffset, Data) \
  62. (UL_WRITE_BYTE((pUart)->BaseAddress, (RegOffset * (pUart)->RegisterStride), Data))
  63. /******************************************************************************
  64. * FUNCTIONS TO ACCESS COMMON REGISTERS
  65. ******************************************************************************/
  66. /* This writes to the THR (Transmit Holding Register). */
  67. #define WRITE_TRANSMIT_HOLDING(pUart, Data) \
  68. WRITE_BYTE_REG_95X(pUart, TRANSMIT_HOLDING_REGISTER, Data)
  69. /* This reads the RBR (Receive Buffer Register). */
  70. #define READ_RECEIVE_BUFFER(pUart) \
  71. READ_BYTE_REG_95X(pUart, RECEIVE_BUFFER_REGISTER)
  72. /* Writes a byte to the THR (Transmit Holding Register). */
  73. #define FILL_FIFO_95X(pUart, pData, NumBytes) \
  74. (UL_WRITE_MULTIBYTES((pUart)->BaseAddress, (TRANSMIT_HOLDING_REGISTER * (pUart)->RegisterStride), pData, NumBytes))
  75. /* Reads multiple bytes from the RBR (Receive Buffer Register). */
  76. #define EMPTY_FIFO_95X(pUart, pDest, NumBytes) \
  77. (UL_READ_MULTIBYTES((pUart)->BaseAddress, (RECEIVE_BUFFER_REGISTER * (pUart)->RegisterStride), pDest, NumBytes))
  78. /* This writes the IER (Interrupt Enable Register). */
  79. #define WRITE_INTERRUPT_ENABLE(pUart, Data) \
  80. ( \
  81. WRITE_BYTE_REG_95X(pUart, INTERRUPT_ENABLE_REGISTER, Data), \
  82. ((PUART_DATA_16C95X)((pUart)->pUartData))->CurrentIER = Data \
  83. )
  84. /* This reads to the IER (Interrupt Enable Register). */
  85. #define READ_INTERRUPT_ENABLE(pUart) \
  86. ((PUART_DATA_16C95X)((pUart)->pUartData))->CurrentIER
  87. /* READ_BYTE_REG_95X(pUart, INTERRUPT_ENABLE_REGISTER), */
  88. /* This reads to the IIR (Interrupt Identification Register).
  89. *
  90. * Note that this routine potententially quites a transmitter empty interrupt.
  91. * This is because one way that the transmitter empty interrupt is cleared is to
  92. * simply read the interrupt id register. */
  93. #define READ_INTERRUPT_ID_REG(pUart) \
  94. READ_BYTE_REG_95X(pUart, INTERRUPT_IDENT_REGISTER)
  95. /* This reads the LSR (Line Status Register). */
  96. #define READ_LINE_STATUS(pUart) \
  97. READ_BYTE_REG_95X(pUart, LINE_STATUS_REGISTER)
  98. /* This writes to the FCR (FIFO Control Register).
  99. * -- OXSER BUGFIX 4 --
  100. * Incase anyone puts an OX16C950 on the local bus we will unconditionally fix its
  101. * Rx FIFO Flush bug here by following all FCR writes with a read of both RBR and LSR.
  102. *
  103. * 17.11.1999 ARG - ESIL 0920
  104. * When we write to the FCR we store those bits being set - but we don't want the Rx
  105. * and Tx FIFI flush bits to be retained - so we mask them off.
  106. *
  107. * Note : Due to the Rx FIFO flush bug fix, a byte of Rx data will be lost when we do a
  108. * Tx flush
  109. */
  110. #define WRITE_FIFO_CONTROL(pUart, Data) \
  111. ( \
  112. WRITE_BYTE_REG_95X(pUart, FIFO_CONTROL_REGISTER, Data), \
  113. ((PUART_DATA_16C95X)((pUart)->pUartData))->CurrentFCR \
  114. = (Data & ~(FCR_FLUSH_RX_FIFO|FCR_FLUSH_TX_FIFO)), \
  115. \
  116. READ_RECEIVE_BUFFER(pUart), \
  117. READ_LINE_STATUS(pUart) \
  118. )
  119. #define READ_FIFO_CONTROL(pUart) \
  120. ((PUART_DATA_16C95X)((pUart)->pUartData))->CurrentFCR
  121. /* This writes to the LCR (Line Control Register). */
  122. #define WRITE_LINE_CONTROL(pUart, Data) \
  123. ( \
  124. ((PUART_DATA_16C95X)((pUart)->pUartData))->CurrentLCR = Data, \
  125. WRITE_BYTE_REG_95X(pUart, LINE_CONTROL_REGISTER, Data) \
  126. )
  127. /* This reads the LCR (Line Control Register).
  128. *
  129. * -- OXSER Mod 14 --
  130. * An LCR register has been created in the UART Object's Data Structure to store the state of this
  131. * register (updated on every LCR write) this removes the requirement for a read LCR routine to access
  132. * the hardware and means on the 16C95x RFL + TFL read access can be enabled at all times. */
  133. #define READ_LINE_CONTROL(pUart) \
  134. ((PUART_DATA_16C95X)((pUart)->pUartData))->CurrentLCR
  135. /* READ_BYTE_REG_95X(pUart, LINE_CONTROL_REGISTER) */
  136. /* This writes to the MCR (Modem Control Register). */
  137. #define WRITE_MODEM_CONTROL(pUart, Data) \
  138. ( \
  139. ((PUART_DATA_16C95X)((pUart)->pUartData))->CurrentMCR = Data, \
  140. WRITE_BYTE_REG_95X(pUart, MODEM_CONTROL_REGISTER, Data) \
  141. )
  142. /* This reads the MCR (Modem Control Register).
  143. *
  144. * -- OXSER Mod 14 --
  145. * An MCR register has been created in the UART Object's Data Structure to store the state of this
  146. * register (updated on every MCR write) this removes the requirement for a read MCR routine to access
  147. * the hardware and means on the 16C95x RFL + TFL read access can be enabled at all times. */
  148. #define READ_MODEM_CONTROL(pUart) \
  149. ((PUART_DATA_16C95X)((pUart)->pUartData))->CurrentMCR
  150. /* READ_BYTE_REG_95X(pUart, MODEM_CONTROL_REGISTER) */
  151. /* This reads the MSR (Modem Status Register). */
  152. #define READ_MODEM_STATUS(pUart) \
  153. READ_BYTE_REG_95X(pUart, MODEM_STATUS_REGISTER)
  154. /* This writes to the SPR (Scratch Pad Register). */
  155. #define WRITE_SCRATCH_PAD_REGISTER(pUart, Data) \
  156. WRITE_BYTE_REG_95X(pUart, SCRATCH_PAD_REGISTER, Data)
  157. /* This reads the SPR (Scratch Pad Register). */
  158. #define READ_SCRATCH_PAD_REGISTER(pUart) \
  159. READ_BYTE_REG_95X(pUart, SCRATCH_PAD_REGISTER)
  160. /* Sets the divisor latch register.
  161. * The divisor latch register is used to control the baud rate of the UART. */
  162. #define WRITE_DIVISOR_LATCH(pUart, DesiredDivisor) \
  163. ( \
  164. WRITE_LINE_CONTROL(pUart, (BYTE)(READ_LINE_CONTROL(pUart) | LCR_DLAB)), \
  165. \
  166. WRITE_BYTE_REG_95X(pUart, DIVISOR_LATCH_LSB, (BYTE)(DesiredDivisor & 0xFF)), \
  167. \
  168. WRITE_BYTE_REG_95X(pUart, DIVISOR_LATCH_MSB, (BYTE)((DesiredDivisor & 0xFF00) >> 8)), \
  169. \
  170. WRITE_LINE_CONTROL(pUart, (BYTE)(READ_LINE_CONTROL(pUart) & ~LCR_DLAB)) \
  171. )
  172. /* Reads the divisor latch register.
  173. * The divisor latch register is used to control the baud rate of the UART. */
  174. #define READ_DIVISOR_LATCH(pUart, pDivisor) \
  175. ( \
  176. WRITE_LINE_CONTROL(pUart, (BYTE)(READ_LINE_CONTROL(pUart) | LCR_DLAB)), \
  177. \
  178. *pDivisor = (WORD)READ_BYTE_REG_95X(pUart, DIVISOR_LATCH_LSB), \
  179. \
  180. *pDivisor |= (WORD)(READ_BYTE_REG_95X(pUart, DIVISOR_LATCH_MSB) << 8), \
  181. \
  182. WRITE_LINE_CONTROL(pUart, (BYTE)(READ_LINE_CONTROL(pUart) & ~LCR_DLAB)) \
  183. )
  184. void WRITE_TO_OX950_ICR(PUART_OBJECT pUart, BYTE Register, BYTE Value);
  185. BYTE READ_FROM_OX950_ICR(PUART_OBJECT pUart, BYTE Register);
  186. WORD CalculateBaudDivisor_95X(PUART_OBJECT pUart, DWORD DesiredBaud);
  187. /* 16C95X UART REGISTERS */
  188. typedef struct _UART_REGS_16C95X
  189. {
  190. BYTE REG_RHR, REG_IER, REG_FCR, REG_IIR, REG_LCR, REG_MCR, REG_LSR, REG_MSR, REG_SPR,
  191. REG_EFR, REG_XON1, REG_XON2, REG_XOFF1, REG_XOFF2,
  192. REG_ASR, REG_RFL, REG_TFL,
  193. REG_ACR, REG_CPR, REG_TCR, REG_TTL, REG_RTL, REG_FCL, REG_FCH, REG_ID1, REG_ID2, REG_ID3, REG_REV;
  194. } UART_REGS_16C95X, *PUART_REGS_16C95X;
  195. #endif /* End of 16C95X.H */