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.

336 lines
10 KiB

  1. /******************************************************************************
  2. *
  3. * $Workfile: uartlib.c $
  4. *
  5. * $Author: Psmith $
  6. *
  7. * $Revision: 10 $
  8. *
  9. * $Modtime: 6/07/00 15:19 $
  10. *
  11. * Description: Contains generic UART Library functions.
  12. *
  13. ******************************************************************************/
  14. #include "os.h"
  15. #include "uartlib.h"
  16. #include "uartprvt.h"
  17. #include "lib65x.h"
  18. #include "lib95x.h"
  19. /* Prototypes */
  20. PUART_OBJECT UL_CreateUartObject();
  21. void UL_AddUartToList(PUART_OBJECT pUart, PUART_OBJECT pPreviousUart);
  22. void UL_RemoveUartFromList(PUART_OBJECT pUart);
  23. PUART_OBJECT UL_FindLastUartInList(PUART_OBJECT pUart);
  24. /* End of Prototypes. */
  25. /******************************************************************************
  26. * Creates a UART object.
  27. ******************************************************************************/
  28. PUART_OBJECT UL_CreateUartObject()
  29. {
  30. PUART_OBJECT pUart = NULL;
  31. /* Create UART Object */
  32. pUart = (PUART_OBJECT) UL_ALLOC_AND_ZERO_MEM(sizeof(UART_OBJECT));
  33. return pUart;
  34. }
  35. /******************************************************************************
  36. * Find Last UART object in the list.
  37. ******************************************************************************/
  38. PUART_OBJECT UL_FindLastUartInList(PUART_OBJECT pFirstUart)
  39. {
  40. PUART_OBJECT pUart = pFirstUart;
  41. while(pUart)
  42. {
  43. /* If the next UART is not the first UART */
  44. if(pUart->pNextUart != pFirstUart)
  45. pUart = pUart->pNextUart; /* Get the next UART */
  46. else
  47. break; /* Break we have the last UART */
  48. }
  49. return pUart;
  50. }
  51. /******************************************************************************
  52. * Adds a new UART object to the list.
  53. ******************************************************************************/
  54. void UL_AddUartToList(PUART_OBJECT pUart, PUART_OBJECT pPreviousUart)
  55. {
  56. /* Add new UART object into Linked List. */
  57. if(pPreviousUart == NULL) /* must be a new list */
  58. {
  59. pUart->pPreviousUart = pUart;
  60. pUart->pNextUart = pUart;
  61. }
  62. else
  63. {
  64. pUart->pPreviousUart = pPreviousUart; /* Set pPreviousUart */
  65. pUart->pNextUart = pPreviousUart->pNextUart;
  66. pUart->pPreviousUart->pNextUart = pUart;
  67. pUart->pNextUart->pPreviousUart = pUart;
  68. }
  69. }
  70. /******************************************************************************
  71. * Removes a UART object from the list.
  72. ******************************************************************************/
  73. void UL_RemoveUartFromList(PUART_OBJECT pUart)
  74. {
  75. /* Remove UART from linked list. */
  76. if(pUart->pPreviousUart)
  77. pUart->pPreviousUart->pNextUart = pUart->pNextUart;
  78. if(pUart->pNextUart)
  79. pUart->pNextUart->pPreviousUart = pUart->pPreviousUart;
  80. pUart->pPreviousUart = NULL;
  81. pUart->pNextUart = NULL;
  82. }
  83. /******************************************************************************
  84. * Common Init UART object.
  85. ******************************************************************************/
  86. PUART_OBJECT UL_CommonInitUart(PUART_OBJECT pFirstUart)
  87. {
  88. PUART_OBJECT pUart = NULL, pPreviousUart = NULL;
  89. if(!(pUart = UL_CreateUartObject()))
  90. goto Error; /* Memory allocation failed. */
  91. pPreviousUart = UL_FindLastUartInList(pFirstUart);
  92. /* Add new UART object into Linked List. */
  93. UL_AddUartToList(pUart, pPreviousUart);
  94. if(!pUart->pUartConfig) /* Allocate UART Config storage */
  95. if(!(pUart->pUartConfig = (PUART_CONFIG) UL_ALLOC_AND_ZERO_MEM(sizeof(UART_CONFIG))))
  96. goto Error; /* Memory allocation failed. */
  97. return pUart;
  98. /* InitUart Failed - so Clean up. */
  99. Error:
  100. return NULL;
  101. }
  102. /******************************************************************************
  103. * Common DeInit UART object function.
  104. ******************************************************************************/
  105. void UL_CommonDeInitUart(PUART_OBJECT pUart)
  106. {
  107. if(!pUart)
  108. return;
  109. UL_RemoveUartFromList(pUart);
  110. if(pUart->pUartConfig)
  111. {
  112. UL_FREE_MEM(pUart->pUartConfig, sizeof(UART_CONFIG)); /* Free the UART Config Struct. */
  113. pUart->pUartConfig = NULL;
  114. }
  115. UL_FREE_MEM(pUart, sizeof(UART_OBJECT)); /* Destroy UART Object */
  116. }
  117. /******************************************************************************
  118. * Get Current Config Sturcture.
  119. ******************************************************************************/
  120. void UL_GetConfig(PUART_OBJECT pUart, PUART_CONFIG pUartConfig)
  121. {
  122. UL_COPY_MEM(pUartConfig, pUart->pUartConfig, sizeof(UART_CONFIG));
  123. }
  124. /******************************************************************************
  125. * Set pAppBackPtr from UART Object
  126. ******************************************************************************/
  127. void UL_SetAppBackPtr(PUART_OBJECT pUart, PVOID pAppBackPtr)
  128. {
  129. pUart->pAppBackPtr = pAppBackPtr;
  130. }
  131. /******************************************************************************
  132. * Get pAppBackPtr from UART Object
  133. ******************************************************************************/
  134. PVOID UL_GetAppBackPtr(PUART_OBJECT pUart)
  135. {
  136. return pUart->pAppBackPtr;
  137. }
  138. /******************************************************************************
  139. * UL_GetUartObject
  140. ******************************************************************************/
  141. PUART_OBJECT UL_GetUartObject(PUART_OBJECT pUart, int Operation)
  142. {
  143. PUART_OBJECT RequestedUart = NULL;
  144. if(pUart == NULL)
  145. return NULL;
  146. switch(Operation)
  147. {
  148. case UL_OP_GET_NEXT_UART:
  149. {
  150. /* If the NextUart is the same then we are the only one in the list. */
  151. if(pUart->pNextUart == pUart)
  152. RequestedUart = NULL;
  153. else
  154. RequestedUart = pUart->pNextUart;
  155. break;
  156. }
  157. case UL_OP_GET_PREVIOUS_UART:
  158. {
  159. /* If the PreviousUart is the same then we are the only one in the list. */
  160. if(pUart->pPreviousUart == pUart)
  161. RequestedUart = NULL;
  162. else
  163. RequestedUart = pUart->pPreviousUart;
  164. break;
  165. }
  166. default:
  167. break;
  168. }
  169. return RequestedUart;
  170. }
  171. /******************************************************************************
  172. * UL_InitUartLibrary
  173. ******************************************************************************/
  174. ULSTATUS UL_InitUartLibrary(PUART_LIB pUartLib, int Library)
  175. {
  176. ULSTATUS ULStatus = UL_STATUS_UNSUCCESSFUL;
  177. if(pUartLib != NULL)
  178. {
  179. switch(Library)
  180. {
  181. case UL_LIB_16C65X_UART: /* UART library functions for 16C65x UART */
  182. {
  183. pUartLib->UL_InitUart_XXXX = UL_InitUart_16C65X;
  184. pUartLib->UL_DeInitUart_XXXX = UL_DeInitUart_16C65X;
  185. pUartLib->UL_ResetUart_XXXX = UL_ResetUart_16C65X;
  186. pUartLib->UL_VerifyUart_XXXX = UL_VerifyUart_16C65X;
  187. pUartLib->UL_SetConfig_XXXX = UL_SetConfig_16C65X;
  188. pUartLib->UL_BufferControl_XXXX = UL_BufferControl_16C65X;
  189. pUartLib->UL_ModemControl_XXXX = UL_ModemControl_16C65X;
  190. pUartLib->UL_IntsPending_XXXX = UL_IntsPending_16C65X;
  191. pUartLib->UL_GetUartInfo_XXXX = UL_GetUartInfo_16C65X;
  192. pUartLib->UL_OutputData_XXXX = UL_OutputData_16C65X;
  193. pUartLib->UL_InputData_XXXX = UL_InputData_16C65X;
  194. pUartLib->UL_ReadData_XXXX = UL_ReadData_16C65X;
  195. pUartLib->UL_WriteData_XXXX = UL_WriteData_16C65X;
  196. pUartLib->UL_ImmediateByte_XXXX = UL_ImmediateByte_16C65X;
  197. pUartLib->UL_GetStatus_XXXX = UL_GetStatus_16C65X;
  198. pUartLib->UL_DumpUartRegs_XXXX = UL_DumpUartRegs_16C65X;
  199. pUartLib->UL_SetAppBackPtr_XXXX = UL_SetAppBackPtr_16C65X;
  200. pUartLib->UL_GetAppBackPtr_XXXX = UL_GetAppBackPtr_16C65X;
  201. pUartLib->UL_GetConfig_XXXX = UL_GetConfig_16C65X;
  202. pUartLib->UL_GetUartObject_XXXX = UL_GetUartObject_16C65X;
  203. ULStatus = UL_STATUS_SUCCESS;
  204. break;
  205. }
  206. case UL_LIB_16C95X_UART: /* UART library functions for 16C95x UART */
  207. {
  208. pUartLib->UL_InitUart_XXXX = UL_InitUart_16C95X;
  209. pUartLib->UL_DeInitUart_XXXX = UL_DeInitUart_16C95X;
  210. pUartLib->UL_ResetUart_XXXX = UL_ResetUart_16C95X;
  211. pUartLib->UL_VerifyUart_XXXX = UL_VerifyUart_16C95X;
  212. pUartLib->UL_SetConfig_XXXX = UL_SetConfig_16C95X;
  213. pUartLib->UL_BufferControl_XXXX = UL_BufferControl_16C95X;
  214. pUartLib->UL_ModemControl_XXXX = UL_ModemControl_16C95X;
  215. pUartLib->UL_IntsPending_XXXX = UL_IntsPending_16C95X;
  216. pUartLib->UL_GetUartInfo_XXXX = UL_GetUartInfo_16C95X;
  217. pUartLib->UL_OutputData_XXXX = UL_OutputData_16C95X;
  218. pUartLib->UL_InputData_XXXX = UL_InputData_16C95X;
  219. pUartLib->UL_ReadData_XXXX = UL_ReadData_16C95X;
  220. pUartLib->UL_WriteData_XXXX = UL_WriteData_16C95X;
  221. pUartLib->UL_ImmediateByte_XXXX = UL_ImmediateByte_16C95X;
  222. pUartLib->UL_GetStatus_XXXX = UL_GetStatus_16C95X;
  223. pUartLib->UL_DumpUartRegs_XXXX = UL_DumpUartRegs_16C95X;
  224. pUartLib->UL_SetAppBackPtr_XXXX = UL_SetAppBackPtr_16C95X;
  225. pUartLib->UL_GetAppBackPtr_XXXX = UL_GetAppBackPtr_16C95X;
  226. pUartLib->UL_GetConfig_XXXX = UL_GetConfig_16C95X;
  227. pUartLib->UL_GetUartObject_XXXX = UL_GetUartObject_16C95X;
  228. ULStatus = UL_STATUS_SUCCESS;
  229. break;
  230. }
  231. default: /* Unknown UART */
  232. ULStatus = UL_STATUS_INVALID_PARAMETER;
  233. break;
  234. }
  235. }
  236. return ULStatus;
  237. }
  238. /******************************************************************************
  239. * UL_DeInitUartLibrary
  240. ******************************************************************************/
  241. void UL_DeInitUartLibrary(PUART_LIB pUartLib)
  242. {
  243. ULSTATUS ULStatus = UL_STATUS_UNSUCCESSFUL;
  244. if(pUartLib != NULL)
  245. {
  246. pUartLib->UL_InitUart_XXXX = NULL;
  247. pUartLib->UL_DeInitUart_XXXX = NULL;
  248. pUartLib->UL_ResetUart_XXXX = NULL;
  249. pUartLib->UL_VerifyUart_XXXX = NULL;
  250. pUartLib->UL_SetConfig_XXXX = NULL;
  251. pUartLib->UL_BufferControl_XXXX = NULL;
  252. pUartLib->UL_ModemControl_XXXX = NULL;
  253. pUartLib->UL_IntsPending_XXXX = NULL;
  254. pUartLib->UL_GetUartInfo_XXXX = NULL;
  255. pUartLib->UL_OutputData_XXXX = NULL;
  256. pUartLib->UL_InputData_XXXX = NULL;
  257. pUartLib->UL_ReadData_XXXX = NULL;
  258. pUartLib->UL_WriteData_XXXX = NULL;
  259. pUartLib->UL_ImmediateByte_XXXX = NULL;
  260. pUartLib->UL_GetStatus_XXXX = NULL;
  261. pUartLib->UL_DumpUartRegs_XXXX = NULL;
  262. pUartLib->UL_SetAppBackPtr_XXXX = NULL;
  263. pUartLib->UL_GetAppBackPtr_XXXX = NULL;
  264. pUartLib->UL_GetConfig_XXXX = NULL;
  265. pUartLib->UL_GetUartObject_XXXX = NULL;
  266. }
  267. }