romapi_uart.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * @brief UART ROM API declarations and functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2014
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef __ROMAPI_UART_H_
  32. #define __ROMAPI_UART_H_
  33. #include "hw_uart_rom_api.h"
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /** @defgroup ROMAPI_UART_WRAPPER CHIP: UART ROM wrapper functions
  38. * @ingroup ROMAPI_5410X
  39. * @{
  40. */
  41. /**
  42. * @brief Get memory size in bytes needed for SPI master driver context
  43. * @return Size in bytes needed for the ROM driver
  44. */
  45. uint32_t ROM_UART_GetMemSize(void);
  46. /**
  47. * @brief Initialize UART ROM Driver
  48. * @param pMem : Pointer to memory area for driver context
  49. * @param baseAddr : Base address of the UART peripheral
  50. * @param pUserData : Pointer to User Data
  51. * @return Pointer to the device context handle or NULL on alignment failure
  52. * @note Parameter @a pMem must be a pointer to word aligned memory
  53. * if the pointer is not word aligned (4-Byte) the function returns
  54. * NULL.
  55. */
  56. UART_HANDLE_T ROM_UART_Init(void *pMem, uint32_t baseAddr, void *pUserData);
  57. /**
  58. * @brief Configure the UART peripheral
  59. * @param hUART : Handle to UART obtained using ROM_UART_Init()
  60. * @param pCfg : Pointer to configuration structure #UART_CFG_T
  61. * @return LPC_OK on Success, ERR_UART_PARAM if any of cfg values are invalid
  62. */
  63. ErrorCode_t ROM_UART_Configure(UART_HANDLE_T hUART, const UART_CFG_T *pCfg);
  64. /**
  65. * @brief Calculate UART Baud rate parameters
  66. * @param baud : [IN/OUT] Pointer to baud rate structure
  67. * @return LPC_OK on Success, ERR_UART_BAUDRATE baudrate for given frequency is not within limits
  68. * @sa UART_BAUD_T
  69. */
  70. ErrorCode_t ROM_UART_CalBaud(UART_BAUD_T *baud);
  71. /**
  72. * @brief Set UART Control operations
  73. * @param hUART : Handle to UART obtained using ROM_UART_Init()
  74. * @param cfgVal : Configuration value (one or more (OR'ed) values of #UART_BREAK_ON, #UART_TX_PAUSE etc)
  75. * @return Nothing
  76. * @note
  77. * To set TX in BREAK state, use <b>ROM_UART_SetCtrl(hUART, UART_BREAK_ON)</b>, to bring TX out of BREAK state
  78. * use <b>ROM_UART_SetCtrl(hUART, UART_BREAK_OFF)</b>. Us the above method will set TX line to BREAK state even
  79. * if there is a data is being sent, hence the receiver might get a UART FRAME error and the data in progress might
  80. * get lost. To avoid this application can pause TX before the TX gets to BREAK state by calling, <b>
  81. * ROM_UART_SetCtrl(hUART, #UART_BREAK_ON | #UART_TX_PAUSE)</b> and release the break by calling <b>
  82. * ROM_UART_SetCtrl(hUART, #UART_BREAK_OFF | #UART_TX_RESUME)</b>.<br>
  83. * <b>ROM_UART_SetCtrl(hUART, #UART_TX_PAUSE)</b> will stop the TX until <b>ROM_UART_SetCtrl(hUART,
  84. * #UART_TX_RESUME)</b> * this could be used to implement flow-control.
  85. */
  86. void ROM_UART_SetCtrl(UART_HANDLE_T hUART, uint32_t cfgVal);
  87. /**
  88. * @brief Registers a callback function associated with an event
  89. * @param hUART : Handle to UART obtained using ROM_UART_Init()
  90. * @param cbIndex : Index of the call-back function (Associated with an event)
  91. * @param pCbFunc : Pointer to callback function
  92. * @return Success or failure
  93. * @retval LPC_OK Callback successfully registered
  94. * @retval ERR_UART_PARAM Invaild event parameter for @a cbIndex
  95. */
  96. ErrorCode_t ROM_UART_RegisterCB(UART_HANDLE_T hUART, UART_CBINDEX_T cbIndex, void (*pCbFunc)(UART_HANDLE_T,
  97. UART_EVENT_T,
  98. void *));
  99. /**
  100. * @brief UART Event handler function (Usually called from interrupt handler)
  101. * @param hUART : Handle to UART obtained using ROM_UART_Init()
  102. * @return Nothing
  103. */
  104. void ROM_UART_Handler(UART_HANDLE_T hUART);
  105. /**
  106. * @brief Send data to UART
  107. * @param hUART : Handle to UART obtained using ROM_UART_Init()
  108. * @param buffer : Buffer to send
  109. * @param size : Number of items in buffer
  110. * @return LPC_OK when buffer is queued successfully for sending
  111. * @note If the UART Data size is 9, then buffer should be of type
  112. * uint16_t *, size should be number of uint16_t (not size in bytes).
  113. */
  114. ErrorCode_t ROM_UART_Send(UART_HANDLE_T hUART, const void *buffer, uint16_t size);
  115. /**
  116. * @brief Receive data from UART
  117. * @param hUART : Handle to UART obtained using ROM_UART_Init()
  118. * @param buffer : Buffer to send
  119. * @param size : Number of items in buffer
  120. * @return LPC_OK when buffer is queued successfully for receiving data
  121. * @note If the UART Data size is 9, then buffer should be of type
  122. * uint16_t *, size should be number of uint16_t (not size in bytes).
  123. */
  124. ErrorCode_t ROM_UART_Receive(UART_HANDLE_T hUART, void *buffer, uint16_t size);
  125. /**
  126. * @brief Send data to UART [Blocking]
  127. * @param hUART : Handle to UART obtained using ROM_UART_Init()
  128. * @param buffer : Buffer to send
  129. * @param size : Number of items in buffer
  130. * @return LPC_OK when buffer is queued successfully for sending
  131. * @note If the UART Data size is 9, then buffer should be of type
  132. * uint16_t *, size should be number of uint16_t (not size in bytes).
  133. * <b> This API is not in the ROM this is a wrapper API, that uses
  134. * @a ROM_UART_Send() and @a ROM_UART_FlushTx()</b>
  135. */
  136. ErrorCode_t ROM_UART_SendBlock(UART_HANDLE_T hUART, const void *buffer, uint16_t size);
  137. /**
  138. * @brief Receive data from UART [Blocking]
  139. * @param hUART : Handle to UART obtained using ROM_UART_Init()
  140. * @param buffer : Buffer to send
  141. * @param size : Number of items in buffer
  142. * @return LPC_OK when buffer is queued successfully for receiving data
  143. * @note If the UART Data size is 9, then buffer should be of type
  144. * uint16_t *, size should be number of uint16_t (not size in bytes).
  145. * <b> This API is not in the ROM this is a wrapper API, that uses
  146. * @a ROM_UART_Receive() and @a ROM_UART_FetchRx()</b>
  147. */
  148. ErrorCode_t ROM_UART_ReceiveBlock(UART_HANDLE_T hUART, void *buffer, uint16_t size);
  149. /**
  150. * @brief Wait for the current TX buffer to be sent
  151. * @param hUART : Handle to UART obtained using ROM_UART_Init()
  152. * @return Nothing
  153. * @note This call will bock the excution till all the data bytes are sent.
  154. * @sa ROM_UART_Send()
  155. */
  156. void ROM_UART_WaitTx(UART_HANDLE_T hUART);
  157. /**
  158. * @brief Complete the current Receive transfer
  159. * @param hUART : Handle to UART obtained using ROM_UART_Init()
  160. * @return Nothing
  161. * @note This call will bock the excution till all the data bytes are read,
  162. * if there is no RX in progress this call will read and discard the current
  163. * pending RX data and the incoming data until there is no data coming from uart
  164. * atleast for one data time, mainly used for discarding UART frames that had
  165. * started arriving and overflown before the ROM_UART_Receive was called.
  166. * @sa ROM_UART_Receive()
  167. */
  168. void ROM_UART_WaitRx(UART_HANDLE_T hUART);
  169. /**
  170. * @brief Return the UART ROM driver version
  171. * @return Driver version number
  172. * @note The returned driver version number consists of a major and minor
  173. * number, with the minor number in the lower 8 bits and the major number in
  174. * the upper 8 bits.
  175. */
  176. uint16_t ROM_UART_GetDriverVersion(void);
  177. /**
  178. * @}
  179. */
  180. #ifdef __cplusplus
  181. }
  182. #endif
  183. #endif /* __ROMAPI_UART_H_ */