Lpuart_Uart_Ip.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : FLEXIO
  5. * Dependencies :
  6. *
  7. * Autosar Version : 4.4.0
  8. * Autosar Revision : ASR_REL_4_4_REV_0000
  9. * Autosar Conf.Variant :
  10. * SW Version : 1.0.0
  11. * Build Version : S32K1_RTD_1_0_0_HF01_D2109_ASR_REL_4_4_REV_0000_20210907
  12. *
  13. * (c) Copyright 2020-2021 NXP Semiconductors
  14. * All Rights Reserved.
  15. *
  16. * NXP Confidential. This software is owned or controlled by NXP and may only be
  17. * used strictly in accordance with the applicable license terms. By expressly
  18. * accepting such terms or by downloading, installing, activating and/or otherwise
  19. * using the software, you are agreeing that you have read, and that you agree to
  20. * comply with and are bound by, such license terms. If you do not agree to be
  21. * bound by the applicable license terms, then you may not retain, install,
  22. * activate or otherwise use the software.
  23. ==================================================================================================*/
  24. #ifndef LPUART_UART_IP_H
  25. #define LPUART_UART_IP_H
  26. /**
  27. * @file
  28. * @defgroup lpuart_uart_ip Lpuart UART IPL
  29. * @addtogroup lpuart_uart_ip Lpuart UART IPL
  30. * @{
  31. */
  32. #ifdef __cplusplus
  33. extern "C"{
  34. #endif
  35. /*==================================================================================================
  36. * INCLUDE FILES
  37. * 1) system and project includes
  38. * 2) needed interfaces from external units
  39. * 3) internal and external interfaces from this unit
  40. ==================================================================================================*/
  41. #include "Lpuart_Uart_Ip_Types.h"
  42. #include "Lpuart_Uart_Ip_Cfg.h"
  43. #include "Mcal.h"
  44. /*==================================================================================================
  45. * SOURCE FILE VERSION INFORMATION
  46. ==================================================================================================*/
  47. #define LPUART_UART_IP_VENDOR_ID 43
  48. #define LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION 4
  49. #define LPUART_UART_IP_AR_RELEASE_MINOR_VERSION 4
  50. #define LPUART_UART_IP_AR_RELEASE_REVISION_VERSION 0
  51. #define LPUART_UART_IP_SW_MAJOR_VERSION 1
  52. #define LPUART_UART_IP_SW_MINOR_VERSION 0
  53. #define LPUART_UART_IP_SW_PATCH_VERSION 0
  54. /*==================================================================================================
  55. * FILE VERSION CHECKS
  56. ==================================================================================================*/
  57. /* Checks against Lpuart_Uart_Ip_Types.h */
  58. #if (LPUART_UART_IP_VENDOR_ID != LPUART_UART_IP_TYPES_VENDOR_ID)
  59. #error "Lpuart_Uart_Ip.h and Lpuart_Uart_Ip_Types.h have different vendor ids"
  60. #endif
  61. #if ((LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION != LPUART_UART_IP_TYPES_AR_RELEASE_MAJOR_VERSION) || \
  62. (LPUART_UART_IP_AR_RELEASE_MINOR_VERSION != LPUART_UART_IP_TYPES_AR_RELEASE_MINOR_VERSION) || \
  63. (LPUART_UART_IP_AR_RELEASE_REVISION_VERSION != LPUART_UART_IP_TYPES_AR_RELEASE_REVISION_VERSION))
  64. #error "AUTOSAR Version Numbers of Lpuart_Uart_Ip.h and Lpuart_Uart_Ip_Types.h are different"
  65. #endif
  66. #if ((LPUART_UART_IP_SW_MAJOR_VERSION != LPUART_UART_IP_TYPES_SW_MAJOR_VERSION) || \
  67. (LPUART_UART_IP_SW_MINOR_VERSION != LPUART_UART_IP_TYPES_SW_MINOR_VERSION) || \
  68. (LPUART_UART_IP_SW_PATCH_VERSION != LPUART_UART_IP_TYPES_SW_PATCH_VERSION))
  69. #error "Software Version Numbers of Lpuart_Uart_Ip.h and Lpuart_Uart_Ip_Types.h are different"
  70. #endif
  71. /* Checks against Lpuart_Uart_Ip_Cfg.h */
  72. #if (LPUART_UART_IP_VENDOR_ID != LPUART_UART_IP_CFG_VENDOR_ID)
  73. #error "Lpuart_Uart_Ip.h and Lpuart_Uart_Ip_Cfg.h have different vendor ids"
  74. #endif
  75. #if ((LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION != LPUART_UART_IP_CFG_AR_RELEASE_MAJOR_VERSION) || \
  76. (LPUART_UART_IP_AR_RELEASE_MINOR_VERSION != LPUART_UART_IP_CFG_AR_RELEASE_MINOR_VERSION) || \
  77. (LPUART_UART_IP_AR_RELEASE_REVISION_VERSION != LPUART_UART_IP_CFG_AR_RELEASE_REVISION_VERSION))
  78. #error "AUTOSAR Version Numbers of Lpuart_Uart_Ip.h and Lpuart_Uart_Ip_Cfg.h are different"
  79. #endif
  80. #if ((LPUART_UART_IP_SW_MAJOR_VERSION != LPUART_UART_IP_CFG_SW_MAJOR_VERSION) || \
  81. (LPUART_UART_IP_SW_MINOR_VERSION != LPUART_UART_IP_CFG_SW_MINOR_VERSION) || \
  82. (LPUART_UART_IP_SW_PATCH_VERSION != LPUART_UART_IP_CFG_SW_PATCH_VERSION))
  83. #error "Software Version Numbers of Lpuart_Uart_Ip.h and Lpuart_Uart_Ip_Cfg.h are different"
  84. #endif
  85. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  86. /* Checks against Mcal.h */
  87. #if ((LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION != MCAL_AR_RELEASE_MAJOR_VERSION) || \
  88. (LPUART_UART_IP_AR_RELEASE_MINOR_VERSION != MCAL_AR_RELEASE_MINOR_VERSION))
  89. #error "AUTOSAR Version Numbers of Lpuart_Uart_Ip.h and Mcal.h are different"
  90. #endif
  91. #endif
  92. /*==================================================================================================
  93. * CONSTANTS
  94. ==================================================================================================*/
  95. #define UART_START_SEC_CONFIG_DATA_UNSPECIFIED
  96. #include "Uart_MemMap.h"
  97. /* Calling the external Configuration symbols defined by Lpuart_Uart_Ip_Cfg.h */
  98. LPUART_UART_IP_CONFIG_EXT
  99. #define UART_STOP_SEC_CONFIG_DATA_UNSPECIFIED
  100. #include "Uart_MemMap.h"
  101. /*==================================================================================================
  102. * DEFINES AND MACROS
  103. ==================================================================================================*/
  104. /*==================================================================================================
  105. * ENUMS
  106. ==================================================================================================*/
  107. /*==================================================================================================
  108. * STRUCTURES AND OTHER TYPEDEFS
  109. ==================================================================================================*/
  110. /*==================================================================================================
  111. * GLOBAL VARIABLE DECLARATIONS
  112. ==================================================================================================*/
  113. /*==================================================================================================
  114. * FUNCTION PROTOTYPES
  115. ==================================================================================================*/
  116. #define UART_START_SEC_CODE
  117. #include "Uart_MemMap.h"
  118. /*!
  119. * @brief Initializes an LPUART operation instance.
  120. *
  121. * The caller provides memory for the driver state structures during initialization.
  122. * The user must select the LPUART clock source in the application to initialize the LPUART.
  123. *
  124. * @param Instance LPUART instance number
  125. * @param UserConfig user configuration structure of type #Lpuart_Uart_Ip_UserConfigType
  126. * @return void
  127. */
  128. void Lpuart_Uart_Ip_Init(const uint8 Instance, const Lpuart_Uart_Ip_UserConfigType * UserConfig);
  129. /*!
  130. * @brief Shuts down the LPUART by disabling interrupts and transmitter/receiver.
  131. *
  132. * @param Instance LPUART instance number
  133. * @return void
  134. */
  135. void Lpuart_Uart_Ip_Deinit(const uint8 Instance);
  136. /*!
  137. * @brief Send out multiple bytes of data using polling method.
  138. *
  139. * @param Instance LPUART instance number.
  140. * @param TxBuff The buffer pointer which saves the data to be sent.
  141. * @param TxSize Size of data to be sent in unit of byte.
  142. * @param Timeout value in microseconds.
  143. * @return LPUART_UART_IP_STATUS_SUCCESS if successful;
  144. * LPUART_UART_IP_STATUS_BUSY if the resource is busy;
  145. * LPUART_UART_IP_STATUS_TIMEOUT if timeout occur
  146. */
  147. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SyncSend(const uint8 Instance,
  148. const uint8 *TxBuff,
  149. const uint32 TxSize,
  150. const uint32 Timeout);
  151. /*!
  152. * @brief Sends data out through the LPUART module using a non-blocking method.
  153. * This enables an a-sync method for transmitting data. When used with
  154. * a non-blocking receive, the LPUART can perform a full duplex operation.
  155. * Non-blocking means that the function returns immediately.
  156. * The application has to get the transmit status to know when the transmit is complete.
  157. *
  158. * @param Instance LPUART instance number.
  159. * @param TxBuff The buffer pointer which saves the data to be sent.
  160. * @param TxSize Size of data to be sent in unit of byte.
  161. * @return LPUART_UART_IP_STATUS_SUCCESS if successful;
  162. * LPUART_UART_IP_STATUS_BUSY if the resource is busy;
  163. */
  164. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_AsyncSend(const uint8 Instance,
  165. const uint8 * TxBuff,
  166. const uint32 TxSize);
  167. /*!
  168. * @brief Returns whether the previous transmit is complete.
  169. *
  170. * @param Instance LPUART instance number
  171. * @param BytesRemaining Pointer to value that is populated with the number of bytes that
  172. * have been sent in the active transfer
  173. * @note In DMA mode, this parameter may not be accurate, in case the transfer completes
  174. * right after calling this function; in this edge-case, the parameter will reflect
  175. * the initial transfer size, due to automatic reloading of the major loop count
  176. * in the DMA transfer descriptor.
  177. * @return The transmit status.
  178. * @retval LPUART_UART_IP_STATUS_SUCCESS The transmit has completed successfully.
  179. * @retval LPUART_UART_IP_STATUS_BUSY The transmit is still in progress. @a bytesRemaining will be
  180. * filled with the number of bytes that are yet to be transmitted.
  181. * @retval LPUART_UART_IP_STATUS_ABORTED The transmit was aborted.
  182. * @retval LPUART_UART_IP_STATUS_TIMEOUT A timeout was reached.
  183. * @retval LPUART_UART_IP_STATUS_ERROR An error occurred.
  184. */
  185. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_GetTransmitStatus(const uint8 Instance, uint32 * BytesRemaining);
  186. /*!
  187. * @brief Terminates a non-blocking transmission early.
  188. *
  189. * @param instance LPUART instance number
  190. * @return Whether the aborting is successful or not.
  191. */
  192. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_AbortSendingData(const uint8 Instance);
  193. /*!
  194. * @brief Receive multiple bytes of data using polling method.
  195. *
  196. *
  197. * @param Instance LPUART instance number.
  198. * @param RxBuff The buffer pointer which saves the data to be received.
  199. * @param RxSize Size of data need to be received in unit of byte.
  200. * @param Timeout value in microseconds.
  201. * @return LPUART_UART_IP_STATUS_SUCCESS if the transaction is successful;
  202. * LPUART_UART_IP_STATUS_BUSY if the resource is busy;
  203. * LPUART_UART_IP_STATUS_RX_OVERRUN if an overrun error occured
  204. * LPUART_UART_IP_STATUS_FRAMING_ERROR if a framing error occured
  205. * LPUART_UART_IP_STATUS_PARITY_ERROR if a parity error occured
  206. * LPUART_UART_IP_STATUS_NOISE_ERROR if a noise error occured
  207. * LPUART_UART_IP_STATUS_TIMEOUT if timeout occur
  208. */
  209. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SyncReceive(const uint8 Instance,
  210. uint8 *RxBuff,
  211. const uint32 RxSize,
  212. const uint32 Timeout);
  213. /*!
  214. * @brief Gets data from the LPUART module by using a non-blocking method.
  215. * This enables an a-sync method for receiving data. When used with
  216. * a non-blocking transmission, the LPUART can perform a full duplex operation.
  217. * Non-blocking means that the function returns immediately.
  218. * The application has to get the receive status to know when the receive is complete.
  219. *
  220. * @param Instance LPUART instance number
  221. * @param RxBuff buffer containing 8-bit read data chars received
  222. * @param RxSize the number of bytes to receive
  223. * @return LPUART_UART_IP_STATUS_SUCCESS if successful;
  224. * LPUART_UART_IP_STATUS_BUSY if the resource is busy
  225. */
  226. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_AsyncReceive(const uint8 Instance,
  227. uint8 * RxBuff,
  228. const uint32 RxSize);
  229. /*!
  230. * @brief Returns whether the previous receive is complete.
  231. *
  232. * @param Instance LPUART instance number
  233. * @param BytesRemaining pointer to value that is filled with the number of bytes that
  234. * still need to be received in the active transfer.
  235. * @note In DMA mode, this parameter may not be accurate, in case the transfer completes
  236. * right after calling this function; in this edge-case, the parameter will reflect
  237. * the initial transfer size, due to automatic reloading of the major loop count
  238. * in the DMA transfer descriptor.
  239. * @return The receive status.
  240. * @retval LPUART_UART_IP_STATUS_SUCCESS the receive has completed successfully.
  241. * @retval LPUART_UART_IP_STATUS_BUSY the receive is still in progress. @a bytesReceived will be
  242. * filled with the number of bytes that have been received so far.
  243. * @retval LPUART_UART_IP_STATUS_ABORTED The receive was aborted.
  244. * @retval LPUART_UART_IP_STATUS_TIMEOUT A timeout was reached.
  245. * @retval LPUART_UART_IP_STATUS_RX_OVERRUN, LPUART_UART_IP_STATUS_FRAMING_ERROR, LPUART_UART_IP_STATUS_PARITY_ERROR,
  246. or LPUART_UART_IP_STATUS_NOISE_ERROR, LPUART_UART_IP_STATUS_ERROR An error occurred during reception.
  247. */
  248. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_GetReceiveStatus(const uint8 Instance, uint32 * BytesRemaining);
  249. /*!
  250. * @brief Terminates a non-blocking receive early.
  251. *
  252. * @param Instance LPUART instance number
  253. *
  254. * @return Whether the receiving was successful or not.
  255. */
  256. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_AbortReceivingData(const uint8 Instance);
  257. /*!
  258. * @brief Configures the LPUART baud rate.
  259. *
  260. * This function configures the LPUART baud rate.
  261. * In some LPUART instances the user must disable the transmitter/receiver
  262. * before calling this function.
  263. * Generally, this may be applied to all LPUARTs to ensure safe operation.
  264. *
  265. * @param Instance LPUART instance number.
  266. * @param DesiredBaudrate LPUART desired baud rate.
  267. * @param ClockFrequency Clock Frequency of LPUART instance.
  268. * @return LPUART_UART_IP_STATUS_BUSY if called during an on-going transfer, LPUART_UART_IP_STATUS_SUCCESS otherwise
  269. */
  270. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SetBaudRate(const uint8 Instance,
  271. const Lpuart_Uart_Ip_BaudrateType DesiredBaudrate,
  272. const uint32 ClockFrequency);
  273. /*!
  274. * @brief Returns the LPUART baud rate.
  275. *
  276. * This function returns the LPUART configured baud rate.
  277. *
  278. * @param Instance LPUART instance number.
  279. * @param[out] ConfiguredBaudRate LPUART configured baud rate.
  280. */
  281. void Lpuart_Uart_Ip_GetBaudRate(const uint8 Instance, uint32 * ConfiguredBaudRate);
  282. /*!
  283. * @brief Sets the internal driver reference to the tx buffer.
  284. *
  285. * This function can be called from the tx callback to provide the driver
  286. * with a new buffer, for continuous transmission.
  287. *
  288. * @param Instance LPUART instance number
  289. * @param TxBuff source buffer containing 8-bit data chars to send
  290. * @param TxSize the number of bytes to send
  291. * @return LPUART_UART_IP_STATUS_SUCCESS
  292. */
  293. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SetTxBuffer(const uint8 Instance,
  294. const uint8 * TxBuff,
  295. const uint32 TxSize);
  296. /*!
  297. * @brief Sets the internal driver reference to the rx buffer.
  298. *
  299. * This function can be called from the rx callback to provide the driver
  300. * with a new buffer, for continuous reception.
  301. *
  302. * @param instance LPUART instance number
  303. * @param RxBuff destination buffer containing 8-bit data chars to receive
  304. * @param RxSize the number of bytes to receive
  305. * @return LPUART_UART_IP_STATUS_SUCCESS
  306. */
  307. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SetRxBuffer(const uint8 Instance,
  308. uint8 * RxBuff,
  309. const uint32 RxSize);
  310. void Lpuart_Uart_Ip_IrqHandler(const uint8 Instance);
  311. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  312. /**
  313. * @internal
  314. * @brief : Finish up a transmit by completing the process of sending
  315. * data and disabling the DMA requests. This is a part of callback for DMA major loop
  316. * completion, so it must match the DMA callback signature.
  317. * @param Instance Lpuart instance number
  318. * @return void
  319. */
  320. void Lpuart_Uart_Ip_CompleteSendUsingDma(uint8 Instance);
  321. /**
  322. * @internal
  323. * @brief : Finish up a receive by completing the process of receiving data
  324. * and disabling the DMA requests. This is a part of callback for DMA major loop
  325. * completion, so it must match the DMA callback signature.
  326. * @param Instance Lpuart instance number
  327. * @return void
  328. */
  329. void Lpuart_Uart_Ip_CompleteReceiveUsingDma(uint8 Instance);
  330. #endif
  331. #define UART_STOP_SEC_CODE
  332. #include "Uart_MemMap.h"
  333. #if defined(__cplusplus)
  334. }
  335. #endif
  336. /*! @}*/
  337. #endif /* LPUART_UART_IP_H */