fsl_flexio_uart.h 23 KB

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