fsl_flexio_uart.h 23 KB

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