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.

254 lines
8.1 KiB

  1. /******************************************************************************
  2. *
  3. * $Workfile: 16c65x.h $
  4. *
  5. * $Author: Psmith $
  6. *
  7. * $Revision: 3 $
  8. *
  9. * $Modtime: 6/07/00 15:16 $
  10. *
  11. * Description: Contains private 16C65X UART Library structures,
  12. * macros & prototypes.
  13. *
  14. ******************************************************************************/
  15. #if !defined(_16C65X_H) /* 16C65X.H */
  16. #define _16C65X_H
  17. #include "os.h"
  18. #include "uartlib.h"
  19. #include "uartprvt.h"
  20. #include "16cx5x.h"
  21. #if ACCESS_16C65X_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_65X_TX_FIFO_SIZE 64
  29. #define MAX_65X_RX_FIFO_SIZE 64
  30. #define DEFAULT_65X_HI_FC_TRIG_LEVEL 60 /* = 75% of FIFO */
  31. #define DEFAULT_65X_LO_FC_TRIG_LEVEL 16 /* = 25% of FIFO */
  32. /* 16C95X UART Data */
  33. typedef struct _UART_DATA_16C65X
  34. {
  35. BYTE CurrentFCR;
  36. BYTE CurrentIER;
  37. BYTE CurrentMCR;
  38. BYTE CurrentLCR;
  39. BOOLEAN FIFOEnabled;
  40. BYTE TxFIFOSize;
  41. BYTE RxFIFOSize;
  42. BYTE TxFIFOTrigLevel;
  43. BYTE RxFIFOTrigLevel;
  44. DWORD HiFlowCtrlLevel; /* For software buffers only not FIFOs */
  45. DWORD LoFlowCtrlLevel; /* For software buffers only not FIFOs */
  46. BOOLEAN RTSToggle;
  47. BOOLEAN DSRSensitive;
  48. BOOLEAN DTRHandshake;
  49. BOOLEAN DSRHandshake;
  50. BOOLEAN TxDisabled;
  51. BOOLEAN RxDisabled;
  52. BOOLEAN Verified;
  53. BOOLEAN StripNULLs;
  54. } UART_DATA_16C65X, *PUART_DATA_16C65X;
  55. /******************************************************************************
  56. * FUNCTIONS TO READ & WRITE BYTES TO REGISTERS
  57. ******************************************************************************/
  58. /* Reads a byte from a Register at offset RegOffset. */
  59. #define READ_BYTE_REG_65X(pUart, RegOffset) \
  60. (UL_READ_BYTE((pUart)->BaseAddress, (RegOffset * (pUart)->RegisterStride)))
  61. /* Writes a byte to a Register at offset RegOffset. */
  62. #define WRITE_BYTE_REG_65X(pUart, RegOffset, Data) \
  63. (UL_WRITE_BYTE((pUart)->BaseAddress, (RegOffset * (pUart)->RegisterStride), Data))
  64. /******************************************************************************
  65. * FUNCTIONS TO ACCESS COMMON REGISTERS
  66. ******************************************************************************/
  67. /* This writes to the THR (Transmit Holding Register). */
  68. #define WRITE_TRANSMIT_HOLDING_65X(pUart, Data) \
  69. WRITE_BYTE_REG_65X(pUart, TRANSMIT_HOLDING_REGISTER, Data)
  70. /* This reads the RBR (Receive Buffer Register). */
  71. #define READ_RECEIVE_BUFFER_65X(pUart) \
  72. READ_BYTE_REG_65X(pUart, RECEIVE_BUFFER_REGISTER)
  73. /* Writes a byte to the THR (Transmit Holding Register). */
  74. #define FILL_FIFO_65X(pUart, pData, NumBytes) \
  75. (UL_WRITE_MULTIBYTES((pUart)->BaseAddress, (TRANSMIT_HOLDING_REGISTER * (pUart)->RegisterStride), pData, NumBytes))
  76. /* Reads multiple bytes from the RBR (Receive Buffer Register). */
  77. #define EMPTY_FIFO_65X(pUart, pDest, NumBytes) \
  78. (UL_READ_MULTIBYTES((pUart)->BaseAddress, (RECEIVE_BUFFER_REGISTER * (pUart)->RegisterStride), pDest, NumBytes))
  79. /* This writes the IER (Interrupt Enable Register). */
  80. #define WRITE_INTERRUPT_ENABLE_65X(pUart, Data) \
  81. ( \
  82. WRITE_BYTE_REG_65X(pUart, INTERRUPT_ENABLE_REGISTER, Data), \
  83. ((PUART_DATA_16C65X)((pUart)->pUartData))->CurrentIER = Data \
  84. )
  85. /* This reads to the IER (Interrupt Enable Register). */
  86. #define READ_INTERRUPT_ENABLE_65X(pUart) \
  87. ((PUART_DATA_16C65X)((pUart)->pUartData))->CurrentIER
  88. /* READ_BYTE_REG_65X(pUart, INTERRUPT_ENABLE_REGISTER), */
  89. /* This reads to the IIR (Interrupt Identification Register).
  90. *
  91. * Note that this routine potententially quites a transmitter empty interrupt.
  92. * This is because one way that the transmitter empty interrupt is cleared is to
  93. * simply read the interrupt id register. */
  94. #define READ_INTERRUPT_ID_REG_65X(pUart) \
  95. READ_BYTE_REG_65X(pUart, INTERRUPT_IDENT_REGISTER)
  96. /* This reads the LSR (Line Status Register). */
  97. #define READ_LINE_STATUS_65X(pUart) \
  98. READ_BYTE_REG_65X(pUart, LINE_STATUS_REGISTER)
  99. /* This writes to the FCR (FIFO Control Register).
  100. *
  101. * 17.11.1999 ARG - ESIL 0920
  102. * When we write to the FCR we store those bits being set - but we don't want the Rx
  103. * and Tx FIFO flush bits to be retained - so we mask them off.
  104. *
  105. */
  106. #define WRITE_FIFO_CONTROL_65X(pUart, Data) \
  107. ( \
  108. WRITE_BYTE_REG_65X(pUart, FIFO_CONTROL_REGISTER, Data), \
  109. ((PUART_DATA_16C65X)((pUart)->pUartData))->CurrentFCR \
  110. = (Data & ~(FCR_FLUSH_RX_FIFO|FCR_FLUSH_TX_FIFO)) \
  111. )
  112. #define READ_FIFO_CONTROL_65X(pUart) \
  113. ((PUART_DATA_16C65X)((pUart)->pUartData))->CurrentFCR
  114. /* This writes to the LCR (Line Control Register). */
  115. #define WRITE_LINE_CONTROL_65X(pUart, Data) \
  116. ( \
  117. ((PUART_DATA_16C65X)((pUart)->pUartData))->CurrentLCR = Data, \
  118. WRITE_BYTE_REG_65X(pUart, LINE_CONTROL_REGISTER, Data) \
  119. )
  120. /* This reads the LCR (Line Control Register).
  121. *
  122. * -- OXSER Mod 14 --
  123. * An LCR register has been created in the UART Object's Data Structure to store the state of this
  124. * register (updated on every LCR write) this removes the requirement for a read LCR routine to access
  125. * the hardware and means on the 16C95x RFL + TFL read access can be enabled at all times. */
  126. #define READ_LINE_CONTROL_65X(pUart) \
  127. ((PUART_DATA_16C65X)((pUart)->pUartData))->CurrentLCR
  128. /* READ_BYTE_REG_65X(pUart, LINE_CONTROL_REGISTER) */
  129. /* This writes to the MCR (Modem Control Register). */
  130. #define WRITE_MODEM_CONTROL_65X(pUart, Data) \
  131. ( \
  132. ((PUART_DATA_16C65X)((pUart)->pUartData))->CurrentMCR = Data, \
  133. WRITE_BYTE_REG_65X(pUart, MODEM_CONTROL_REGISTER, Data) \
  134. )
  135. /* This reads the MCR (Modem Control Register).
  136. *
  137. * -- OXSER Mod 14 --
  138. * An MCR register has been created in the UART Object's Data Structure to store the state of this
  139. * register (updated on every MCR write) this removes the requirement for a read MCR routine to access
  140. * the hardware and means on the 16C95x RFL + TFL read access can be enabled at all times. */
  141. #define READ_MODEM_CONTROL_65X(pUart) \
  142. ((PUART_DATA_16C65X)((pUart)->pUartData))->CurrentMCR
  143. /* READ_BYTE_REG_65X(pUart, MODEM_CONTROL_REGISTER) */
  144. /* This reads the MSR (Modem Status Register). */
  145. #define READ_MODEM_STATUS_65X(pUart) \
  146. READ_BYTE_REG_65X(pUart, MODEM_STATUS_REGISTER)
  147. /* This writes to the SPR (Scratch Pad Register). */
  148. #define WRITE_SCRATCH_PAD_REGISTER_65X(pUart, Data) \
  149. WRITE_BYTE_REG_65X(pUart, SCRATCH_PAD_REGISTER, Data)
  150. /* This reads the SPR (Scratch Pad Register). */
  151. #define READ_SCRATCH_PAD_REGISTER_65X(pUart) \
  152. READ_BYTE_REG_65X(pUart, SCRATCH_PAD_REGISTER)
  153. /* Sets the divisor latch register.
  154. * The divisor latch register is used to control the baud rate of the UART. */
  155. #define WRITE_DIVISOR_LATCH_65X(pUart, DesiredDivisor) \
  156. ( \
  157. WRITE_LINE_CONTROL_65X(pUart, (BYTE)(READ_LINE_CONTROL_65X(pUart) | LCR_DLAB)), \
  158. \
  159. WRITE_BYTE_REG_65X(pUart, DIVISOR_LATCH_LSB, (BYTE)(DesiredDivisor & 0xFF)), \
  160. \
  161. WRITE_BYTE_REG_65X(pUart, DIVISOR_LATCH_MSB, (BYTE)((DesiredDivisor & 0xFF00) >> 8)), \
  162. \
  163. WRITE_LINE_CONTROL_65X(pUart, (BYTE)(READ_LINE_CONTROL_65X(pUart) & ~LCR_DLAB)) \
  164. )
  165. /* Reads the divisor latch register.
  166. * The divisor latch register is used to control the baud rate of the UART. */
  167. #define READ_DIVISOR_LATCH_65X(pUart, pDivisor) \
  168. ( \
  169. WRITE_LINE_CONTROL_65X(pUart, (BYTE)(READ_LINE_CONTROL_65X(pUart) | LCR_DLAB)), \
  170. \
  171. *pDivisor = (WORD)READ_BYTE_REG_65X(pUart, DIVISOR_LATCH_LSB), \
  172. \
  173. *pDivisor |= (WORD)(READ_BYTE_REG_65X(pUart, DIVISOR_LATCH_MSB) << 8), \
  174. \
  175. WRITE_LINE_CONTROL_65X(pUart, (BYTE)(READ_LINE_CONTROL_65X(pUart) & ~LCR_DLAB)) \
  176. )
  177. WORD CalculateBaudDivisor_65X(PUART_OBJECT pUart, DWORD DesiredBaud);
  178. /* 16C65X UART REGISTERS */
  179. typedef struct _UART_REGS_16C65X
  180. {
  181. BYTE REG_RHR, REG_IER, REG_FCR, REG_IIR, REG_LCR, REG_MCR, REG_LSR, REG_MSR, REG_SPR,
  182. REG_EFR, REG_XON1, REG_XON2, REG_XOFF1, REG_XOFF2;
  183. } UART_REGS_16C65X, *PUART_REGS_16C65X;
  184. #endif /* End of 16C65X.H */