fsl_flexio_uart.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /*
  2. * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2021 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_FLEXIO_UART_H_
  9. #define _FSL_FLEXIO_UART_H_
  10. #include "fsl_common.h"
  11. #include "fsl_flexio.h"
  12. /*!
  13. * @addtogroup flexio_uart
  14. * @{
  15. */
  16. /*******************************************************************************
  17. * Definitions
  18. ******************************************************************************/
  19. /*! @name Driver version */
  20. /*@{*/
  21. /*! @brief FlexIO UART driver version. */
  22. #define FSL_FLEXIO_UART_DRIVER_VERSION (MAKE_VERSION(2, 4, 0))
  23. /*@}*/
  24. /*! @brief Retry times for waiting flag. */
  25. #ifndef UART_RETRY_TIMES
  26. #define UART_RETRY_TIMES 0U /* Defining to zero means to keep waiting for the flag until it is assert/deassert. */
  27. #endif
  28. /*! @brief Error codes for the UART driver. */
  29. enum
  30. {
  31. kStatus_FLEXIO_UART_TxBusy = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 0), /*!< Transmitter is busy. */
  32. kStatus_FLEXIO_UART_RxBusy = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 1), /*!< Receiver is busy. */
  33. kStatus_FLEXIO_UART_TxIdle = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 2), /*!< UART transmitter is idle. */
  34. kStatus_FLEXIO_UART_RxIdle = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 3), /*!< UART receiver is idle. */
  35. kStatus_FLEXIO_UART_ERROR = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 4), /*!< ERROR happens on UART. */
  36. kStatus_FLEXIO_UART_RxRingBufferOverrun =
  37. MAKE_STATUS(kStatusGroup_FLEXIO_UART, 5), /*!< UART RX software ring buffer overrun. */
  38. kStatus_FLEXIO_UART_RxHardwareOverrun = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 6), /*!< UART RX receiver overrun. */
  39. kStatus_FLEXIO_UART_Timeout = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 7), /*!< UART times out. */
  40. kStatus_FLEXIO_UART_BaudrateNotSupport =
  41. MAKE_STATUS(kStatusGroup_FLEXIO_UART, 8) /*!< Baudrate is not supported in current clock source */
  42. };
  43. /*! @brief FlexIO UART bit count per char. */
  44. typedef enum _flexio_uart_bit_count_per_char
  45. {
  46. kFLEXIO_UART_7BitsPerChar = 7U, /*!< 7-bit data characters */
  47. kFLEXIO_UART_8BitsPerChar = 8U, /*!< 8-bit data characters */
  48. kFLEXIO_UART_9BitsPerChar = 9U, /*!< 9-bit data characters */
  49. } flexio_uart_bit_count_per_char_t;
  50. /*! @brief Define FlexIO UART interrupt mask. */
  51. enum _flexio_uart_interrupt_enable
  52. {
  53. kFLEXIO_UART_TxDataRegEmptyInterruptEnable = 0x1U, /*!< Transmit buffer empty interrupt enable. */
  54. kFLEXIO_UART_RxDataRegFullInterruptEnable = 0x2U, /*!< Receive buffer full interrupt enable. */
  55. };
  56. /*! @brief Define FlexIO UART status mask. */
  57. enum _flexio_uart_status_flags
  58. {
  59. kFLEXIO_UART_TxDataRegEmptyFlag = 0x1U, /*!< Transmit buffer empty flag. */
  60. kFLEXIO_UART_RxDataRegFullFlag = 0x2U, /*!< Receive buffer full flag. */
  61. kFLEXIO_UART_RxOverRunFlag = 0x4U, /*!< Receive buffer over run flag. */
  62. };
  63. /*! @brief Define FlexIO UART access structure typedef. */
  64. typedef struct _flexio_uart_type
  65. {
  66. FLEXIO_Type *flexioBase; /*!< FlexIO base pointer. */
  67. uint8_t TxPinIndex; /*!< Pin select for UART_Tx. */
  68. uint8_t RxPinIndex; /*!< Pin select for UART_Rx. */
  69. uint8_t shifterIndex[2]; /*!< Shifter index used in FlexIO UART. */
  70. uint8_t timerIndex[2]; /*!< Timer index used in FlexIO UART. */
  71. } FLEXIO_UART_Type;
  72. /*! @brief Define FlexIO UART user configuration structure. */
  73. typedef struct _flexio_uart_config
  74. {
  75. bool enableUart; /*!< Enable/disable FlexIO UART TX & RX. */
  76. bool enableInDoze; /*!< Enable/disable FlexIO operation in doze mode*/
  77. bool enableInDebug; /*!< Enable/disable FlexIO operation in debug mode*/
  78. bool enableFastAccess; /*!< Enable/disable fast access to FlexIO registers,
  79. fast access requires the FlexIO clock to be at least
  80. twice the frequency of the bus clock. */
  81. uint32_t baudRate_Bps; /*!< Baud rate in Bps. */
  82. flexio_uart_bit_count_per_char_t bitCountPerChar; /*!< number of bits, 7/8/9 -bit */
  83. } flexio_uart_config_t;
  84. /*! @brief Define FlexIO UART transfer structure. */
  85. typedef struct _flexio_uart_transfer
  86. {
  87. /*
  88. * Use separate TX and RX data pointer, because TX data is const data.
  89. * The member data is kept for backward compatibility.
  90. */
  91. union
  92. {
  93. uint8_t *data; /*!< The buffer of data to be transfer.*/
  94. uint8_t *rxData; /*!< The buffer to receive data. */
  95. const uint8_t *txData; /*!< The buffer of data to be sent. */
  96. };
  97. size_t dataSize; /*!< Transfer size*/
  98. } flexio_uart_transfer_t;
  99. /* Forward declaration of the handle typedef. */
  100. typedef struct _flexio_uart_handle flexio_uart_handle_t;
  101. /*! @brief FlexIO UART transfer callback function. */
  102. typedef void (*flexio_uart_transfer_callback_t)(FLEXIO_UART_Type *base,
  103. flexio_uart_handle_t *handle,
  104. status_t status,
  105. void *userData);
  106. /*! @brief Define FLEXIO UART handle structure*/
  107. struct _flexio_uart_handle
  108. {
  109. const uint8_t *volatile txData; /*!< Address of remaining data to send. */
  110. volatile size_t txDataSize; /*!< Size of the remaining data to send. */
  111. uint8_t *volatile rxData; /*!< Address of remaining data to receive. */
  112. volatile size_t rxDataSize; /*!< Size of the remaining data to receive. */
  113. size_t txDataSizeAll; /*!< Total bytes to be sent. */
  114. size_t rxDataSizeAll; /*!< Total bytes to be received. */
  115. uint8_t *rxRingBuffer; /*!< Start address of the receiver ring buffer. */
  116. size_t rxRingBufferSize; /*!< Size of the ring buffer. */
  117. volatile uint16_t rxRingBufferHead; /*!< Index for the driver to store received data into ring buffer. */
  118. volatile uint16_t rxRingBufferTail; /*!< Index for the user to get data from the ring buffer. */
  119. flexio_uart_transfer_callback_t callback; /*!< Callback function. */
  120. void *userData; /*!< UART callback function parameter.*/
  121. volatile uint8_t txState; /*!< TX transfer state. */
  122. volatile uint8_t rxState; /*!< RX transfer state */
  123. };
  124. /*******************************************************************************
  125. * API
  126. ******************************************************************************/
  127. #if defined(__cplusplus)
  128. extern "C" {
  129. #endif /*_cplusplus*/
  130. /*!
  131. * @name Initialization and deinitialization
  132. * @{
  133. */
  134. /*!
  135. * @brief Ungates the FlexIO clock, resets the FlexIO module, configures FlexIO UART
  136. * hardware, and configures the FlexIO UART with FlexIO UART configuration.
  137. * The configuration structure can be filled by the user or be set with
  138. * default values by FLEXIO_UART_GetDefaultConfig().
  139. *
  140. * Example
  141. @code
  142. FLEXIO_UART_Type base = {
  143. .flexioBase = FLEXIO,
  144. .TxPinIndex = 0,
  145. .RxPinIndex = 1,
  146. .shifterIndex = {0,1},
  147. .timerIndex = {0,1}
  148. };
  149. flexio_uart_config_t config = {
  150. .enableInDoze = false,
  151. .enableInDebug = true,
  152. .enableFastAccess = false,
  153. .baudRate_Bps = 115200U,
  154. .bitCountPerChar = 8
  155. };
  156. FLEXIO_UART_Init(base, &config, srcClock_Hz);
  157. @endcode
  158. *
  159. * @param base Pointer to the FLEXIO_UART_Type structure.
  160. * @param userConfig Pointer to the flexio_uart_config_t structure.
  161. * @param srcClock_Hz FlexIO source clock in Hz.
  162. * @retval kStatus_Success Configuration success.
  163. * @retval kStatus_FLEXIO_UART_BaudrateNotSupport Baudrate is not supported for current clock source frequency.
  164. */
  165. status_t FLEXIO_UART_Init(FLEXIO_UART_Type *base, const flexio_uart_config_t *userConfig, uint32_t srcClock_Hz);
  166. /*!
  167. * @brief Resets the FlexIO UART shifter and timer config.
  168. *
  169. * @note After calling this API, call the FLEXO_UART_Init to use the FlexIO UART module.
  170. *
  171. * @param base Pointer to FLEXIO_UART_Type structure
  172. */
  173. void FLEXIO_UART_Deinit(FLEXIO_UART_Type *base);
  174. /*!
  175. * @brief Gets the default configuration to configure the FlexIO UART. The configuration
  176. * can be used directly for calling the FLEXIO_UART_Init().
  177. * Example:
  178. @code
  179. flexio_uart_config_t config;
  180. FLEXIO_UART_GetDefaultConfig(&userConfig);
  181. @endcode
  182. * @param userConfig Pointer to the flexio_uart_config_t structure.
  183. */
  184. void FLEXIO_UART_GetDefaultConfig(flexio_uart_config_t *userConfig);
  185. /* @} */
  186. /*!
  187. * @name Status
  188. * @{
  189. */
  190. /*!
  191. * @brief Gets the FlexIO UART status flags.
  192. *
  193. * @param base Pointer to the FLEXIO_UART_Type structure.
  194. * @return FlexIO UART status flags.
  195. */
  196. uint32_t FLEXIO_UART_GetStatusFlags(FLEXIO_UART_Type *base);
  197. /*!
  198. * @brief Gets the FlexIO UART status flags.
  199. *
  200. * @param base Pointer to the FLEXIO_UART_Type structure.
  201. * @param mask Status flag.
  202. * The parameter can be any combination of the following values:
  203. * @arg kFLEXIO_UART_TxDataRegEmptyFlag
  204. * @arg kFLEXIO_UART_RxEmptyFlag
  205. * @arg kFLEXIO_UART_RxOverRunFlag
  206. */
  207. void FLEXIO_UART_ClearStatusFlags(FLEXIO_UART_Type *base, uint32_t mask);
  208. /* @} */
  209. /*!
  210. * @name Interrupts
  211. * @{
  212. */
  213. /*!
  214. * @brief Enables the FlexIO UART interrupt.
  215. *
  216. * This function enables the FlexIO UART interrupt.
  217. *
  218. * @param base Pointer to the FLEXIO_UART_Type structure.
  219. * @param mask Interrupt source.
  220. */
  221. void FLEXIO_UART_EnableInterrupts(FLEXIO_UART_Type *base, uint32_t mask);
  222. /*!
  223. * @brief Disables the FlexIO UART interrupt.
  224. *
  225. * This function disables the FlexIO UART interrupt.
  226. *
  227. * @param base Pointer to the FLEXIO_UART_Type structure.
  228. * @param mask Interrupt source.
  229. */
  230. void FLEXIO_UART_DisableInterrupts(FLEXIO_UART_Type *base, uint32_t mask);
  231. /* @} */
  232. /*!
  233. * @name DMA Control
  234. * @{
  235. */
  236. /*!
  237. * @brief Gets the FlexIO UARt transmit data register address.
  238. *
  239. * This function returns the UART data register address, which is mainly used by DMA/eDMA.
  240. *
  241. * @param base Pointer to the FLEXIO_UART_Type structure.
  242. * @return FlexIO UART transmit data register address.
  243. */
  244. static inline uint32_t FLEXIO_UART_GetTxDataRegisterAddress(FLEXIO_UART_Type *base)
  245. {
  246. return FLEXIO_GetShifterBufferAddress(base->flexioBase, kFLEXIO_ShifterBuffer, base->shifterIndex[0]);
  247. }
  248. /*!
  249. * @brief Gets the FlexIO UART receive data register address.
  250. *
  251. * This function returns the UART data register address, which is mainly used by DMA/eDMA.
  252. *
  253. * @param base Pointer to the FLEXIO_UART_Type structure.
  254. * @return FlexIO UART receive data register address.
  255. */
  256. static inline uint32_t FLEXIO_UART_GetRxDataRegisterAddress(FLEXIO_UART_Type *base)
  257. {
  258. return FLEXIO_GetShifterBufferAddress(base->flexioBase, kFLEXIO_ShifterBufferByteSwapped, base->shifterIndex[1]);
  259. }
  260. /*!
  261. * @brief Enables/disables the FlexIO UART transmit DMA.
  262. * This function enables/disables the FlexIO UART Tx DMA,
  263. * which means asserting the kFLEXIO_UART_TxDataRegEmptyFlag does/doesn't trigger the DMA request.
  264. *
  265. * @param base Pointer to the FLEXIO_UART_Type structure.
  266. * @param enable True to enable, false to disable.
  267. */
  268. static inline void FLEXIO_UART_EnableTxDMA(FLEXIO_UART_Type *base, bool enable)
  269. {
  270. FLEXIO_EnableShifterStatusDMA(base->flexioBase, 1UL << base->shifterIndex[0], enable);
  271. }
  272. /*!
  273. * @brief Enables/disables the FlexIO UART receive DMA.
  274. * This function enables/disables the FlexIO UART Rx DMA,
  275. * which means asserting kFLEXIO_UART_RxDataRegFullFlag does/doesn't trigger the DMA request.
  276. *
  277. * @param base Pointer to the FLEXIO_UART_Type structure.
  278. * @param enable True to enable, false to disable.
  279. */
  280. static inline void FLEXIO_UART_EnableRxDMA(FLEXIO_UART_Type *base, bool enable)
  281. {
  282. FLEXIO_EnableShifterStatusDMA(base->flexioBase, 1UL << base->shifterIndex[1], enable);
  283. }
  284. /* @} */
  285. /*!
  286. * @name Bus Operations
  287. * @{
  288. */
  289. /*!
  290. * @brief Enables/disables the FlexIO UART module operation.
  291. *
  292. * @param base Pointer to the FLEXIO_UART_Type.
  293. * @param enable True to enable, false does not have any effect.
  294. */
  295. static inline void FLEXIO_UART_Enable(FLEXIO_UART_Type *base, bool enable)
  296. {
  297. if (enable)
  298. {
  299. base->flexioBase->CTRL |= FLEXIO_CTRL_FLEXEN_MASK;
  300. }
  301. }
  302. /*!
  303. * @brief Writes one byte of data.
  304. *
  305. * @note This is a non-blocking API, which returns directly after the data is put into the
  306. * data register. Ensure that the TxEmptyFlag is asserted before calling
  307. * this API.
  308. *
  309. * @param base Pointer to the FLEXIO_UART_Type structure.
  310. * @param buffer The data bytes to send.
  311. */
  312. static inline void FLEXIO_UART_WriteByte(FLEXIO_UART_Type *base, const uint8_t *buffer)
  313. {
  314. base->flexioBase->SHIFTBUF[base->shifterIndex[0]] = *buffer;
  315. }
  316. /*!
  317. * @brief Reads one byte of data.
  318. *
  319. * @note This is a non-blocking API, which returns directly after the data is read from the
  320. * data register. Ensure that the RxFullFlag is asserted before calling this API.
  321. *
  322. * @param base Pointer to the FLEXIO_UART_Type structure.
  323. * @param buffer The buffer to store the received bytes.
  324. */
  325. static inline void FLEXIO_UART_ReadByte(FLEXIO_UART_Type *base, uint8_t *buffer)
  326. {
  327. *buffer = (uint8_t)(base->flexioBase->SHIFTBUFBYS[base->shifterIndex[1]]);
  328. }
  329. /*!
  330. * @brief Sends a buffer of data bytes.
  331. *
  332. * @note This function blocks using the polling method until all bytes have been sent.
  333. *
  334. * @param base Pointer to the FLEXIO_UART_Type structure.
  335. * @param txData The data bytes to send.
  336. * @param txSize The number of data bytes to send.
  337. * @retval kStatus_FLEXIO_UART_Timeout Transmission timed out and was aborted.
  338. * @retval kStatus_Success Successfully wrote all data.
  339. */
  340. status_t FLEXIO_UART_WriteBlocking(FLEXIO_UART_Type *base, const uint8_t *txData, size_t txSize);
  341. /*!
  342. * @brief Receives a buffer of bytes.
  343. *
  344. * @note This function blocks using the polling method until all bytes have been received.
  345. *
  346. * @param base Pointer to the FLEXIO_UART_Type structure.
  347. * @param rxData The buffer to store the received bytes.
  348. * @param rxSize The number of data bytes to be received.
  349. * @retval kStatus_FLEXIO_UART_Timeout Transmission timed out and was aborted.
  350. * @retval kStatus_Success Successfully received all data.
  351. */
  352. status_t FLEXIO_UART_ReadBlocking(FLEXIO_UART_Type *base, uint8_t *rxData, size_t rxSize);
  353. /* @} */
  354. /*!
  355. * @name Transactional
  356. * @{
  357. */
  358. /*!
  359. * @brief Initializes the UART handle.
  360. *
  361. * This function initializes the FlexIO UART handle, which can be used for other FlexIO
  362. * UART transactional APIs. Call this API once to get the
  363. * initialized handle.
  364. *
  365. * The UART driver supports the "background" receiving, which means that users can set up
  366. * a RX ring buffer optionally. Data received is stored into the ring buffer even when
  367. * the user doesn't call the FLEXIO_UART_TransferReceiveNonBlocking() API. If there is already data
  368. * received in the ring buffer, users can get the received data from the ring buffer
  369. * directly. The ring buffer is disabled if passing NULL as @p ringBuffer.
  370. *
  371. * @param base to FLEXIO_UART_Type structure.
  372. * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
  373. * @param callback The callback function.
  374. * @param userData The parameter of the callback function.
  375. * @retval kStatus_Success Successfully create the handle.
  376. * @retval kStatus_OutOfRange The FlexIO type/handle/ISR table out of range.
  377. */
  378. status_t FLEXIO_UART_TransferCreateHandle(FLEXIO_UART_Type *base,
  379. flexio_uart_handle_t *handle,
  380. flexio_uart_transfer_callback_t callback,
  381. void *userData);
  382. /*!
  383. * @brief Sets up the RX ring buffer.
  384. *
  385. * This function sets up the RX ring buffer to a specific UART handle.
  386. *
  387. * When the RX ring buffer is used, data received is stored into the ring buffer even when
  388. * the user doesn't call the UART_ReceiveNonBlocking() API. If there is already data received
  389. * in the ring buffer, users can get the received data from the ring buffer directly.
  390. *
  391. * @note When using the RX ring buffer, one byte is reserved for internal use. In other
  392. * words, if @p ringBufferSize is 32, only 31 bytes are used for saving data.
  393. *
  394. * @param base Pointer to the FLEXIO_UART_Type structure.
  395. * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
  396. * @param ringBuffer Start address of ring buffer for background receiving. Pass NULL to disable the ring buffer.
  397. * @param ringBufferSize Size of the ring buffer.
  398. */
  399. void FLEXIO_UART_TransferStartRingBuffer(FLEXIO_UART_Type *base,
  400. flexio_uart_handle_t *handle,
  401. uint8_t *ringBuffer,
  402. size_t ringBufferSize);
  403. /*!
  404. * @brief Aborts the background transfer and uninstalls the ring buffer.
  405. *
  406. * This function aborts the background transfer and uninstalls the ring buffer.
  407. *
  408. * @param base Pointer to the FLEXIO_UART_Type structure.
  409. * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
  410. */
  411. void FLEXIO_UART_TransferStopRingBuffer(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle);
  412. /*!
  413. * @brief Transmits a buffer of data using the interrupt method.
  414. *
  415. * This function sends data using an interrupt method. This is a non-blocking function,
  416. * which returns directly without waiting for all data to be written to the TX register. When
  417. * all data is written to the TX register in ISR, the FlexIO UART driver calls the callback
  418. * function and passes the @ref kStatus_FLEXIO_UART_TxIdle as status parameter.
  419. *
  420. * @note The kStatus_FLEXIO_UART_TxIdle is passed to the upper layer when all data is written
  421. * to the TX register. However, it does not ensure that all data is sent out.
  422. *
  423. * @param base Pointer to the FLEXIO_UART_Type structure.
  424. * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
  425. * @param xfer FlexIO UART transfer structure. See #flexio_uart_transfer_t.
  426. * @retval kStatus_Success Successfully starts the data transmission.
  427. * @retval kStatus_UART_TxBusy Previous transmission still not finished, data not written to the TX register.
  428. */
  429. status_t FLEXIO_UART_TransferSendNonBlocking(FLEXIO_UART_Type *base,
  430. flexio_uart_handle_t *handle,
  431. flexio_uart_transfer_t *xfer);
  432. /*!
  433. * @brief Aborts the interrupt-driven data transmit.
  434. *
  435. * This function aborts the interrupt-driven data sending. Get the remainBytes to find out
  436. * how many bytes are still not sent out.
  437. *
  438. * @param base Pointer to the FLEXIO_UART_Type structure.
  439. * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
  440. */
  441. void FLEXIO_UART_TransferAbortSend(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle);
  442. /*!
  443. * @brief Gets the number of bytes sent.
  444. *
  445. * This function gets the number of bytes sent driven by interrupt.
  446. *
  447. * @param base Pointer to the FLEXIO_UART_Type structure.
  448. * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
  449. * @param count Number of bytes sent so far by the non-blocking transaction.
  450. * @retval kStatus_NoTransferInProgress transfer has finished or no transfer in progress.
  451. * @retval kStatus_Success Successfully return the count.
  452. */
  453. status_t FLEXIO_UART_TransferGetSendCount(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, size_t *count);
  454. /*!
  455. * @brief Receives a buffer of data using the interrupt method.
  456. *
  457. * This function receives data using the interrupt method. This is a non-blocking function,
  458. * which returns without waiting for all data to be received.
  459. * If the RX ring buffer is used and not empty, the data in ring buffer is copied and
  460. * the parameter @p receivedBytes shows how many bytes are copied from the ring buffer.
  461. * After copying, if the data in ring buffer is not enough to read, the receive
  462. * request is saved by the UART driver. When new data arrives, the receive request
  463. * is serviced first. When all data is received, the UART driver notifies the upper layer
  464. * through a callback function and passes the status parameter kStatus_UART_RxIdle.
  465. * For example, if the upper layer needs 10 bytes but there are only 5 bytes in the ring buffer,
  466. * the 5 bytes are copied to xfer->data. This function returns with the
  467. * parameter @p receivedBytes set to 5. For the last 5 bytes, newly arrived data is
  468. * saved from the xfer->data[5]. When 5 bytes are received, the UART driver notifies upper layer.
  469. * If the RX ring buffer is not enabled, this function enables the RX and RX interrupt
  470. * to receive data to xfer->data. When all data is received, the upper layer is notified.
  471. *
  472. * @param base Pointer to the FLEXIO_UART_Type structure.
  473. * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
  474. * @param xfer UART transfer structure. See #flexio_uart_transfer_t.
  475. * @param receivedBytes Bytes received from the ring buffer directly.
  476. * @retval kStatus_Success Successfully queue the transfer into the transmit queue.
  477. * @retval kStatus_FLEXIO_UART_RxBusy Previous receive request is not finished.
  478. */
  479. status_t FLEXIO_UART_TransferReceiveNonBlocking(FLEXIO_UART_Type *base,
  480. flexio_uart_handle_t *handle,
  481. flexio_uart_transfer_t *xfer,
  482. size_t *receivedBytes);
  483. /*!
  484. * @brief Aborts the receive data which was using IRQ.
  485. *
  486. * This function aborts the receive data which was using IRQ.
  487. *
  488. * @param base Pointer to the FLEXIO_UART_Type structure.
  489. * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
  490. */
  491. void FLEXIO_UART_TransferAbortReceive(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle);
  492. /*!
  493. * @brief Gets the number of bytes received.
  494. *
  495. * This function gets the number of bytes received driven by interrupt.
  496. *
  497. * @param base Pointer to the FLEXIO_UART_Type structure.
  498. * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
  499. * @param count Number of bytes received so far by the non-blocking transaction.
  500. * @retval kStatus_NoTransferInProgress transfer has finished or no transfer in progress.
  501. * @retval kStatus_Success Successfully return the count.
  502. */
  503. status_t FLEXIO_UART_TransferGetReceiveCount(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, size_t *count);
  504. /*!
  505. * @brief FlexIO UART IRQ handler function.
  506. *
  507. * This function processes the FlexIO UART transmit and receives the IRQ request.
  508. *
  509. * @param uartType Pointer to the FLEXIO_UART_Type structure.
  510. * @param uartHandle Pointer to the flexio_uart_handle_t structure to store the transfer state.
  511. */
  512. void FLEXIO_UART_TransferHandleIRQ(void *uartType, void *uartHandle);
  513. /*@}*/
  514. #if defined(__cplusplus)
  515. }
  516. #endif /*_cplusplus*/
  517. /*@}*/
  518. #endif /*_FSL_FLEXIO_UART_H_*/