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.

341 lines
13 KiB

  1. /******************************************************************************
  2. *
  3. * $Workfile: uartlib.h $
  4. *
  5. * $Author: Moti $
  6. *
  7. * $Revision: 23 $
  8. *
  9. * $Modtime: 3/15/02 12:28p $
  10. *
  11. * Description: Contains public UART Library definitions and prototypes.
  12. *
  13. ******************************************************************************/
  14. #if !defined(UARTLIB_H) /* UARTLIB.H */
  15. #define UARTLIB_H
  16. /* UART object structure prototype */
  17. typedef struct _UART_OBJECT *PUART_OBJECT;
  18. /* UART_CONFIG.FrameConfig */
  19. #define UC_FCFG_DATALEN_MASK ((DWORD)(0x0000000F)) /* Data Length mask for bits 0:3 */
  20. #define UC_FCFG_DATALEN_5 ((DWORD)(0x00<<0)) /* Bits 0:3 - Sets Data Word Length to 5 Bits. */
  21. #define UC_FCFG_DATALEN_6 ((DWORD)(0x01<<0)) /* Bits 0:3 - Sets Data Word Length to 6 Bits. */
  22. #define UC_FCFG_DATALEN_7 ((DWORD)(0x02<<0)) /* Bits 0:3 - Sets Data Word Length to 7 Bits. */
  23. #define UC_FCFG_DATALEN_8 ((DWORD)(0x03<<0)) /* Bits 0:3 - Sets Data Word Length to 8 Bits. */
  24. #define UC_FCFG_STOPBITS_MASK ((DWORD)(0x000000F0)) /* Stop Bits mask for bits 4:7 */
  25. #define UC_FCFG_STOPBITS_1 ((DWORD)(0x00<<4)) /* Bits 4:7 - 1 Stop Bit. */
  26. #define UC_FCFG_STOPBITS_1_5 ((DWORD)(0x01<<4)) /* Bits 4:7 - 1.5 Stop Bits. */
  27. #define UC_FCFG_STOPBITS_2 ((DWORD)(0x02<<4)) /* Bits 4:7 - 2 Stop Bits. */
  28. #define UC_FCFG_PARITY_MASK ((DWORD)(0x00000F00)) /* Parity Bits mask for bits 8:11 */
  29. #define UC_FCFG_NO_PARITY ((DWORD)(0x00<<8)) /* Bits 8:11 - No Parity. */
  30. #define UC_FCFG_ODD_PARITY ((DWORD)(0x01<<8)) /* Bits 8:11 - Odd Parity. */
  31. #define UC_FCFG_EVEN_PARITY ((DWORD)(0x02<<8)) /* Bits 8:11 - Even Parity. */
  32. #define UC_FCFG_MARK_PARITY ((DWORD)(0x03<<8)) /* Bits 8:11 - High Parity - Mark (Forced to 1). */
  33. #define UC_FCFG_SPACE_PARITY ((DWORD)(0x04<<8)) /* Bits 8:11 - Low Parity - Space (Forced to 0). */
  34. /* UART_CONFIG.InterruptEnable */
  35. #define UC_IE_NO_INTS ((DWORD)(0x00)) /* No Interrupts - Interrupts Disabled. */
  36. #define UC_IE_RX_STAT_INT ((DWORD)(0x01)) /* Bit 0 - Receive Status Interrupt. */
  37. #define UC_IE_RX_INT ((DWORD)(0x02)) /* Bit 1 - Receive Data Available Interrupt. */
  38. #define UC_IE_TX_INT ((DWORD)(0x04)) /* Bit 2 - Transmit Interrupt. */
  39. #define UC_IE_TX_EMPTY_INT ((DWORD)(0x08)) /* Bit 3 - Transmit Empty Interrupt. */
  40. #define UC_IE_MODEM_STAT_INT ((DWORD)(0x10)) /* Bit 4 - Modem Status Interrupt. */
  41. /* UART_CONFIG.FlowControl */
  42. #define UC_FLWC_RTS_FLOW_MASK ((DWORD)(0x0000000F))
  43. #define UC_FLWC_NO_RTS_FLOW ((DWORD)(0x00<<0)) /* No RTS Handshaking */
  44. #define UC_FLWC_RTS_HS ((DWORD)(0x01<<0)) /* RTS Handshaking */
  45. #define UC_FLWC_RTS_TOGGLE ((DWORD)(0x02<<0)) /* RTS is raised when there is data to send and whilst being sent. */
  46. #define UC_FLWC_CTS_FLOW_MASK ((DWORD)(0x000000F0))
  47. #define UC_FLWC_NO_CTS_FLOW ((DWORD)(0x00<<4)) /* No CTS Handshaking */
  48. #define UC_FLWC_CTS_HS ((DWORD)(0x01<<4)) /* CTS Handshaking */
  49. #define UC_FLWC_DSR_FLOW_MASK ((DWORD)(0x00000F00))
  50. #define UC_FLWC_NO_DSR_FLOW ((DWORD)(0x00<<8)) /* No DSR Handshaking */
  51. #define UC_FLWC_DSR_HS ((DWORD)(0x01<<8)) /* DSR Handshaking */
  52. #define UC_FLWC_DTR_FLOW_MASK ((DWORD)(0x0000F000))
  53. #define UC_FLWC_NO_DTR_FLOW ((DWORD)(0x00<<12)) /* No DTR Handshaking */
  54. #define UC_FLWC_DTR_HS ((DWORD)(0x01<<12)) /* DTR Handshaking */
  55. #define UC_FLWC_DSR_IP_SENSITIVE ((DWORD)(0x02<<12)) /* DSR input sensitivity. */
  56. #define UC_FLWC_TX_XON_XOFF_FLOW_MASK ((DWORD)(0x000F0000)) /* Transmit XON/XOFF flow control. */
  57. #define UC_FLWC_TX_NO_XON_XOFF_FLOW ((DWORD)(0x00<<16)) /* No transmit XON/XOFF in-band flow control. */
  58. #define UC_FLWC_TX_XON_XOFF_FLOW ((DWORD)(0x01<<16)) /* Transmit XON/XOFF in-band flow control. */
  59. #define UC_FLWC_TX_XONANY_XOFF_FLOW ((DWORD)(0x02<<16)) /* Transmit XON Any/XOFF in-band flow control. */
  60. /* 10.11.1999 ARG - ESIL 0928 */
  61. /* Definition for Rx XON-ANY/XOFF flow control removed as not a feature of UART */
  62. #define UC_FLWC_RX_XON_XOFF_FLOW_MASK ((DWORD)(0x00F00000)) /* Receive XON/XOFF flow control. */
  63. #define UC_FLWC_RX_NO_XON_XOFF_FLOW ((DWORD)(0x00<<20)) /* No receive XON/XOFF in-band flow control. */
  64. #define UC_FLWC_RX_XON_XOFF_FLOW ((DWORD)(0x01<<20)) /* Receive XON/XOFF in-band flow control. */
  65. #define UC_FLWC_DISABLE_TXRX_MASK ((DWORD)(0xF0000000))
  66. #define UC_FLWC_DISABLE_TX ((DWORD)(0x01<<28)) /* Disable Tx. */
  67. #define UC_FLWC_DISABLE_RX ((DWORD)(0x02<<28)) /* Disable Rx. */
  68. #define UC_FLWC_DISABLE_TXRX ((DWORD)(0x03<<28)) /* Disable Tx & Rx. */
  69. /* UART_CONFIG.SpecialMode */
  70. #define UC_SM_LOOPBACK_MODE ((DWORD)(0x01)) /* Place UART into internal loopback mode */
  71. #define UC_SM_LOW_POWER_MODE ((DWORD)(0x02)) /* Place UART into low power mode */
  72. #define UC_SM_TX_BREAK ((DWORD)(0x04)) /* Send break character */
  73. #define UC_SM_DETECT_SPECIAL_CHAR ((DWORD)(0x08)) /* Detect special character */
  74. #define UC_SM_DO_NULL_STRIPPING ((DWORD)(0x10)) /* Strip all NULLs from receive data */
  75. /* Config Structure Masks */
  76. #define UC_FRAME_CONFIG_MASK ((DWORD)(0x01))
  77. #define UC_INT_ENABLE_MASK ((DWORD)(0x02))
  78. #define UC_FLOW_CTRL_MASK ((DWORD)(0x04))
  79. #define UC_FC_THRESHOLD_SETTING_MASK ((DWORD)(0x08))
  80. #define UC_SPECIAL_CHARS_MASK ((DWORD)(0x10))
  81. #define UC_TX_BAUD_RATE_MASK ((DWORD)(0x20))
  82. #define UC_RX_BAUD_RATE_MASK ((DWORD)(0x40))
  83. #define UC_SPECIAL_MODE_MASK ((DWORD)(0x80))
  84. #define UC_ALL_MASK ((DWORD)(0xFFFF))
  85. /* Configure UART Struct. */
  86. typedef struct _UART_CONFIG
  87. {
  88. /* UC_FRAME_CONFIG_MASK */
  89. DWORD FrameConfig; /* Parity/Stop/Data */
  90. /* UC_INT_ENABLE_MASK */
  91. DWORD InterruptEnable; /* Enable/Disable Interrupts */
  92. /* UC_FLOW_CTRL_MASK */
  93. DWORD FlowControl; /* Receive & Transmit Flow Control Settings & Enable Tx & Rx. */
  94. /* UC_SPECIAL_CHARS_MASK */
  95. DWORD XON; /* XON Special Character for XON/XOFF flow control. */
  96. DWORD XOFF; /* XOFF Special Character for XON/XOFF flow control. */
  97. DWORD SpecialCharDetect; /* Special Character to detect */
  98. /* UC_FC_THRESHOLD_SETTING_MASK */
  99. DWORD HiFlowCtrlThreshold; /* High Flow control threshold level */
  100. DWORD LoFlowCtrlThreshold; /* Low Flow control threshold level */
  101. /* UC_TX_BAUD_RATE_MASK */
  102. DWORD TxBaud; /* Transmit baud rate. */
  103. /* UC_RX_BAUD_RATE_MASK */
  104. DWORD RxBaud; /* Receive baud rate. */
  105. /* UC_SPECIAL_MODE_MASK */
  106. DWORD SpecialMode; /* Special Mode */
  107. } UART_CONFIG, *PUART_CONFIG;
  108. /* Buffer Control Operations */
  109. #define UL_BC_OP_FLUSH 0x01
  110. #define UL_BC_OP_SET 0x02
  111. #define UL_BC_OP_GET 0x03
  112. #define UL_BC_FIFO ((DWORD)(0x01))
  113. #define UL_BC_BUFFER ((DWORD)(0x02))
  114. #define UL_BC_IN ((DWORD)(0x04))
  115. #define UL_BC_OUT ((DWORD)(0x08))
  116. /* Set UART Buffer Sizes Struct. */
  117. typedef struct _SET_BUFFER_SIZES
  118. {
  119. PBYTE pINBuffer; /* Pointer to allocated IN buffer */
  120. DWORD INBufferSize; /* IN buffer size */
  121. DWORD TxFIFOSize; /* Tx FIFO size */
  122. DWORD RxFIFOSize; /* Rx FIFO size */
  123. BYTE TxFIFOTrigLevel; /* Tx FIFO interrupt trigger level. */
  124. BYTE RxFIFOTrigLevel; /* Rx FIFO interrupt trigger level. */
  125. } SET_BUFFER_SIZES, *PSET_BUFFER_SIZES;
  126. /* Get UART Buffer State Struct. */
  127. typedef struct _GET_BUFFER_STATE
  128. {
  129. DWORD BytesInOUTBuffer; /* Bytes in OUT buffer */
  130. DWORD BytesInINBuffer; /* Bytes in IN buffer */
  131. DWORD BytesInTxFIFO; /* Bytes in TX FIFO */
  132. DWORD BytesInRxFIFO; /* Bytes in RX FIFO */
  133. } GET_BUFFER_STATE, *PGET_BUFFER_STATE;
  134. /* Modem Control Operations */
  135. #define UL_MC_OP_SET 0x01
  136. #define UL_MC_OP_BIT_SET 0x02
  137. #define UL_MC_OP_BIT_CLEAR 0x03
  138. #define UL_MC_OP_STATUS 0x04
  139. /* Modem Control Signals */
  140. #define UL_MC_RTS ((DWORD)0x00000001) /* O Read/Write */
  141. #define UL_MC_DTR ((DWORD)0x00000002) /* O Read/Write */
  142. #define UL_MC_DCD ((DWORD)0x00000004) /* I Read Only */
  143. #define UL_MC_RI ((DWORD)0x00000008) /* I Read Only */
  144. #define UL_MC_DSR ((DWORD)0x00000010) /* I Read Only */
  145. #define UL_MC_CTS ((DWORD)0x00000020) /* I Read Only */
  146. #define UL_MC_DELTA_DCD ((DWORD)0x00010000) /* I Read Only */
  147. #define UL_MC_TRAILING_RI_EDGE ((DWORD)0x00020000) /* I Read Only */
  148. #define UL_MC_DELTA_DSR ((DWORD)0x00040000) /* I Read Only */
  149. #define UL_MC_DELTA_CTS ((DWORD)0x00080000) /* I Read Only */
  150. #define UL_MC_INPUT_SIGNALS_CHANGED (UL_MC_DELTA_DCD | UL_MC_TRAILING_RI_EDGE | UL_MC_DELTA_DSR | UL_MC_DELTA_CTS)
  151. /* UART Information Struct. */
  152. typedef struct _UART_INFO
  153. {
  154. DWORD MaxTxFIFOSize;
  155. DWORD MaxRxFIFOSize;
  156. BOOLEAN PowerManagement;
  157. BOOLEAN IndependentRxBaud;
  158. DWORD UART_SubType;
  159. DWORD UART_Rev;
  160. } UART_INFO, *PUART_INFO;
  161. /* UART Interrupts Pending */
  162. #define UL_IP_RX_STAT ((DWORD)0x1<<0)
  163. #define UL_IP_RX ((DWORD)0x1<<1)
  164. #define UL_IP_RXTO ((DWORD)0x1<<2)
  165. #define UL_IP_TX ((DWORD)0x1<<3)
  166. #define UL_IP_TX_EMPTY ((DWORD)0x1<<4)
  167. #define UL_IP_MODEM ((DWORD)0x1<<5)
  168. /* GetUartStatus operations */
  169. #define UL_GS_OP_HOLDING_REASONS 0x1
  170. #define UL_GS_OP_LINESTATUS 0x2
  171. /* These are the reasons that the device could be holding. */
  172. /* UART Status */
  173. #define UL_TX_WAITING_FOR_CTS ((DWORD)0x00000001)
  174. #define UL_TX_WAITING_FOR_DSR ((DWORD)0x00000002)
  175. #define UL_TX_WAITING_FOR_DCD ((DWORD)0x00000004)
  176. #define UL_TX_WAITING_FOR_XON ((DWORD)0x00000008)
  177. #define UL_TX_WAITING_XOFF_SENT ((DWORD)0x00000010)
  178. #define UL_TX_WAITING_ON_BREAK ((DWORD)0x00000020)
  179. #define UL_RX_WAITING_FOR_DSR ((DWORD)0x00010000)
  180. /* UART Status Errors */
  181. #define UL_US_OVERRUN_ERROR ((DWORD)0x00000001) /* Buffer Overrun Error */
  182. #define UL_US_PARITY_ERROR ((DWORD)0x00000002) /* Parity Error */
  183. #define UL_US_FRAMING_ERROR ((DWORD)0x00000004) /* Framing Error. */
  184. #define UL_US_BREAK_ERROR ((DWORD)0x00000008) /* Break Interrupt. */
  185. #define UL_US_DATA_ERROR ((DWORD)0x00000010) /* Error In Receive FIFO. */
  186. /* Receive Status */
  187. #define UL_RS_SPECIAL_CHAR_DETECTED ((DWORD)0x00000020) /* Detected special char. */
  188. #define UL_RS_BUFFER_OVERRUN ((DWORD)0x00000040) /* IN Buffer Overrun */
  189. /* Immediate Byte Operations */
  190. #define UL_IM_OP_WRITE 0x1
  191. #define UL_IM_OP_CANCEL 0x2
  192. #define UL_IM_OP_STATUS 0x3
  193. #define UL_IM_NO_BYTE_TO_SEND 0x0 /* Byte Does not need to be sent */
  194. #define UL_IM_BYTE_TO_SEND 0x1 /* Byte needs to be sent */
  195. /* Init UART Struct. */
  196. typedef struct _INIT_UART
  197. {
  198. DWORD UartNumber; /* UART Number. */
  199. PVOID BaseAddress; /* UART Base Address. */
  200. DWORD RegisterStride; /* UART Register Stride */
  201. DWORD ClockFreq; /* UART Clock Frequency in Hz */
  202. } INIT_UART, *PINIT_UART;
  203. typedef int ULSTATUS;
  204. /* General UART Library status codes */
  205. #define UL_STATUS_SUCCESS 0
  206. #define UL_STATUS_UNSUCCESSFUL -1
  207. #define UL_STATUS_INSUFFICIENT_RESOURCES -2
  208. #define UL_STATUS_INVALID_PARAMETER -3
  209. #define UL_STATUS_SAME_BASE_ADDRESS -4
  210. #define UL_STATUS_TOO_MANY_UARTS_FOR_CHIP -5
  211. // UL_GetUartObject Operations
  212. #define UL_OP_GET_NEXT_UART 0x1
  213. #define UL_OP_GET_PREVIOUS_UART 0x2
  214. #define UL_LIB_16C65X_UART 1
  215. #define UL_LIB_16C95X_UART 2
  216. typedef struct _UART_LIB
  217. {
  218. ULSTATUS (*UL_InitUart_XXXX)(PINIT_UART pInitUart, PUART_OBJECT pFirstUart, PUART_OBJECT *ppUart);
  219. void (*UL_DeInitUart_XXXX)(PUART_OBJECT pUart);
  220. void (*UL_ResetUart_XXXX)(PUART_OBJECT pUart);
  221. ULSTATUS (*UL_VerifyUart_XXXX)(PUART_OBJECT pUart);
  222. ULSTATUS (*UL_SetConfig_XXXX)(PUART_OBJECT pUart, PUART_CONFIG pNewUartConfig, DWORD ConfigMask);
  223. ULSTATUS (*UL_BufferControl_XXXX)(PUART_OBJECT pUart, PVOID pBufferControl, int Operation, DWORD Flags);
  224. ULSTATUS (*UL_ModemControl_XXXX)(PUART_OBJECT pUart, PDWORD pModemSignals, int Operation);
  225. DWORD (*UL_IntsPending_XXXX)(PUART_OBJECT *ppUart);
  226. void (*UL_GetUartInfo_XXXX)(PUART_OBJECT pUart, PUART_INFO pUartInfo);
  227. int (*UL_OutputData_XXXX)(PUART_OBJECT pUart);
  228. int (*UL_InputData_XXXX)(PUART_OBJECT pUart, PDWORD pRxStatus);
  229. int (*UL_ReadData_XXXX)(PUART_OBJECT pUart, PBYTE pDest, int Size);
  230. ULSTATUS (*UL_WriteData_XXXX)(PUART_OBJECT pUart, PBYTE pData, int Size);
  231. ULSTATUS (*UL_ImmediateByte_XXXX)(PUART_OBJECT pUart, PBYTE pData, int Operation);
  232. ULSTATUS (*UL_GetStatus_XXXX)(PUART_OBJECT pUart, PDWORD pReturnData, int Operation);
  233. void (*UL_DumpUartRegs_XXXX)(PUART_OBJECT pUart);
  234. void (*UL_SetAppBackPtr_XXXX)(PUART_OBJECT pUart, PVOID pAppBackPtr);
  235. PVOID (*UL_GetAppBackPtr_XXXX)(PUART_OBJECT pUart);
  236. void (*UL_GetConfig_XXXX)(PUART_OBJECT pUart, PUART_CONFIG pUartConfig);
  237. PUART_OBJECT (*UL_GetUartObject_XXXX)(PUART_OBJECT pUart, int Operation);
  238. } UART_LIB, *PUART_LIB;
  239. /* Prototypes - functions should not be called directly */
  240. void UL_SetAppBackPtr(PUART_OBJECT pUart, PVOID pAppBackPtr);
  241. PVOID UL_GetAppBackPtr(PUART_OBJECT pUart);
  242. void UL_GetConfig(PUART_OBJECT pUart, PUART_CONFIG pUartConfig);
  243. PUART_OBJECT UL_GetUartObject(PUART_OBJECT pUart, int Operation);
  244. ULSTATUS UL_InitUartLibrary(PUART_LIB pUartLib, int Library);
  245. void UL_DeInitUartLibrary(PUART_LIB pUartLib);
  246. /* End of prototypes. */
  247. #endif /* End of UARTLIB.H */