2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
\r
3 * Copyright 2016-2018 NXP
\r
4 * All rights reserved.
\r
6 * SPDX-License-Identifier: BSD-3-Clause
\r
8 #ifndef _FSL_USART_H_
\r
9 #define _FSL_USART_H_
\r
11 #include "fsl_common.h"
\r
14 * @addtogroup usart_driver
\r
18 /*******************************************************************************
\r
20 ******************************************************************************/
\r
22 /*! @name Driver version */
\r
24 /*! @brief USART driver version 2.0.3. */
\r
25 #define FSL_USART_DRIVER_VERSION (MAKE_VERSION(2, 0, 3))
\r
28 #define USART_FIFOTRIG_TXLVL_GET(base) (((base)->FIFOTRIG & USART_FIFOTRIG_TXLVL_MASK) >> USART_FIFOTRIG_TXLVL_SHIFT)
\r
29 #define USART_FIFOTRIG_RXLVL_GET(base) (((base)->FIFOTRIG & USART_FIFOTRIG_RXLVL_MASK) >> USART_FIFOTRIG_RXLVL_SHIFT)
\r
31 /*! @brief Error codes for the USART driver. */
\r
34 kStatus_USART_TxBusy = MAKE_STATUS(kStatusGroup_LPC_USART, 0), /*!< Transmitter is busy. */
\r
35 kStatus_USART_RxBusy = MAKE_STATUS(kStatusGroup_LPC_USART, 1), /*!< Receiver is busy. */
\r
36 kStatus_USART_TxIdle = MAKE_STATUS(kStatusGroup_LPC_USART, 2), /*!< USART transmitter is idle. */
\r
37 kStatus_USART_RxIdle = MAKE_STATUS(kStatusGroup_LPC_USART, 3), /*!< USART receiver is idle. */
\r
38 kStatus_USART_TxError = MAKE_STATUS(kStatusGroup_LPC_USART, 7), /*!< Error happens on txFIFO. */
\r
39 kStatus_USART_RxError = MAKE_STATUS(kStatusGroup_LPC_USART, 9), /*!< Error happens on rxFIFO. */
\r
40 kStatus_USART_RxRingBufferOverrun = MAKE_STATUS(kStatusGroup_LPC_USART, 8), /*!< Error happens on rx ring buffer */
\r
41 kStatus_USART_NoiseError = MAKE_STATUS(kStatusGroup_LPC_USART, 10), /*!< USART noise error. */
\r
42 kStatus_USART_FramingError = MAKE_STATUS(kStatusGroup_LPC_USART, 11), /*!< USART framing error. */
\r
43 kStatus_USART_ParityError = MAKE_STATUS(kStatusGroup_LPC_USART, 12), /*!< USART parity error. */
\r
44 kStatus_USART_BaudrateNotSupport =
\r
45 MAKE_STATUS(kStatusGroup_LPC_USART, 13), /*!< Baudrate is not support in current clock source */
\r
48 /*! @brief USART parity mode. */
\r
49 typedef enum _usart_parity_mode
\r
51 kUSART_ParityDisabled = 0x0U, /*!< Parity disabled */
\r
52 kUSART_ParityEven = 0x2U, /*!< Parity enabled, type even, bit setting: PE|PT = 10 */
\r
53 kUSART_ParityOdd = 0x3U, /*!< Parity enabled, type odd, bit setting: PE|PT = 11 */
\r
54 } usart_parity_mode_t;
\r
56 /*! @brief USART stop bit count. */
\r
57 typedef enum _usart_stop_bit_count
\r
59 kUSART_OneStopBit = 0U, /*!< One stop bit */
\r
60 kUSART_TwoStopBit = 1U, /*!< Two stop bits */
\r
61 } usart_stop_bit_count_t;
\r
63 /*! @brief USART data size. */
\r
64 typedef enum _usart_data_len
\r
66 kUSART_7BitsPerChar = 0U, /*!< Seven bit mode */
\r
67 kUSART_8BitsPerChar = 1U, /*!< Eight bit mode */
\r
70 /*! @brief txFIFO watermark values */
\r
71 typedef enum _usart_txfifo_watermark
\r
73 kUSART_TxFifo0 = 0, /*!< USART tx watermark is empty */
\r
74 kUSART_TxFifo1 = 1, /*!< USART tx watermark at 1 item */
\r
75 kUSART_TxFifo2 = 2, /*!< USART tx watermark at 2 items */
\r
76 kUSART_TxFifo3 = 3, /*!< USART tx watermark at 3 items */
\r
77 kUSART_TxFifo4 = 4, /*!< USART tx watermark at 4 items */
\r
78 kUSART_TxFifo5 = 5, /*!< USART tx watermark at 5 items */
\r
79 kUSART_TxFifo6 = 6, /*!< USART tx watermark at 6 items */
\r
80 kUSART_TxFifo7 = 7, /*!< USART tx watermark at 7 items */
\r
81 } usart_txfifo_watermark_t;
\r
83 /*! @brief rxFIFO watermark values */
\r
84 typedef enum _usart_rxfifo_watermark
\r
86 kUSART_RxFifo1 = 0, /*!< USART rx watermark at 1 item */
\r
87 kUSART_RxFifo2 = 1, /*!< USART rx watermark at 2 items */
\r
88 kUSART_RxFifo3 = 2, /*!< USART rx watermark at 3 items */
\r
89 kUSART_RxFifo4 = 3, /*!< USART rx watermark at 4 items */
\r
90 kUSART_RxFifo5 = 4, /*!< USART rx watermark at 5 items */
\r
91 kUSART_RxFifo6 = 5, /*!< USART rx watermark at 6 items */
\r
92 kUSART_RxFifo7 = 6, /*!< USART rx watermark at 7 items */
\r
93 kUSART_RxFifo8 = 7, /*!< USART rx watermark at 8 items */
\r
94 } usart_rxfifo_watermark_t;
\r
97 * @brief USART interrupt configuration structure, default settings all disabled.
\r
99 enum _usart_interrupt_enable
\r
101 kUSART_TxErrorInterruptEnable = (USART_FIFOINTENSET_TXERR_MASK),
\r
102 kUSART_RxErrorInterruptEnable = (USART_FIFOINTENSET_RXERR_MASK),
\r
103 kUSART_TxLevelInterruptEnable = (USART_FIFOINTENSET_TXLVL_MASK),
\r
104 kUSART_RxLevelInterruptEnable = (USART_FIFOINTENSET_RXLVL_MASK),
\r
108 * @brief USART status flags.
\r
110 * This provides constants for the USART status flags for use in the USART functions.
\r
114 kUSART_TxError = (USART_FIFOSTAT_TXERR_MASK), /*!< TEERR bit, sets if TX buffer is error */
\r
115 kUSART_RxError = (USART_FIFOSTAT_RXERR_MASK), /*!< RXERR bit, sets if RX buffer is error */
\r
116 kUSART_TxFifoEmptyFlag = (USART_FIFOSTAT_TXEMPTY_MASK), /*!< TXEMPTY bit, sets if TX buffer is empty */
\r
117 kUSART_TxFifoNotFullFlag = (USART_FIFOSTAT_TXNOTFULL_MASK), /*!< TXNOTFULL bit, sets if TX buffer is not full */
\r
118 kUSART_RxFifoNotEmptyFlag = (USART_FIFOSTAT_RXNOTEMPTY_MASK), /*!< RXNOEMPTY bit, sets if RX buffer is not empty */
\r
119 kUSART_RxFifoFullFlag = (USART_FIFOSTAT_RXFULL_MASK), /*!< RXFULL bit, sets if RX buffer is full */
\r
122 /*! @brief USART configuration structure. */
\r
123 typedef struct _usart_config
\r
125 uint32_t baudRate_Bps; /*!< USART baud rate */
\r
126 usart_parity_mode_t parityMode; /*!< Parity mode, disabled (default), even, odd */
\r
127 usart_stop_bit_count_t stopBitCount; /*!< Number of stop bits, 1 stop bit (default) or 2 stop bits */
\r
128 usart_data_len_t bitCountPerChar; /*!< Data length - 7 bit, 8 bit */
\r
129 bool loopback; /*!< Enable peripheral loopback */
\r
130 bool enableRx; /*!< Enable RX */
\r
131 bool enableTx; /*!< Enable TX */
\r
132 usart_txfifo_watermark_t txWatermark; /*!< txFIFO watermark */
\r
133 usart_rxfifo_watermark_t rxWatermark; /*!< rxFIFO watermark */
\r
136 /*! @brief USART transfer structure. */
\r
137 typedef struct _usart_transfer
\r
139 uint8_t *data; /*!< The buffer of data to be transfer.*/
\r
140 size_t dataSize; /*!< The byte count to be transfer. */
\r
141 } usart_transfer_t;
\r
143 /* Forward declaration of the handle typedef. */
\r
144 typedef struct _usart_handle usart_handle_t;
\r
146 /*! @brief USART transfer callback function. */
\r
147 typedef void (*usart_transfer_callback_t)(USART_Type *base, usart_handle_t *handle, status_t status, void *userData);
\r
149 /*! @brief USART handle structure. */
\r
150 struct _usart_handle
\r
152 uint8_t *volatile txData; /*!< Address of remaining data to send. */
\r
153 volatile size_t txDataSize; /*!< Size of the remaining data to send. */
\r
154 size_t txDataSizeAll; /*!< Size of the data to send out. */
\r
155 uint8_t *volatile rxData; /*!< Address of remaining data to receive. */
\r
156 volatile size_t rxDataSize; /*!< Size of the remaining data to receive. */
\r
157 size_t rxDataSizeAll; /*!< Size of the data to receive. */
\r
159 uint8_t *rxRingBuffer; /*!< Start address of the receiver ring buffer. */
\r
160 size_t rxRingBufferSize; /*!< Size of the ring buffer. */
\r
161 volatile uint16_t rxRingBufferHead; /*!< Index for the driver to store received data into ring buffer. */
\r
162 volatile uint16_t rxRingBufferTail; /*!< Index for the user to get data from the ring buffer. */
\r
164 usart_transfer_callback_t callback; /*!< Callback function. */
\r
165 void *userData; /*!< USART callback function parameter.*/
\r
167 volatile uint8_t txState; /*!< TX transfer state. */
\r
168 volatile uint8_t rxState; /*!< RX transfer state */
\r
170 usart_txfifo_watermark_t txWatermark; /*!< txFIFO watermark */
\r
171 usart_rxfifo_watermark_t rxWatermark; /*!< rxFIFO watermark */
\r
174 /*******************************************************************************
\r
176 ******************************************************************************/
\r
178 #if defined(__cplusplus)
\r
180 #endif /* _cplusplus */
\r
182 /*! @brief Returns instance number for USART peripheral base address. */
\r
183 uint32_t USART_GetInstance(USART_Type *base);
\r
186 * @name Initialization and deinitialization
\r
191 * @brief Initializes a USART instance with user configuration structure and peripheral clock.
\r
193 * This function configures the USART module with the user-defined settings. The user can configure the configuration
\r
194 * structure and also get the default configuration by using the USART_GetDefaultConfig() function.
\r
195 * Example below shows how to use this API to configure USART.
\r
197 * usart_config_t usartConfig;
\r
198 * usartConfig.baudRate_Bps = 115200U;
\r
199 * usartConfig.parityMode = kUSART_ParityDisabled;
\r
200 * usartConfig.stopBitCount = kUSART_OneStopBit;
\r
201 * USART_Init(USART1, &usartConfig, 20000000U);
\r
204 * @param base USART peripheral base address.
\r
205 * @param config Pointer to user-defined configuration structure.
\r
206 * @param srcClock_Hz USART clock source frequency in HZ.
\r
207 * @retval kStatus_USART_BaudrateNotSupport Baudrate is not support in current clock source.
\r
208 * @retval kStatus_InvalidArgument USART base address is not valid
\r
209 * @retval kStatus_Success Status USART initialize succeed
\r
211 status_t USART_Init(USART_Type *base, const usart_config_t *config, uint32_t srcClock_Hz);
\r
214 * @brief Deinitializes a USART instance.
\r
216 * This function waits for TX complete, disables TX and RX, and disables the USART clock.
\r
218 * @param base USART peripheral base address.
\r
220 void USART_Deinit(USART_Type *base);
\r
223 * @brief Gets the default configuration structure.
\r
225 * This function initializes the USART configuration structure to a default value. The default
\r
227 * usartConfig->baudRate_Bps = 115200U;
\r
228 * usartConfig->parityMode = kUSART_ParityDisabled;
\r
229 * usartConfig->stopBitCount = kUSART_OneStopBit;
\r
230 * usartConfig->bitCountPerChar = kUSART_8BitsPerChar;
\r
231 * usartConfig->loopback = false;
\r
232 * usartConfig->enableTx = false;
\r
233 * usartConfig->enableRx = false;
\r
235 * @param config Pointer to configuration structure.
\r
237 void USART_GetDefaultConfig(usart_config_t *config);
\r
240 * @brief Sets the USART instance baud rate.
\r
242 * This function configures the USART module baud rate. This function is used to update
\r
243 * the USART module baud rate after the USART module is initialized by the USART_Init.
\r
245 * USART_SetBaudRate(USART1, 115200U, 20000000U);
\r
248 * @param base USART peripheral base address.
\r
249 * @param baudrate_Bps USART baudrate to be set.
\r
250 * @param srcClock_Hz USART clock source freqency in HZ.
\r
251 * @retval kStatus_USART_BaudrateNotSupport Baudrate is not support in current clock source.
\r
252 * @retval kStatus_Success Set baudrate succeed.
\r
253 * @retval kStatus_InvalidArgument One or more arguments are invalid.
\r
255 status_t USART_SetBaudRate(USART_Type *base, uint32_t baudrate_Bps, uint32_t srcClock_Hz);
\r
265 * @brief Get USART status flags.
\r
267 * This function get all USART status flags, the flags are returned as the logical
\r
268 * OR value of the enumerators @ref _usart_flags. To check a specific status,
\r
269 * compare the return value with enumerators in @ref _usart_flags.
\r
270 * For example, to check whether the TX is empty:
\r
272 * if (kUSART_TxFifoNotFullFlag & USART_GetStatusFlags(USART1))
\r
278 * @param base USART peripheral base address.
\r
279 * @return USART status flags which are ORed by the enumerators in the _usart_flags.
\r
281 static inline uint32_t USART_GetStatusFlags(USART_Type *base)
\r
283 return base->FIFOSTAT;
\r
287 * @brief Clear USART status flags.
\r
289 * This function clear supported USART status flags
\r
290 * Flags that can be cleared or set are:
\r
295 * USART_ClearStatusFlags(USART1, kUSART_TxError | kUSART_RxError)
\r
298 * @param base USART peripheral base address.
\r
299 * @param mask status flags to be cleared.
\r
301 static inline void USART_ClearStatusFlags(USART_Type *base, uint32_t mask)
\r
303 /* Only TXERR, RXERR fields support write. Remaining fields should be set to zero */
\r
304 base->FIFOSTAT = mask & (USART_FIFOSTAT_TXERR_MASK | USART_FIFOSTAT_RXERR_MASK);
\r
315 * @brief Enables USART interrupts according to the provided mask.
\r
317 * This function enables the USART interrupts according to the provided mask. The mask
\r
318 * is a logical OR of enumeration members. See @ref _usart_interrupt_enable.
\r
319 * For example, to enable TX empty interrupt and RX full interrupt:
\r
321 * USART_EnableInterrupts(USART1, kUSART_TxLevelInterruptEnable | kUSART_RxLevelInterruptEnable);
\r
324 * @param base USART peripheral base address.
\r
325 * @param mask The interrupts to enable. Logical OR of @ref _usart_interrupt_enable.
\r
327 static inline void USART_EnableInterrupts(USART_Type *base, uint32_t mask)
\r
329 base->FIFOINTENSET = mask & 0xF;
\r
333 * @brief Disables USART interrupts according to a provided mask.
\r
335 * This function disables the USART interrupts according to a provided mask. The mask
\r
336 * is a logical OR of enumeration members. See @ref _usart_interrupt_enable.
\r
337 * This example shows how to disable the TX empty interrupt and RX full interrupt:
\r
339 * USART_DisableInterrupts(USART1, kUSART_TxLevelInterruptEnable | kUSART_RxLevelInterruptEnable);
\r
342 * @param base USART peripheral base address.
\r
343 * @param mask The interrupts to disable. Logical OR of @ref _usart_interrupt_enable.
\r
345 static inline void USART_DisableInterrupts(USART_Type *base, uint32_t mask)
\r
347 base->FIFOINTENCLR = mask & 0xF;
\r
351 * @brief Returns enabled USART interrupts.
\r
353 * This function returns the enabled USART interrupts.
\r
355 * @param base USART peripheral base address.
\r
357 static inline uint32_t USART_GetEnabledInterrupts(USART_Type *base)
\r
359 return base->FIFOINTENSET;
\r
363 * @brief Enable DMA for Tx
\r
365 static inline void USART_EnableTxDMA(USART_Type *base, bool enable)
\r
369 base->FIFOCFG |= USART_FIFOCFG_DMATX_MASK;
\r
373 base->FIFOCFG &= ~(USART_FIFOCFG_DMATX_MASK);
\r
378 * @brief Enable DMA for Rx
\r
380 static inline void USART_EnableRxDMA(USART_Type *base, bool enable)
\r
384 base->FIFOCFG |= USART_FIFOCFG_DMARX_MASK;
\r
388 base->FIFOCFG &= ~(USART_FIFOCFG_DMARX_MASK);
\r
393 * @brief Enable CTS.
\r
394 * This function will determine whether CTS is used for flow control.
\r
396 * @param base USART peripheral base address.
\r
397 * @param enable Enable CTS or not, true for enable and false for disable.
\r
399 static inline void USART_EnableCTS(USART_Type *base, bool enable)
\r
403 base->CFG |= USART_CFG_CTSEN_MASK;
\r
407 base->CFG &= ~USART_CFG_CTSEN_MASK;
\r
414 * @name Bus Operations
\r
419 * @brief Writes to the FIFOWR register.
\r
421 * This function writes data to the txFIFO directly. The upper layer must ensure
\r
422 * that txFIFO has space for data to write before calling this function.
\r
424 * @param base USART peripheral base address.
\r
425 * @param data The byte to write.
\r
427 static inline void USART_WriteByte(USART_Type *base, uint8_t data)
\r
429 base->FIFOWR = data;
\r
433 * @brief Reads the FIFORD register directly.
\r
435 * This function reads data from the rxFIFO directly. The upper layer must
\r
436 * ensure that the rxFIFO is not empty before calling this function.
\r
438 * @param base USART peripheral base address.
\r
439 * @return The byte read from USART data register.
\r
441 static inline uint8_t USART_ReadByte(USART_Type *base)
\r
443 return base->FIFORD;
\r
447 * @brief Writes to the TX register using a blocking method.
\r
449 * This function polls the TX register, waits for the TX register to be empty or for the TX FIFO
\r
450 * to have room and writes data to the TX buffer.
\r
452 * @param base USART peripheral base address.
\r
453 * @param data Start address of the data to write.
\r
454 * @param length Size of the data to write.
\r
456 void USART_WriteBlocking(USART_Type *base, const uint8_t *data, size_t length);
\r
459 * @brief Read RX data register using a blocking method.
\r
461 * This function polls the RX register, waits for the RX register to be full or for RX FIFO to
\r
462 * have data and read data from the TX register.
\r
464 * @param base USART peripheral base address.
\r
465 * @param data Start address of the buffer to store the received data.
\r
466 * @param length Size of the buffer.
\r
467 * @retval kStatus_USART_FramingError Receiver overrun happened while receiving data.
\r
468 * @retval kStatus_USART_ParityError Noise error happened while receiving data.
\r
469 * @retval kStatus_USART_NoiseError Framing error happened while receiving data.
\r
470 * @retval kStatus_USART_RxError Overflow or underflow rxFIFO happened.
\r
471 * @retval kStatus_Success Successfully received all data.
\r
473 status_t USART_ReadBlocking(USART_Type *base, uint8_t *data, size_t length);
\r
478 * @name Transactional
\r
483 * @brief Initializes the USART handle.
\r
485 * This function initializes the USART handle which can be used for other USART
\r
486 * transactional APIs. Usually, for a specified USART instance,
\r
487 * call this API once to get the initialized handle.
\r
489 * @param base USART peripheral base address.
\r
490 * @param handle USART handle pointer.
\r
491 * @param callback The callback function.
\r
492 * @param userData The parameter of the callback function.
\r
494 status_t USART_TransferCreateHandle(USART_Type *base,
\r
495 usart_handle_t *handle,
\r
496 usart_transfer_callback_t callback,
\r
500 * @brief Transmits a buffer of data using the interrupt method.
\r
502 * This function sends data using an interrupt method. This is a non-blocking function, which
\r
503 * returns directly without waiting for all data to be written to the TX register. When
\r
504 * all data is written to the TX register in the IRQ handler, the USART driver calls the callback
\r
505 * function and passes the @ref kStatus_USART_TxIdle as status parameter.
\r
507 * @note The kStatus_USART_TxIdle is passed to the upper layer when all data is written
\r
508 * to the TX register. However it does not ensure that all data are sent out. Before disabling the TX,
\r
509 * check the kUSART_TransmissionCompleteFlag to ensure that the TX is finished.
\r
511 * @param base USART peripheral base address.
\r
512 * @param handle USART handle pointer.
\r
513 * @param xfer USART transfer structure. See #usart_transfer_t.
\r
514 * @retval kStatus_Success Successfully start the data transmission.
\r
515 * @retval kStatus_USART_TxBusy Previous transmission still not finished, data not all written to TX register yet.
\r
516 * @retval kStatus_InvalidArgument Invalid argument.
\r
518 status_t USART_TransferSendNonBlocking(USART_Type *base, usart_handle_t *handle, usart_transfer_t *xfer);
\r
521 * @brief Sets up the RX ring buffer.
\r
523 * This function sets up the RX ring buffer to a specific USART handle.
\r
525 * When the RX ring buffer is used, data received are stored into the ring buffer even when the
\r
526 * user doesn't call the USART_TransferReceiveNonBlocking() API. If there is already data received
\r
527 * in the ring buffer, the user can get the received data from the ring buffer directly.
\r
529 * @note When using the RX ring buffer, one byte is reserved for internal use. In other
\r
530 * words, if @p ringBufferSize is 32, then only 31 bytes are used for saving data.
\r
532 * @param base USART peripheral base address.
\r
533 * @param handle USART handle pointer.
\r
534 * @param ringBuffer Start address of the ring buffer for background receiving. Pass NULL to disable the ring buffer.
\r
535 * @param ringBufferSize size of the ring buffer.
\r
537 void USART_TransferStartRingBuffer(USART_Type *base,
\r
538 usart_handle_t *handle,
\r
539 uint8_t *ringBuffer,
\r
540 size_t ringBufferSize);
\r
543 * @brief Aborts the background transfer and uninstalls the ring buffer.
\r
545 * This function aborts the background transfer and uninstalls the ring buffer.
\r
547 * @param base USART peripheral base address.
\r
548 * @param handle USART handle pointer.
\r
550 void USART_TransferStopRingBuffer(USART_Type *base, usart_handle_t *handle);
\r
553 * @brief Get the length of received data in RX ring buffer.
\r
555 * @param handle USART handle pointer.
\r
556 * @return Length of received data in RX ring buffer.
\r
558 size_t USART_TransferGetRxRingBufferLength(usart_handle_t *handle);
\r
561 * @brief Aborts the interrupt-driven data transmit.
\r
563 * This function aborts the interrupt driven data sending. The user can get the remainBtyes to find out
\r
564 * how many bytes are still not sent out.
\r
566 * @param base USART peripheral base address.
\r
567 * @param handle USART handle pointer.
\r
569 void USART_TransferAbortSend(USART_Type *base, usart_handle_t *handle);
\r
572 * @brief Get the number of bytes that have been written to USART TX register.
\r
574 * This function gets the number of bytes that have been written to USART TX
\r
575 * register by interrupt method.
\r
577 * @param base USART peripheral base address.
\r
578 * @param handle USART handle pointer.
\r
579 * @param count Send bytes count.
\r
580 * @retval kStatus_NoTransferInProgress No send in progress.
\r
581 * @retval kStatus_InvalidArgument Parameter is invalid.
\r
582 * @retval kStatus_Success Get successfully through the parameter \p count;
\r
584 status_t USART_TransferGetSendCount(USART_Type *base, usart_handle_t *handle, uint32_t *count);
\r
587 * @brief Receives a buffer of data using an interrupt method.
\r
589 * This function receives data using an interrupt method. This is a non-blocking function, which
\r
590 * returns without waiting for all data to be received.
\r
591 * If the RX ring buffer is used and not empty, the data in the ring buffer is copied and
\r
592 * the parameter @p receivedBytes shows how many bytes are copied from the ring buffer.
\r
593 * After copying, if the data in the ring buffer is not enough to read, the receive
\r
594 * request is saved by the USART driver. When the new data arrives, the receive request
\r
595 * is serviced first. When all data is received, the USART driver notifies the upper layer
\r
596 * through a callback function and passes the status parameter @ref kStatus_USART_RxIdle.
\r
597 * For example, the upper layer needs 10 bytes but there are only 5 bytes in the ring buffer.
\r
598 * The 5 bytes are copied to the xfer->data and this function returns with the
\r
599 * parameter @p receivedBytes set to 5. For the left 5 bytes, newly arrived data is
\r
600 * saved from the xfer->data[5]. When 5 bytes are received, the USART driver notifies the upper layer.
\r
601 * If the RX ring buffer is not enabled, this function enables the RX and RX interrupt
\r
602 * to receive data to the xfer->data. When all data is received, the upper layer is notified.
\r
604 * @param base USART peripheral base address.
\r
605 * @param handle USART handle pointer.
\r
606 * @param xfer USART transfer structure, see #usart_transfer_t.
\r
607 * @param receivedBytes Bytes received from the ring buffer directly.
\r
608 * @retval kStatus_Success Successfully queue the transfer into transmit queue.
\r
609 * @retval kStatus_USART_RxBusy Previous receive request is not finished.
\r
610 * @retval kStatus_InvalidArgument Invalid argument.
\r
612 status_t USART_TransferReceiveNonBlocking(USART_Type *base,
\r
613 usart_handle_t *handle,
\r
614 usart_transfer_t *xfer,
\r
615 size_t *receivedBytes);
\r
618 * @brief Aborts the interrupt-driven data receiving.
\r
620 * This function aborts the interrupt-driven data receiving. The user can get the remainBytes to find out
\r
621 * how many bytes not received yet.
\r
623 * @param base USART peripheral base address.
\r
624 * @param handle USART handle pointer.
\r
626 void USART_TransferAbortReceive(USART_Type *base, usart_handle_t *handle);
\r
629 * @brief Get the number of bytes that have been received.
\r
631 * This function gets the number of bytes that have been received.
\r
633 * @param base USART peripheral base address.
\r
634 * @param handle USART handle pointer.
\r
635 * @param count Receive bytes count.
\r
636 * @retval kStatus_NoTransferInProgress No receive in progress.
\r
637 * @retval kStatus_InvalidArgument Parameter is invalid.
\r
638 * @retval kStatus_Success Get successfully through the parameter \p count;
\r
640 status_t USART_TransferGetReceiveCount(USART_Type *base, usart_handle_t *handle, uint32_t *count);
\r
643 * @brief USART IRQ handle function.
\r
645 * This function handles the USART transmit and receive IRQ request.
\r
647 * @param base USART peripheral base address.
\r
648 * @param handle USART handle pointer.
\r
650 void USART_TransferHandleIRQ(USART_Type *base, usart_handle_t *handle);
\r
654 #if defined(__cplusplus)
\r
660 #endif /* _FSL_USART_H_ */
\r