2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
\r
3 * Copyright 2016-2019 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.1.1. */
\r
25 #define FSL_USART_DRIVER_VERSION (MAKE_VERSION(2, 1, 1))
\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 synchronous mode. */
\r
49 typedef enum _usart_sync_mode
\r
51 kUSART_SyncModeDisabled = 0x0U, /*!< Asynchronous mode. */
\r
52 kUSART_SyncModeSlave = 0x2U, /*!< Synchronous slave mode. */
\r
53 kUSART_SyncModeMaster = 0x3U, /*!< Synchronous master mode. */
\r
54 } usart_sync_mode_t;
\r
56 /*! @brief USART parity mode. */
\r
57 typedef enum _usart_parity_mode
\r
59 kUSART_ParityDisabled = 0x0U, /*!< Parity disabled */
\r
60 kUSART_ParityEven = 0x2U, /*!< Parity enabled, type even, bit setting: PE|PT = 10 */
\r
61 kUSART_ParityOdd = 0x3U, /*!< Parity enabled, type odd, bit setting: PE|PT = 11 */
\r
62 } usart_parity_mode_t;
\r
64 /*! @brief USART stop bit count. */
\r
65 typedef enum _usart_stop_bit_count
\r
67 kUSART_OneStopBit = 0U, /*!< One stop bit */
\r
68 kUSART_TwoStopBit = 1U, /*!< Two stop bits */
\r
69 } usart_stop_bit_count_t;
\r
71 /*! @brief USART data size. */
\r
72 typedef enum _usart_data_len
\r
74 kUSART_7BitsPerChar = 0U, /*!< Seven bit mode */
\r
75 kUSART_8BitsPerChar = 1U, /*!< Eight bit mode */
\r
78 /*! @brief USART clock polarity configuration, used in sync mode.*/
\r
79 typedef enum _usart_clock_polarity
\r
81 kUSART_RxSampleOnFallingEdge = 0x0U, /*!< Un_RXD is sampled on the falling edge of SCLK. */
\r
82 kUSART_RxSampleOnRisingEdge = 0x1U, /*!< Un_RXD is sampled on the rising edge of SCLK. */
\r
83 } usart_clock_polarity_t;
\r
85 /*! @brief txFIFO watermark values */
\r
86 typedef enum _usart_txfifo_watermark
\r
88 kUSART_TxFifo0 = 0, /*!< USART tx watermark is empty */
\r
89 kUSART_TxFifo1 = 1, /*!< USART tx watermark at 1 item */
\r
90 kUSART_TxFifo2 = 2, /*!< USART tx watermark at 2 items */
\r
91 kUSART_TxFifo3 = 3, /*!< USART tx watermark at 3 items */
\r
92 kUSART_TxFifo4 = 4, /*!< USART tx watermark at 4 items */
\r
93 kUSART_TxFifo5 = 5, /*!< USART tx watermark at 5 items */
\r
94 kUSART_TxFifo6 = 6, /*!< USART tx watermark at 6 items */
\r
95 kUSART_TxFifo7 = 7, /*!< USART tx watermark at 7 items */
\r
96 } usart_txfifo_watermark_t;
\r
98 /*! @brief rxFIFO watermark values */
\r
99 typedef enum _usart_rxfifo_watermark
\r
101 kUSART_RxFifo1 = 0, /*!< USART rx watermark at 1 item */
\r
102 kUSART_RxFifo2 = 1, /*!< USART rx watermark at 2 items */
\r
103 kUSART_RxFifo3 = 2, /*!< USART rx watermark at 3 items */
\r
104 kUSART_RxFifo4 = 3, /*!< USART rx watermark at 4 items */
\r
105 kUSART_RxFifo5 = 4, /*!< USART rx watermark at 5 items */
\r
106 kUSART_RxFifo6 = 5, /*!< USART rx watermark at 6 items */
\r
107 kUSART_RxFifo7 = 6, /*!< USART rx watermark at 7 items */
\r
108 kUSART_RxFifo8 = 7, /*!< USART rx watermark at 8 items */
\r
109 } usart_rxfifo_watermark_t;
\r
112 * @brief USART interrupt configuration structure, default settings all disabled.
\r
114 enum _usart_interrupt_enable
\r
116 kUSART_TxErrorInterruptEnable = (USART_FIFOINTENSET_TXERR_MASK),
\r
117 kUSART_RxErrorInterruptEnable = (USART_FIFOINTENSET_RXERR_MASK),
\r
118 kUSART_TxLevelInterruptEnable = (USART_FIFOINTENSET_TXLVL_MASK),
\r
119 kUSART_RxLevelInterruptEnable = (USART_FIFOINTENSET_RXLVL_MASK),
\r
123 * @brief USART status flags.
\r
125 * This provides constants for the USART status flags for use in the USART functions.
\r
129 kUSART_TxError = (USART_FIFOSTAT_TXERR_MASK), /*!< TEERR bit, sets if TX buffer is error */
\r
130 kUSART_RxError = (USART_FIFOSTAT_RXERR_MASK), /*!< RXERR bit, sets if RX buffer is error */
\r
131 kUSART_TxFifoEmptyFlag = (USART_FIFOSTAT_TXEMPTY_MASK), /*!< TXEMPTY bit, sets if TX buffer is empty */
\r
132 kUSART_TxFifoNotFullFlag = (USART_FIFOSTAT_TXNOTFULL_MASK), /*!< TXNOTFULL bit, sets if TX buffer is not full */
\r
133 kUSART_RxFifoNotEmptyFlag = (USART_FIFOSTAT_RXNOTEMPTY_MASK), /*!< RXNOEMPTY bit, sets if RX buffer is not empty */
\r
134 kUSART_RxFifoFullFlag = (USART_FIFOSTAT_RXFULL_MASK), /*!< RXFULL bit, sets if RX buffer is full */
\r
137 /*! @brief USART configuration structure. */
\r
138 typedef struct _usart_config
\r
140 uint32_t baudRate_Bps; /*!< USART baud rate */
\r
141 usart_parity_mode_t parityMode; /*!< Parity mode, disabled (default), even, odd */
\r
142 usart_stop_bit_count_t stopBitCount; /*!< Number of stop bits, 1 stop bit (default) or 2 stop bits */
\r
143 usart_data_len_t bitCountPerChar; /*!< Data length - 7 bit, 8 bit */
\r
144 bool loopback; /*!< Enable peripheral loopback */
\r
145 bool enableRx; /*!< Enable RX */
\r
146 bool enableTx; /*!< Enable TX */
\r
147 bool enableContinuousSCLK; /*!< USART continuous Clock generation enable in synchronous master mode. */
\r
148 usart_txfifo_watermark_t txWatermark; /*!< txFIFO watermark */
\r
149 usart_rxfifo_watermark_t rxWatermark; /*!< rxFIFO watermark */
\r
150 usart_sync_mode_t syncMode; /*!< Transfer mode select - asynchronous, synchronous master, synchronous slave. */
\r
151 usart_clock_polarity_t clockPolarity; /*!< Selects the clock polarity and sampling edge in synchronous mode. */
\r
154 /*! @brief USART transfer structure. */
\r
155 typedef struct _usart_transfer
\r
157 uint8_t *data; /*!< The buffer of data to be transfer.*/
\r
158 size_t dataSize; /*!< The byte count to be transfer. */
\r
159 } usart_transfer_t;
\r
161 /* Forward declaration of the handle typedef. */
\r
162 typedef struct _usart_handle usart_handle_t;
\r
164 /*! @brief USART transfer callback function. */
\r
165 typedef void (*usart_transfer_callback_t)(USART_Type *base, usart_handle_t *handle, status_t status, void *userData);
\r
167 /*! @brief USART handle structure. */
\r
168 struct _usart_handle
\r
170 uint8_t *volatile txData; /*!< Address of remaining data to send. */
\r
171 volatile size_t txDataSize; /*!< Size of the remaining data to send. */
\r
172 size_t txDataSizeAll; /*!< Size of the data to send out. */
\r
173 uint8_t *volatile rxData; /*!< Address of remaining data to receive. */
\r
174 volatile size_t rxDataSize; /*!< Size of the remaining data to receive. */
\r
175 size_t rxDataSizeAll; /*!< Size of the data to receive. */
\r
177 uint8_t *rxRingBuffer; /*!< Start address of the receiver ring buffer. */
\r
178 size_t rxRingBufferSize; /*!< Size of the ring buffer. */
\r
179 volatile uint16_t rxRingBufferHead; /*!< Index for the driver to store received data into ring buffer. */
\r
180 volatile uint16_t rxRingBufferTail; /*!< Index for the user to get data from the ring buffer. */
\r
182 usart_transfer_callback_t callback; /*!< Callback function. */
\r
183 void *userData; /*!< USART callback function parameter.*/
\r
185 volatile uint8_t txState; /*!< TX transfer state. */
\r
186 volatile uint8_t rxState; /*!< RX transfer state */
\r
188 uint8_t txWatermark; /*!< txFIFO watermark */
\r
189 uint8_t rxWatermark; /*!< rxFIFO watermark */
\r
192 /*! @brief Typedef for usart interrupt handler. */
\r
193 typedef void (*flexcomm_usart_irq_handler_t)(USART_Type *base, usart_handle_t *handle);
\r
195 /*******************************************************************************
\r
197 ******************************************************************************/
\r
199 #if defined(__cplusplus)
\r
201 #endif /* _cplusplus */
\r
203 /*! @brief Returns instance number for USART peripheral base address. */
\r
204 uint32_t USART_GetInstance(USART_Type *base);
\r
207 * @name Initialization and deinitialization
\r
212 * @brief Initializes a USART instance with user configuration structure and peripheral clock.
\r
214 * This function configures the USART module with the user-defined settings. The user can configure the configuration
\r
215 * structure and also get the default configuration by using the USART_GetDefaultConfig() function.
\r
216 * Example below shows how to use this API to configure USART.
\r
218 * usart_config_t usartConfig;
\r
219 * usartConfig.baudRate_Bps = 115200U;
\r
220 * usartConfig.parityMode = kUSART_ParityDisabled;
\r
221 * usartConfig.stopBitCount = kUSART_OneStopBit;
\r
222 * USART_Init(USART1, &usartConfig, 20000000U);
\r
225 * @param base USART peripheral base address.
\r
226 * @param config Pointer to user-defined configuration structure.
\r
227 * @param srcClock_Hz USART clock source frequency in HZ.
\r
228 * @retval kStatus_USART_BaudrateNotSupport Baudrate is not support in current clock source.
\r
229 * @retval kStatus_InvalidArgument USART base address is not valid
\r
230 * @retval kStatus_Success Status USART initialize succeed
\r
232 status_t USART_Init(USART_Type *base, const usart_config_t *config, uint32_t srcClock_Hz);
\r
235 * @brief Deinitializes a USART instance.
\r
237 * This function waits for TX complete, disables TX and RX, and disables the USART clock.
\r
239 * @param base USART peripheral base address.
\r
241 void USART_Deinit(USART_Type *base);
\r
244 * @brief Gets the default configuration structure.
\r
246 * This function initializes the USART configuration structure to a default value. The default
\r
248 * usartConfig->baudRate_Bps = 115200U;
\r
249 * usartConfig->parityMode = kUSART_ParityDisabled;
\r
250 * usartConfig->stopBitCount = kUSART_OneStopBit;
\r
251 * usartConfig->bitCountPerChar = kUSART_8BitsPerChar;
\r
252 * usartConfig->loopback = false;
\r
253 * usartConfig->enableTx = false;
\r
254 * usartConfig->enableRx = false;
\r
256 * @param config Pointer to configuration structure.
\r
258 void USART_GetDefaultConfig(usart_config_t *config);
\r
261 * @brief Sets the USART instance baud rate.
\r
263 * This function configures the USART module baud rate. This function is used to update
\r
264 * the USART module baud rate after the USART module is initialized by the USART_Init.
\r
266 * USART_SetBaudRate(USART1, 115200U, 20000000U);
\r
269 * @param base USART peripheral base address.
\r
270 * @param baudrate_Bps USART baudrate to be set.
\r
271 * @param srcClock_Hz USART clock source frequency in HZ.
\r
272 * @retval kStatus_USART_BaudrateNotSupport Baudrate is not support in current clock source.
\r
273 * @retval kStatus_Success Set baudrate succeed.
\r
274 * @retval kStatus_InvalidArgument One or more arguments are invalid.
\r
276 status_t USART_SetBaudRate(USART_Type *base, uint32_t baudrate_Bps, uint32_t srcClock_Hz);
\r
286 * @brief Get USART status flags.
\r
288 * This function get all USART status flags, the flags are returned as the logical
\r
289 * OR value of the enumerators @ref _usart_flags. To check a specific status,
\r
290 * compare the return value with enumerators in @ref _usart_flags.
\r
291 * For example, to check whether the TX is empty:
\r
293 * if (kUSART_TxFifoNotFullFlag & USART_GetStatusFlags(USART1))
\r
299 * @param base USART peripheral base address.
\r
300 * @return USART status flags which are ORed by the enumerators in the _usart_flags.
\r
302 static inline uint32_t USART_GetStatusFlags(USART_Type *base)
\r
304 return base->FIFOSTAT;
\r
308 * @brief Clear USART status flags.
\r
310 * This function clear supported USART status flags
\r
311 * Flags that can be cleared or set are:
\r
316 * USART_ClearStatusFlags(USART1, kUSART_TxError | kUSART_RxError)
\r
319 * @param base USART peripheral base address.
\r
320 * @param mask status flags to be cleared.
\r
322 static inline void USART_ClearStatusFlags(USART_Type *base, uint32_t mask)
\r
324 /* Only TXERR, RXERR fields support write. Remaining fields should be set to zero */
\r
325 base->FIFOSTAT = mask & (USART_FIFOSTAT_TXERR_MASK | USART_FIFOSTAT_RXERR_MASK);
\r
336 * @brief Enables USART interrupts according to the provided mask.
\r
338 * This function enables the USART interrupts according to the provided mask. The mask
\r
339 * is a logical OR of enumeration members. See @ref _usart_interrupt_enable.
\r
340 * For example, to enable TX empty interrupt and RX full interrupt:
\r
342 * USART_EnableInterrupts(USART1, kUSART_TxLevelInterruptEnable | kUSART_RxLevelInterruptEnable);
\r
345 * @param base USART peripheral base address.
\r
346 * @param mask The interrupts to enable. Logical OR of @ref _usart_interrupt_enable.
\r
348 static inline void USART_EnableInterrupts(USART_Type *base, uint32_t mask)
\r
350 base->FIFOINTENSET = mask & 0xFUL;
\r
354 * @brief Disables USART interrupts according to a provided mask.
\r
356 * This function disables the USART interrupts according to a provided mask. The mask
\r
357 * is a logical OR of enumeration members. See @ref _usart_interrupt_enable.
\r
358 * This example shows how to disable the TX empty interrupt and RX full interrupt:
\r
360 * USART_DisableInterrupts(USART1, kUSART_TxLevelInterruptEnable | kUSART_RxLevelInterruptEnable);
\r
363 * @param base USART peripheral base address.
\r
364 * @param mask The interrupts to disable. Logical OR of @ref _usart_interrupt_enable.
\r
366 static inline void USART_DisableInterrupts(USART_Type *base, uint32_t mask)
\r
368 base->FIFOINTENCLR = mask & 0xFUL;
\r
372 * @brief Returns enabled USART interrupts.
\r
374 * This function returns the enabled USART interrupts.
\r
376 * @param base USART peripheral base address.
\r
378 static inline uint32_t USART_GetEnabledInterrupts(USART_Type *base)
\r
380 return base->FIFOINTENSET;
\r
384 * @brief Enable DMA for Tx
\r
386 static inline void USART_EnableTxDMA(USART_Type *base, bool enable)
\r
390 base->FIFOCFG |= USART_FIFOCFG_DMATX_MASK;
\r
394 base->FIFOCFG &= ~(USART_FIFOCFG_DMATX_MASK);
\r
399 * @brief Enable DMA for Rx
\r
401 static inline void USART_EnableRxDMA(USART_Type *base, bool enable)
\r
405 base->FIFOCFG |= USART_FIFOCFG_DMARX_MASK;
\r
409 base->FIFOCFG &= ~(USART_FIFOCFG_DMARX_MASK);
\r
414 * @brief Enable CTS.
\r
415 * This function will determine whether CTS is used for flow control.
\r
417 * @param base USART peripheral base address.
\r
418 * @param enable Enable CTS or not, true for enable and false for disable.
\r
420 static inline void USART_EnableCTS(USART_Type *base, bool enable)
\r
424 base->CFG |= USART_CFG_CTSEN_MASK;
\r
428 base->CFG &= ~USART_CFG_CTSEN_MASK;
\r
433 * @brief Continuous Clock generation.
\r
434 * By default, SCLK is only output while data is being transmitted in synchronous mode.
\r
435 * Enable this funciton, SCLK will run continuously in synchronous mode, allowing
\r
436 * characters to be received on Un_RxD independently from transmission on Un_TXD).
\r
438 * @param base USART peripheral base address.
\r
439 * @param enable Enable Continuous Clock generation mode or not, true for enable and false for disable.
\r
441 static inline void USART_EnableContinuousSCLK(USART_Type *base, bool enable)
\r
445 base->CTL |= USART_CTL_CC_MASK;
\r
449 base->CTL &= ~USART_CTL_CC_MASK;
\r
454 * @brief Enable Continuous Clock generation bit auto clear.
\r
455 * While enable this cuntion, the Continuous Clock bit is automatically cleared when a complete
\r
456 * character has been received. This bit is cleared at the same time.
\r
458 * @param base USART peripheral base address.
\r
459 * @param enable Enable auto clear or not, true for enable and false for disable.
\r
461 static inline void USART_EnableAutoClearSCLK(USART_Type *base, bool enable)
\r
465 base->CTL |= USART_CTL_CLRCCONRX_MASK;
\r
469 base->CTL &= ~USART_CTL_CLRCCONRX_MASK;
\r
475 * @name Bus Operations
\r
480 * @brief Writes to the FIFOWR register.
\r
482 * This function writes data to the txFIFO directly. The upper layer must ensure
\r
483 * that txFIFO has space for data to write before calling this function.
\r
485 * @param base USART peripheral base address.
\r
486 * @param data The byte to write.
\r
488 static inline void USART_WriteByte(USART_Type *base, uint8_t data)
\r
490 base->FIFOWR = data;
\r
494 * @brief Reads the FIFORD register directly.
\r
496 * This function reads data from the rxFIFO directly. The upper layer must
\r
497 * ensure that the rxFIFO is not empty before calling this function.
\r
499 * @param base USART peripheral base address.
\r
500 * @return The byte read from USART data register.
\r
502 static inline uint8_t USART_ReadByte(USART_Type *base)
\r
504 return (uint8_t)base->FIFORD;
\r
508 * @brief Writes to the TX register using a blocking method.
\r
510 * This function polls the TX register, waits for the TX register to be empty or for the TX FIFO
\r
511 * to have room and writes data to the TX buffer.
\r
513 * @param base USART peripheral base address.
\r
514 * @param data Start address of the data to write.
\r
515 * @param length Size of the data to write.
\r
517 void USART_WriteBlocking(USART_Type *base, const uint8_t *data, size_t length);
\r
520 * @brief Read RX data register using a blocking method.
\r
522 * This function polls the RX register, waits for the RX register to be full or for RX FIFO to
\r
523 * have data and read data from the TX register.
\r
525 * @param base USART peripheral base address.
\r
526 * @param data Start address of the buffer to store the received data.
\r
527 * @param length Size of the buffer.
\r
528 * @retval kStatus_USART_FramingError Receiver overrun happened while receiving data.
\r
529 * @retval kStatus_USART_ParityError Noise error happened while receiving data.
\r
530 * @retval kStatus_USART_NoiseError Framing error happened while receiving data.
\r
531 * @retval kStatus_USART_RxError Overflow or underflow rxFIFO happened.
\r
532 * @retval kStatus_Success Successfully received all data.
\r
534 status_t USART_ReadBlocking(USART_Type *base, uint8_t *data, size_t length);
\r
539 * @name Transactional
\r
544 * @brief Initializes the USART handle.
\r
546 * This function initializes the USART handle which can be used for other USART
\r
547 * transactional APIs. Usually, for a specified USART instance,
\r
548 * call this API once to get the initialized handle.
\r
550 * @param base USART peripheral base address.
\r
551 * @param handle USART handle pointer.
\r
552 * @param callback The callback function.
\r
553 * @param userData The parameter of the callback function.
\r
555 status_t USART_TransferCreateHandle(USART_Type *base,
\r
556 usart_handle_t *handle,
\r
557 usart_transfer_callback_t callback,
\r
561 * @brief Transmits a buffer of data using the interrupt method.
\r
563 * This function sends data using an interrupt method. This is a non-blocking function, which
\r
564 * returns directly without waiting for all data to be written to the TX register. When
\r
565 * all data is written to the TX register in the IRQ handler, the USART driver calls the callback
\r
566 * function and passes the @ref kStatus_USART_TxIdle as status parameter.
\r
568 * @note The kStatus_USART_TxIdle is passed to the upper layer when all data is written
\r
569 * to the TX register. However it does not ensure that all data are sent out. Before disabling the TX,
\r
570 * check the kUSART_TransmissionCompleteFlag to ensure that the TX is finished.
\r
572 * @param base USART peripheral base address.
\r
573 * @param handle USART handle pointer.
\r
574 * @param xfer USART transfer structure. See #usart_transfer_t.
\r
575 * @retval kStatus_Success Successfully start the data transmission.
\r
576 * @retval kStatus_USART_TxBusy Previous transmission still not finished, data not all written to TX register yet.
\r
577 * @retval kStatus_InvalidArgument Invalid argument.
\r
579 status_t USART_TransferSendNonBlocking(USART_Type *base, usart_handle_t *handle, usart_transfer_t *xfer);
\r
582 * @brief Sets up the RX ring buffer.
\r
584 * This function sets up the RX ring buffer to a specific USART handle.
\r
586 * When the RX ring buffer is used, data received are stored into the ring buffer even when the
\r
587 * user doesn't call the USART_TransferReceiveNonBlocking() API. If there is already data received
\r
588 * in the ring buffer, the user can get the received data from the ring buffer directly.
\r
590 * @note When using the RX ring buffer, one byte is reserved for internal use. In other
\r
591 * words, if @p ringBufferSize is 32, then only 31 bytes are used for saving data.
\r
593 * @param base USART peripheral base address.
\r
594 * @param handle USART handle pointer.
\r
595 * @param ringBuffer Start address of the ring buffer for background receiving. Pass NULL to disable the ring buffer.
\r
596 * @param ringBufferSize size of the ring buffer.
\r
598 void USART_TransferStartRingBuffer(USART_Type *base,
\r
599 usart_handle_t *handle,
\r
600 uint8_t *ringBuffer,
\r
601 size_t ringBufferSize);
\r
604 * @brief Aborts the background transfer and uninstalls the ring buffer.
\r
606 * This function aborts the background transfer and uninstalls the ring buffer.
\r
608 * @param base USART peripheral base address.
\r
609 * @param handle USART handle pointer.
\r
611 void USART_TransferStopRingBuffer(USART_Type *base, usart_handle_t *handle);
\r
614 * @brief Get the length of received data in RX ring buffer.
\r
616 * @param handle USART handle pointer.
\r
617 * @return Length of received data in RX ring buffer.
\r
619 size_t USART_TransferGetRxRingBufferLength(usart_handle_t *handle);
\r
622 * @brief Aborts the interrupt-driven data transmit.
\r
624 * This function aborts the interrupt driven data sending. The user can get the remainBtyes to find out
\r
625 * how many bytes are still not sent out.
\r
627 * @param base USART peripheral base address.
\r
628 * @param handle USART handle pointer.
\r
630 void USART_TransferAbortSend(USART_Type *base, usart_handle_t *handle);
\r
633 * @brief Get the number of bytes that have been written to USART TX register.
\r
635 * This function gets the number of bytes that have been written to USART TX
\r
636 * register by interrupt method.
\r
638 * @param base USART peripheral base address.
\r
639 * @param handle USART handle pointer.
\r
640 * @param count Send bytes count.
\r
641 * @retval kStatus_NoTransferInProgress No send in progress.
\r
642 * @retval kStatus_InvalidArgument Parameter is invalid.
\r
643 * @retval kStatus_Success Get successfully through the parameter \p count;
\r
645 status_t USART_TransferGetSendCount(USART_Type *base, usart_handle_t *handle, uint32_t *count);
\r
648 * @brief Receives a buffer of data using an interrupt method.
\r
650 * This function receives data using an interrupt method. This is a non-blocking function, which
\r
651 * returns without waiting for all data to be received.
\r
652 * If the RX ring buffer is used and not empty, the data in the ring buffer is copied and
\r
653 * the parameter @p receivedBytes shows how many bytes are copied from the ring buffer.
\r
654 * After copying, if the data in the ring buffer is not enough to read, the receive
\r
655 * request is saved by the USART driver. When the new data arrives, the receive request
\r
656 * is serviced first. When all data is received, the USART driver notifies the upper layer
\r
657 * through a callback function and passes the status parameter @ref kStatus_USART_RxIdle.
\r
658 * For example, the upper layer needs 10 bytes but there are only 5 bytes in the ring buffer.
\r
659 * The 5 bytes are copied to the xfer->data and this function returns with the
\r
660 * parameter @p receivedBytes set to 5. For the left 5 bytes, newly arrived data is
\r
661 * saved from the xfer->data[5]. When 5 bytes are received, the USART driver notifies the upper layer.
\r
662 * If the RX ring buffer is not enabled, this function enables the RX and RX interrupt
\r
663 * to receive data to the xfer->data. When all data is received, the upper layer is notified.
\r
665 * @param base USART peripheral base address.
\r
666 * @param handle USART handle pointer.
\r
667 * @param xfer USART transfer structure, see #usart_transfer_t.
\r
668 * @param receivedBytes Bytes received from the ring buffer directly.
\r
669 * @retval kStatus_Success Successfully queue the transfer into transmit queue.
\r
670 * @retval kStatus_USART_RxBusy Previous receive request is not finished.
\r
671 * @retval kStatus_InvalidArgument Invalid argument.
\r
673 status_t USART_TransferReceiveNonBlocking(USART_Type *base,
\r
674 usart_handle_t *handle,
\r
675 usart_transfer_t *xfer,
\r
676 size_t *receivedBytes);
\r
679 * @brief Aborts the interrupt-driven data receiving.
\r
681 * This function aborts the interrupt-driven data receiving. The user can get the remainBytes to find out
\r
682 * how many bytes not received yet.
\r
684 * @param base USART peripheral base address.
\r
685 * @param handle USART handle pointer.
\r
687 void USART_TransferAbortReceive(USART_Type *base, usart_handle_t *handle);
\r
690 * @brief Get the number of bytes that have been received.
\r
692 * This function gets the number of bytes that have been received.
\r
694 * @param base USART peripheral base address.
\r
695 * @param handle USART handle pointer.
\r
696 * @param count Receive bytes count.
\r
697 * @retval kStatus_NoTransferInProgress No receive in progress.
\r
698 * @retval kStatus_InvalidArgument Parameter is invalid.
\r
699 * @retval kStatus_Success Get successfully through the parameter \p count;
\r
701 status_t USART_TransferGetReceiveCount(USART_Type *base, usart_handle_t *handle, uint32_t *count);
\r
704 * @brief USART IRQ handle function.
\r
706 * This function handles the USART transmit and receive IRQ request.
\r
708 * @param base USART peripheral base address.
\r
709 * @param handle USART handle pointer.
\r
711 void USART_TransferHandleIRQ(USART_Type *base, usart_handle_t *handle);
\r
715 #if defined(__cplusplus)
\r
721 #endif /* _FSL_USART_H_ */
\r