Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:59

0001 /*
0002  * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
0003  * Copyright 2016-2021 NXP
0004  * All rights reserved.
0005  *
0006  * SPDX-License-Identifier: BSD-3-Clause
0007  */
0008 
0009 #ifndef _FSL_FLEXIO_UART_H_
0010 #define _FSL_FLEXIO_UART_H_
0011 
0012 #include "fsl_common.h"
0013 #include "fsl_flexio.h"
0014 
0015 /*!
0016  * @addtogroup flexio_uart
0017  * @{
0018  */
0019 
0020 /*******************************************************************************
0021  * Definitions
0022  ******************************************************************************/
0023 
0024 /*! @name Driver version */
0025 /*@{*/
0026 /*! @brief FlexIO UART driver version. */
0027 #define FSL_FLEXIO_UART_DRIVER_VERSION (MAKE_VERSION(2, 4, 0))
0028 /*@}*/
0029 
0030 /*! @brief Retry times for waiting flag. */
0031 #ifndef UART_RETRY_TIMES
0032 #define UART_RETRY_TIMES 0U /* Defining to zero means to keep waiting for the flag until it is assert/deassert. */
0033 #endif
0034 
0035 /*! @brief Error codes for the UART driver. */
0036 enum
0037 {
0038     kStatus_FLEXIO_UART_TxBusy = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 0), /*!< Transmitter is busy. */
0039     kStatus_FLEXIO_UART_RxBusy = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 1), /*!< Receiver is busy. */
0040     kStatus_FLEXIO_UART_TxIdle = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 2), /*!< UART transmitter is idle. */
0041     kStatus_FLEXIO_UART_RxIdle = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 3), /*!< UART receiver is idle. */
0042     kStatus_FLEXIO_UART_ERROR  = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 4), /*!< ERROR happens on UART. */
0043     kStatus_FLEXIO_UART_RxRingBufferOverrun =
0044         MAKE_STATUS(kStatusGroup_FLEXIO_UART, 5), /*!< UART RX software ring buffer overrun. */
0045     kStatus_FLEXIO_UART_RxHardwareOverrun = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 6), /*!< UART RX receiver overrun. */
0046     kStatus_FLEXIO_UART_Timeout           = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 7), /*!< UART times out. */
0047     kStatus_FLEXIO_UART_BaudrateNotSupport =
0048         MAKE_STATUS(kStatusGroup_FLEXIO_UART, 8) /*!< Baudrate is not supported in current clock source */
0049 };
0050 
0051 /*! @brief FlexIO UART bit count per char. */
0052 typedef enum _flexio_uart_bit_count_per_char
0053 {
0054     kFLEXIO_UART_7BitsPerChar = 7U, /*!< 7-bit data characters */
0055     kFLEXIO_UART_8BitsPerChar = 8U, /*!< 8-bit data characters */
0056     kFLEXIO_UART_9BitsPerChar = 9U, /*!< 9-bit data characters */
0057 } flexio_uart_bit_count_per_char_t;
0058 
0059 /*! @brief Define FlexIO UART interrupt mask. */
0060 enum _flexio_uart_interrupt_enable
0061 {
0062     kFLEXIO_UART_TxDataRegEmptyInterruptEnable = 0x1U, /*!< Transmit buffer empty interrupt enable. */
0063     kFLEXIO_UART_RxDataRegFullInterruptEnable  = 0x2U, /*!< Receive buffer full interrupt enable. */
0064 };
0065 
0066 /*! @brief Define FlexIO UART status mask. */
0067 enum _flexio_uart_status_flags
0068 {
0069     kFLEXIO_UART_TxDataRegEmptyFlag = 0x1U, /*!< Transmit buffer empty flag. */
0070     kFLEXIO_UART_RxDataRegFullFlag  = 0x2U, /*!< Receive buffer full flag. */
0071     kFLEXIO_UART_RxOverRunFlag      = 0x4U, /*!< Receive buffer over run flag. */
0072 };
0073 
0074 /*! @brief Define FlexIO UART access structure typedef. */
0075 typedef struct _flexio_uart_type
0076 {
0077     FLEXIO_Type *flexioBase; /*!< FlexIO base pointer. */
0078     uint8_t TxPinIndex;      /*!< Pin select for UART_Tx. */
0079     uint8_t RxPinIndex;      /*!< Pin select for UART_Rx. */
0080     uint8_t shifterIndex[2]; /*!< Shifter index used in FlexIO UART. */
0081     uint8_t timerIndex[2];   /*!< Timer index used in FlexIO UART. */
0082 } FLEXIO_UART_Type;
0083 
0084 /*! @brief Define FlexIO UART user configuration structure. */
0085 typedef struct _flexio_uart_config
0086 {
0087     bool enableUart;                                  /*!< Enable/disable FlexIO UART TX & RX. */
0088     bool enableInDoze;                                /*!< Enable/disable FlexIO operation in doze mode*/
0089     bool enableInDebug;                               /*!< Enable/disable FlexIO operation in debug mode*/
0090     bool enableFastAccess;                            /*!< Enable/disable fast access to FlexIO registers,
0091                                                        fast access requires the FlexIO clock to be at least
0092                                                        twice the frequency of the bus clock. */
0093     uint32_t baudRate_Bps;                            /*!< Baud rate in Bps. */
0094     flexio_uart_bit_count_per_char_t bitCountPerChar; /*!< number of bits, 7/8/9 -bit */
0095 } flexio_uart_config_t;
0096 
0097 /*! @brief Define FlexIO UART transfer structure. */
0098 typedef struct _flexio_uart_transfer
0099 {
0100     /*
0101      * Use separate TX and RX data pointer, because TX data is const data.
0102      * The member data is kept for backward compatibility.
0103      */
0104     union
0105     {
0106         uint8_t *data;         /*!< The buffer of data to be transfer.*/
0107         uint8_t *rxData;       /*!< The buffer to receive data. */
0108         const uint8_t *txData; /*!< The buffer of data to be sent. */
0109     };
0110     size_t dataSize; /*!< Transfer size*/
0111 } flexio_uart_transfer_t;
0112 
0113 /* Forward declaration of the handle typedef. */
0114 typedef struct _flexio_uart_handle flexio_uart_handle_t;
0115 
0116 /*! @brief FlexIO UART transfer callback function. */
0117 typedef void (*flexio_uart_transfer_callback_t)(FLEXIO_UART_Type *base,
0118                                                 flexio_uart_handle_t *handle,
0119                                                 status_t status,
0120                                                 void *userData);
0121 
0122 /*! @brief Define FLEXIO UART handle structure*/
0123 struct _flexio_uart_handle
0124 {
0125     const uint8_t *volatile txData; /*!< Address of remaining data to send. */
0126     volatile size_t txDataSize;     /*!< Size of the remaining data to send. */
0127     uint8_t *volatile rxData;       /*!< Address of remaining data to receive. */
0128     volatile size_t rxDataSize;     /*!< Size of the remaining data to receive. */
0129     size_t txDataSizeAll;           /*!< Total bytes to be sent. */
0130     size_t rxDataSizeAll;           /*!< Total bytes to be received. */
0131 
0132     uint8_t *rxRingBuffer;              /*!< Start address of the receiver ring buffer. */
0133     size_t rxRingBufferSize;            /*!< Size of the ring buffer. */
0134     volatile uint16_t rxRingBufferHead; /*!< Index for the driver to store received data into ring buffer. */
0135     volatile uint16_t rxRingBufferTail; /*!< Index for the user to get data from the ring buffer. */
0136 
0137     flexio_uart_transfer_callback_t callback; /*!< Callback function. */
0138     void *userData;                           /*!< UART callback function parameter.*/
0139 
0140     volatile uint8_t txState; /*!< TX transfer state. */
0141     volatile uint8_t rxState; /*!< RX transfer state */
0142 };
0143 
0144 /*******************************************************************************
0145  * API
0146  ******************************************************************************/
0147 
0148 #if defined(__cplusplus)
0149 extern "C" {
0150 #endif /*_cplusplus*/
0151 
0152 /*!
0153  * @name Initialization and deinitialization
0154  * @{
0155  */
0156 
0157 /*!
0158  * @brief Ungates the FlexIO clock, resets the FlexIO module, configures FlexIO UART
0159  * hardware, and configures the FlexIO UART with FlexIO UART configuration.
0160  * The configuration structure can be filled by the user or be set with
0161  * default values by FLEXIO_UART_GetDefaultConfig().
0162  *
0163  * Example
0164    @code
0165    FLEXIO_UART_Type base = {
0166    .flexioBase = FLEXIO,
0167    .TxPinIndex = 0,
0168    .RxPinIndex = 1,
0169    .shifterIndex = {0,1},
0170    .timerIndex = {0,1}
0171    };
0172    flexio_uart_config_t config = {
0173    .enableInDoze = false,
0174    .enableInDebug = true,
0175    .enableFastAccess = false,
0176    .baudRate_Bps = 115200U,
0177    .bitCountPerChar = 8
0178    };
0179    FLEXIO_UART_Init(base, &config, srcClock_Hz);
0180    @endcode
0181  *
0182  * @param base Pointer to the FLEXIO_UART_Type structure.
0183  * @param userConfig Pointer to the flexio_uart_config_t structure.
0184  * @param srcClock_Hz FlexIO source clock in Hz.
0185  * @retval kStatus_Success Configuration success.
0186  * @retval kStatus_FLEXIO_UART_BaudrateNotSupport Baudrate is not supported for current clock source frequency.
0187 */
0188 status_t FLEXIO_UART_Init(FLEXIO_UART_Type *base, const flexio_uart_config_t *userConfig, uint32_t srcClock_Hz);
0189 
0190 /*!
0191  * @brief Resets the FlexIO UART shifter and timer config.
0192  *
0193  * @note After calling this API, call the FLEXO_UART_Init to use the FlexIO UART module.
0194  *
0195  * @param base Pointer to FLEXIO_UART_Type structure
0196  */
0197 void FLEXIO_UART_Deinit(FLEXIO_UART_Type *base);
0198 
0199 /*!
0200  * @brief Gets the default configuration to configure the FlexIO UART. The configuration
0201  * can be used directly for calling the FLEXIO_UART_Init().
0202  * Example:
0203    @code
0204    flexio_uart_config_t config;
0205    FLEXIO_UART_GetDefaultConfig(&userConfig);
0206    @endcode
0207  * @param userConfig Pointer to the flexio_uart_config_t structure.
0208 */
0209 void FLEXIO_UART_GetDefaultConfig(flexio_uart_config_t *userConfig);
0210 
0211 /* @} */
0212 
0213 /*!
0214  * @name Status
0215  * @{
0216  */
0217 
0218 /*!
0219  * @brief Gets the FlexIO UART status flags.
0220  *
0221  * @param base Pointer to the FLEXIO_UART_Type structure.
0222  * @return FlexIO UART status flags.
0223  */
0224 
0225 uint32_t FLEXIO_UART_GetStatusFlags(FLEXIO_UART_Type *base);
0226 
0227 /*!
0228  * @brief Gets the FlexIO UART status flags.
0229  *
0230  * @param base Pointer to the FLEXIO_UART_Type structure.
0231  * @param mask Status flag.
0232  *      The parameter can be any combination of the following values:
0233  *          @arg kFLEXIO_UART_TxDataRegEmptyFlag
0234  *          @arg kFLEXIO_UART_RxEmptyFlag
0235  *          @arg kFLEXIO_UART_RxOverRunFlag
0236  */
0237 
0238 void FLEXIO_UART_ClearStatusFlags(FLEXIO_UART_Type *base, uint32_t mask);
0239 
0240 /* @} */
0241 
0242 /*!
0243  * @name Interrupts
0244  * @{
0245  */
0246 
0247 /*!
0248  * @brief Enables the FlexIO UART interrupt.
0249  *
0250  * This function enables the FlexIO UART interrupt.
0251  *
0252  * @param base Pointer to the FLEXIO_UART_Type structure.
0253  * @param mask Interrupt source.
0254  */
0255 void FLEXIO_UART_EnableInterrupts(FLEXIO_UART_Type *base, uint32_t mask);
0256 
0257 /*!
0258  * @brief Disables the FlexIO UART interrupt.
0259  *
0260  * This function disables the FlexIO UART interrupt.
0261  *
0262  * @param base Pointer to the FLEXIO_UART_Type structure.
0263  * @param mask Interrupt source.
0264  */
0265 void FLEXIO_UART_DisableInterrupts(FLEXIO_UART_Type *base, uint32_t mask);
0266 
0267 /* @} */
0268 
0269 /*!
0270  * @name DMA Control
0271  * @{
0272  */
0273 
0274 /*!
0275  * @brief Gets the FlexIO UARt transmit data register address.
0276  *
0277  * This function returns the UART data register address, which is mainly used by DMA/eDMA.
0278  *
0279  * @param base Pointer to the FLEXIO_UART_Type structure.
0280  * @return FlexIO UART transmit data register address.
0281  */
0282 static inline uint32_t FLEXIO_UART_GetTxDataRegisterAddress(FLEXIO_UART_Type *base)
0283 {
0284     return FLEXIO_GetShifterBufferAddress(base->flexioBase, kFLEXIO_ShifterBuffer, base->shifterIndex[0]);
0285 }
0286 
0287 /*!
0288  * @brief Gets the FlexIO UART receive data register address.
0289  *
0290  * This function returns the UART data register address, which is mainly used by DMA/eDMA.
0291  *
0292  * @param base Pointer to the FLEXIO_UART_Type structure.
0293  * @return FlexIO UART receive data register address.
0294  */
0295 static inline uint32_t FLEXIO_UART_GetRxDataRegisterAddress(FLEXIO_UART_Type *base)
0296 {
0297     return FLEXIO_GetShifterBufferAddress(base->flexioBase, kFLEXIO_ShifterBufferByteSwapped, base->shifterIndex[1]);
0298 }
0299 
0300 /*!
0301  * @brief Enables/disables the FlexIO UART transmit DMA.
0302  * This function enables/disables the FlexIO UART Tx DMA,
0303  * which means asserting the kFLEXIO_UART_TxDataRegEmptyFlag does/doesn't trigger the DMA request.
0304  *
0305  * @param base Pointer to the FLEXIO_UART_Type structure.
0306  * @param enable True to enable, false to disable.
0307  */
0308 static inline void FLEXIO_UART_EnableTxDMA(FLEXIO_UART_Type *base, bool enable)
0309 {
0310     FLEXIO_EnableShifterStatusDMA(base->flexioBase, 1UL << base->shifterIndex[0], enable);
0311 }
0312 
0313 /*!
0314  * @brief Enables/disables the FlexIO UART receive DMA.
0315  * This function enables/disables the FlexIO UART Rx DMA,
0316  * which means asserting kFLEXIO_UART_RxDataRegFullFlag does/doesn't trigger the DMA request.
0317  *
0318  * @param base Pointer to the FLEXIO_UART_Type structure.
0319  * @param enable True to enable, false to disable.
0320  */
0321 static inline void FLEXIO_UART_EnableRxDMA(FLEXIO_UART_Type *base, bool enable)
0322 {
0323     FLEXIO_EnableShifterStatusDMA(base->flexioBase, 1UL << base->shifterIndex[1], enable);
0324 }
0325 
0326 /* @} */
0327 
0328 /*!
0329  * @name Bus Operations
0330  * @{
0331  */
0332 
0333 /*!
0334  * @brief Enables/disables the FlexIO UART module operation.
0335  *
0336  * @param base Pointer to the FLEXIO_UART_Type.
0337  * @param enable True to enable, false does not have any effect.
0338  */
0339 static inline void FLEXIO_UART_Enable(FLEXIO_UART_Type *base, bool enable)
0340 {
0341     if (enable)
0342     {
0343         base->flexioBase->CTRL |= FLEXIO_CTRL_FLEXEN_MASK;
0344     }
0345 }
0346 
0347 /*!
0348  * @brief Writes one byte of data.
0349  *
0350  * @note This is a non-blocking API, which returns directly after the data is put into the
0351  * data register. Ensure that the TxEmptyFlag is asserted before calling
0352  * this API.
0353  *
0354  * @param base Pointer to the FLEXIO_UART_Type structure.
0355  * @param buffer The data bytes to send.
0356  */
0357 static inline void FLEXIO_UART_WriteByte(FLEXIO_UART_Type *base, const uint8_t *buffer)
0358 {
0359     base->flexioBase->SHIFTBUF[base->shifterIndex[0]] = *buffer;
0360 }
0361 
0362 /*!
0363  * @brief Reads one byte of data.
0364  *
0365  * @note This is a non-blocking API, which returns directly after the data is read from the
0366  * data register. Ensure that the RxFullFlag is asserted before calling this API.
0367  *
0368  * @param base Pointer to the FLEXIO_UART_Type structure.
0369  * @param buffer The buffer to store the received bytes.
0370  */
0371 static inline void FLEXIO_UART_ReadByte(FLEXIO_UART_Type *base, uint8_t *buffer)
0372 {
0373     *buffer = (uint8_t)(base->flexioBase->SHIFTBUFBYS[base->shifterIndex[1]]);
0374 }
0375 
0376 /*!
0377  * @brief Sends a buffer of data bytes.
0378  *
0379  * @note This function blocks using the polling method until all bytes have been sent.
0380  *
0381  * @param base Pointer to the FLEXIO_UART_Type structure.
0382  * @param txData The data bytes to send.
0383  * @param txSize The number of data bytes to send.
0384  * @retval kStatus_FLEXIO_UART_Timeout Transmission timed out and was aborted.
0385  * @retval kStatus_Success Successfully wrote all data.
0386  */
0387 status_t FLEXIO_UART_WriteBlocking(FLEXIO_UART_Type *base, const uint8_t *txData, size_t txSize);
0388 
0389 /*!
0390  * @brief Receives a buffer of bytes.
0391  *
0392  * @note This function blocks using the polling method until all bytes have been received.
0393  *
0394  * @param base Pointer to the FLEXIO_UART_Type structure.
0395  * @param rxData The buffer to store the received bytes.
0396  * @param rxSize The number of data bytes to be received.
0397  * @retval kStatus_FLEXIO_UART_Timeout Transmission timed out and was aborted.
0398  * @retval kStatus_Success Successfully received all data.
0399  */
0400 status_t FLEXIO_UART_ReadBlocking(FLEXIO_UART_Type *base, uint8_t *rxData, size_t rxSize);
0401 
0402 /* @} */
0403 
0404 /*!
0405  * @name Transactional
0406  * @{
0407  */
0408 
0409 /*!
0410  * @brief Initializes the UART handle.
0411  *
0412  * This function initializes the FlexIO UART handle, which can be used for other FlexIO
0413  * UART transactional APIs. Call this API once to get the
0414  * initialized handle.
0415  *
0416  * The UART driver supports the "background" receiving, which means that users can set up
0417  * a RX ring buffer optionally. Data received is stored into the ring buffer even when
0418  * the user doesn't call the FLEXIO_UART_TransferReceiveNonBlocking() API. If there is already data
0419  * received in the ring buffer, users can get the received data from the ring buffer
0420  * directly. The ring buffer is disabled if passing NULL as @p ringBuffer.
0421  *
0422  * @param base to FLEXIO_UART_Type structure.
0423  * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
0424  * @param callback The callback function.
0425  * @param userData The parameter of the callback function.
0426  * @retval kStatus_Success Successfully create the handle.
0427  * @retval kStatus_OutOfRange The FlexIO type/handle/ISR table out of range.
0428  */
0429 status_t FLEXIO_UART_TransferCreateHandle(FLEXIO_UART_Type *base,
0430                                           flexio_uart_handle_t *handle,
0431                                           flexio_uart_transfer_callback_t callback,
0432                                           void *userData);
0433 
0434 /*!
0435  * @brief Sets up the RX ring buffer.
0436  *
0437  * This function sets up the RX ring buffer to a specific UART handle.
0438  *
0439  * When the RX ring buffer is used, data received is stored into the ring buffer even when
0440  * the user doesn't call the UART_ReceiveNonBlocking() API. If there is already data received
0441  * in the ring buffer, users can get the received data from the ring buffer directly.
0442  *
0443  * @note When using the RX ring buffer, one byte is reserved for internal use. In other
0444  * words, if @p ringBufferSize is 32, only 31 bytes are used for saving data.
0445  *
0446  * @param base Pointer to the FLEXIO_UART_Type structure.
0447  * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
0448  * @param ringBuffer Start address of ring buffer for background receiving. Pass NULL to disable the ring buffer.
0449  * @param ringBufferSize Size of the ring buffer.
0450  */
0451 void FLEXIO_UART_TransferStartRingBuffer(FLEXIO_UART_Type *base,
0452                                          flexio_uart_handle_t *handle,
0453                                          uint8_t *ringBuffer,
0454                                          size_t ringBufferSize);
0455 
0456 /*!
0457  * @brief Aborts the background transfer and uninstalls the ring buffer.
0458  *
0459  * This function aborts the background transfer and uninstalls the ring buffer.
0460  *
0461  * @param base Pointer to the FLEXIO_UART_Type structure.
0462  * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
0463  */
0464 void FLEXIO_UART_TransferStopRingBuffer(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle);
0465 
0466 /*!
0467  * @brief Transmits a buffer of data using the interrupt method.
0468  *
0469  * This function sends data using an interrupt method. This is a non-blocking function,
0470  * which returns directly without waiting for all data to be written to the TX register. When
0471  * all data is written to the TX register in ISR, the FlexIO UART driver calls the callback
0472  * function and passes the @ref kStatus_FLEXIO_UART_TxIdle as status parameter.
0473  *
0474  * @note The kStatus_FLEXIO_UART_TxIdle is passed to the upper layer when all data is written
0475  * to the TX register. However, it does not ensure that all data is sent out.
0476  *
0477  * @param base Pointer to the FLEXIO_UART_Type structure.
0478  * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
0479  * @param xfer FlexIO UART transfer structure. See #flexio_uart_transfer_t.
0480  * @retval kStatus_Success Successfully starts the data transmission.
0481  * @retval kStatus_UART_TxBusy Previous transmission still not finished, data not written to the TX register.
0482  */
0483 status_t FLEXIO_UART_TransferSendNonBlocking(FLEXIO_UART_Type *base,
0484                                              flexio_uart_handle_t *handle,
0485                                              flexio_uart_transfer_t *xfer);
0486 
0487 /*!
0488  * @brief Aborts the interrupt-driven data transmit.
0489  *
0490  * This function aborts the interrupt-driven data sending. Get the remainBytes to find out
0491  * how many bytes are still not sent out.
0492  *
0493  * @param base Pointer to the FLEXIO_UART_Type structure.
0494  * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
0495  */
0496 void FLEXIO_UART_TransferAbortSend(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle);
0497 
0498 /*!
0499  * @brief Gets the number of bytes sent.
0500  *
0501  * This function gets the number of bytes sent driven by interrupt.
0502  *
0503  * @param base Pointer to the FLEXIO_UART_Type structure.
0504  * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
0505  * @param count Number of bytes sent so far by the non-blocking transaction.
0506  * @retval kStatus_NoTransferInProgress transfer has finished or no transfer in progress.
0507  * @retval kStatus_Success Successfully return the count.
0508  */
0509 status_t FLEXIO_UART_TransferGetSendCount(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, size_t *count);
0510 
0511 /*!
0512  * @brief Receives a buffer of data using the interrupt method.
0513  *
0514  * This function receives data using the interrupt method. This is a non-blocking function,
0515  * which returns without waiting for all data to be received.
0516  * If the RX ring buffer is used and not empty, the data in ring buffer is copied and
0517  * the parameter @p receivedBytes shows how many bytes are copied from the ring buffer.
0518  * After copying, if the data in ring buffer is not enough to read, the receive
0519  * request is saved by the UART driver. When new data arrives, the receive request
0520  * is serviced first. When all data is received, the UART driver notifies the upper layer
0521  * through a callback function and passes the status parameter kStatus_UART_RxIdle.
0522  * For example, if the upper layer needs 10 bytes but there are only 5 bytes in the ring buffer,
0523  * the 5 bytes are copied to xfer->data. This function returns with the
0524  * parameter @p receivedBytes set to 5. For the last 5 bytes, newly arrived data is
0525  * saved from the xfer->data[5]. When 5 bytes are received, the UART driver notifies upper layer.
0526  * If the RX ring buffer is not enabled, this function enables the RX and RX interrupt
0527  * to receive data to xfer->data. When all data is received, the upper layer is notified.
0528  *
0529  * @param base Pointer to the FLEXIO_UART_Type structure.
0530  * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
0531  * @param xfer UART transfer structure. See #flexio_uart_transfer_t.
0532  * @param receivedBytes Bytes received from the ring buffer directly.
0533  * @retval kStatus_Success Successfully queue the transfer into the transmit queue.
0534  * @retval kStatus_FLEXIO_UART_RxBusy Previous receive request is not finished.
0535  */
0536 status_t FLEXIO_UART_TransferReceiveNonBlocking(FLEXIO_UART_Type *base,
0537                                                 flexio_uart_handle_t *handle,
0538                                                 flexio_uart_transfer_t *xfer,
0539                                                 size_t *receivedBytes);
0540 
0541 /*!
0542  * @brief Aborts the receive data which was using IRQ.
0543  *
0544  * This function aborts the receive data which was using IRQ.
0545  *
0546  * @param base Pointer to the FLEXIO_UART_Type structure.
0547  * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
0548  */
0549 void FLEXIO_UART_TransferAbortReceive(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle);
0550 
0551 /*!
0552  * @brief Gets the number of bytes received.
0553  *
0554  * This function gets the number of bytes received driven by interrupt.
0555  *
0556  * @param base Pointer to the FLEXIO_UART_Type structure.
0557  * @param handle Pointer to the flexio_uart_handle_t structure to store the transfer state.
0558  * @param count Number of bytes received so far by the non-blocking transaction.
0559  * @retval kStatus_NoTransferInProgress transfer has finished or no transfer in progress.
0560  * @retval kStatus_Success Successfully return the count.
0561  */
0562 status_t FLEXIO_UART_TransferGetReceiveCount(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, size_t *count);
0563 
0564 /*!
0565  * @brief FlexIO UART IRQ handler function.
0566  *
0567  * This function processes the FlexIO UART transmit and receives the IRQ request.
0568  *
0569  * @param uartType Pointer to the FLEXIO_UART_Type structure.
0570  * @param uartHandle Pointer to the flexio_uart_handle_t structure to store the transfer state.
0571  */
0572 void FLEXIO_UART_TransferHandleIRQ(void *uartType, void *uartHandle);
0573 
0574 /*@}*/
0575 
0576 #if defined(__cplusplus)
0577 }
0578 #endif /*_cplusplus*/
0579 /*@}*/
0580 
0581 #endif /*_FSL_FLEXIO_UART_H_*/