The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_LPC54114/TOOLCHAIN_GCC_ARM/fsl_usart.h@172:65be27845400, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 20:53:29 2019 +0000
- Revision:
- 172:65be27845400
- Parent:
- 171:3a7713b1edbc
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 148:fd96258d940d | 1 | /* |
Kojto | 148:fd96258d940d | 2 | * Copyright (c) 2016, Freescale Semiconductor, Inc. |
Kojto | 148:fd96258d940d | 3 | * All rights reserved. |
Kojto | 148:fd96258d940d | 4 | * |
Kojto | 148:fd96258d940d | 5 | * Redistribution and use in source and binary forms, with or without modification, |
Kojto | 148:fd96258d940d | 6 | * are permitted provided that the following conditions are met: |
Kojto | 148:fd96258d940d | 7 | * |
Kojto | 148:fd96258d940d | 8 | * o Redistributions of source code must retain the above copyright notice, this list |
Kojto | 148:fd96258d940d | 9 | * of conditions and the following disclaimer. |
Kojto | 148:fd96258d940d | 10 | * |
Kojto | 148:fd96258d940d | 11 | * o Redistributions in binary form must reproduce the above copyright notice, this |
Kojto | 148:fd96258d940d | 12 | * list of conditions and the following disclaimer in the documentation and/or |
Kojto | 148:fd96258d940d | 13 | * other materials provided with the distribution. |
Kojto | 148:fd96258d940d | 14 | * |
Kojto | 148:fd96258d940d | 15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its |
Kojto | 148:fd96258d940d | 16 | * contributors may be used to endorse or promote products derived from this |
Kojto | 148:fd96258d940d | 17 | * software without specific prior written permission. |
Kojto | 148:fd96258d940d | 18 | * |
Kojto | 148:fd96258d940d | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
Kojto | 148:fd96258d940d | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Kojto | 148:fd96258d940d | 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Kojto | 148:fd96258d940d | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
Kojto | 148:fd96258d940d | 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Kojto | 148:fd96258d940d | 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Kojto | 148:fd96258d940d | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
Kojto | 148:fd96258d940d | 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Kojto | 148:fd96258d940d | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Kojto | 148:fd96258d940d | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Kojto | 148:fd96258d940d | 29 | */ |
Kojto | 148:fd96258d940d | 30 | #ifndef _FSL_USART_H_ |
Kojto | 148:fd96258d940d | 31 | #define _FSL_USART_H_ |
Kojto | 148:fd96258d940d | 32 | |
Kojto | 148:fd96258d940d | 33 | #include "fsl_common.h" |
Kojto | 148:fd96258d940d | 34 | |
Kojto | 148:fd96258d940d | 35 | /*! |
Kojto | 148:fd96258d940d | 36 | * @addtogroup usart_driver |
Kojto | 148:fd96258d940d | 37 | * @{ |
Kojto | 148:fd96258d940d | 38 | */ |
Kojto | 148:fd96258d940d | 39 | |
Kojto | 148:fd96258d940d | 40 | /******************************************************************************* |
Kojto | 148:fd96258d940d | 41 | * Definitions |
Kojto | 148:fd96258d940d | 42 | ******************************************************************************/ |
Kojto | 148:fd96258d940d | 43 | |
Kojto | 148:fd96258d940d | 44 | /*! @name Driver version */ |
Kojto | 148:fd96258d940d | 45 | /*@{*/ |
Kojto | 148:fd96258d940d | 46 | /*! @brief USART driver version 2.0.0. */ |
Kojto | 148:fd96258d940d | 47 | #define FSL_USART_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) |
Kojto | 148:fd96258d940d | 48 | /*@}*/ |
Kojto | 148:fd96258d940d | 49 | |
Kojto | 148:fd96258d940d | 50 | #define USART_FIFOTRIG_TXLVL_GET(base) (((base)->FIFOTRIG & USART_FIFOTRIG_TXLVL_MASK) >> USART_FIFOTRIG_TXLVL_SHIFT) |
Kojto | 148:fd96258d940d | 51 | #define USART_FIFOTRIG_RXLVL_GET(base) (((base)->FIFOTRIG & USART_FIFOTRIG_RXLVL_MASK) >> USART_FIFOTRIG_RXLVL_SHIFT) |
Kojto | 148:fd96258d940d | 52 | |
Kojto | 148:fd96258d940d | 53 | /*! @brief Error codes for the USART driver. */ |
Kojto | 148:fd96258d940d | 54 | enum _usart_status |
Kojto | 148:fd96258d940d | 55 | { |
Kojto | 148:fd96258d940d | 56 | kStatus_USART_TxBusy = MAKE_STATUS(kStatusGroup_LPC_USART, 0), /*!< Transmitter is busy. */ |
Kojto | 148:fd96258d940d | 57 | kStatus_USART_RxBusy = MAKE_STATUS(kStatusGroup_LPC_USART, 1), /*!< Receiver is busy. */ |
Kojto | 148:fd96258d940d | 58 | kStatus_USART_TxIdle = MAKE_STATUS(kStatusGroup_LPC_USART, 2), /*!< USART transmitter is idle. */ |
Kojto | 148:fd96258d940d | 59 | kStatus_USART_RxIdle = MAKE_STATUS(kStatusGroup_LPC_USART, 3), /*!< USART receiver is idle. */ |
Kojto | 148:fd96258d940d | 60 | kStatus_USART_TxError = MAKE_STATUS(kStatusGroup_LPC_USART, 7), /*!< Error happens on txFIFO. */ |
Kojto | 148:fd96258d940d | 61 | kStatus_USART_RxError = MAKE_STATUS(kStatusGroup_LPC_USART, 9), /*!< Error happens on txFIFO. */ |
Kojto | 148:fd96258d940d | 62 | kStatus_USART_RxRingBufferOverrun = MAKE_STATUS(kStatusGroup_LPC_USART, 8), /*!< Error happens on rx ring buffer */ |
Kojto | 148:fd96258d940d | 63 | kStatus_USART_NoiseError = MAKE_STATUS(kStatusGroup_LPC_USART, 10), /*!< USART noise error. */ |
Kojto | 148:fd96258d940d | 64 | kStatus_USART_FramingError = MAKE_STATUS(kStatusGroup_LPC_USART, 11), /*!< USART framing error. */ |
Kojto | 148:fd96258d940d | 65 | kStatus_USART_ParityError = MAKE_STATUS(kStatusGroup_LPC_USART, 12), /*!< USART parity error. */ |
Kojto | 148:fd96258d940d | 66 | kStatus_USART_BaudrateNotSupport = |
Kojto | 148:fd96258d940d | 67 | MAKE_STATUS(kStatusGroup_LPC_USART, 13), /*!< Baudrate is not support in current clock source */ |
Kojto | 148:fd96258d940d | 68 | }; |
Kojto | 148:fd96258d940d | 69 | |
Kojto | 148:fd96258d940d | 70 | /*! @brief USART parity mode. */ |
Kojto | 148:fd96258d940d | 71 | typedef enum _usart_parity_mode { |
Kojto | 148:fd96258d940d | 72 | kUSART_ParityDisabled = 0x0U, /*!< Parity disabled */ |
Kojto | 148:fd96258d940d | 73 | kUSART_ParityEven = 0x2U, /*!< Parity enabled, type even, bit setting: PE|PT = 10 */ |
Kojto | 148:fd96258d940d | 74 | kUSART_ParityOdd = 0x3U, /*!< Parity enabled, type odd, bit setting: PE|PT = 11 */ |
Kojto | 148:fd96258d940d | 75 | } usart_parity_mode_t; |
Kojto | 148:fd96258d940d | 76 | |
Kojto | 148:fd96258d940d | 77 | /*! @brief USART stop bit count. */ |
Kojto | 148:fd96258d940d | 78 | typedef enum _usart_stop_bit_count { |
Kojto | 148:fd96258d940d | 79 | kUSART_OneStopBit = 0U, /*!< One stop bit */ |
Kojto | 148:fd96258d940d | 80 | kUSART_TwoStopBit = 1U, /*!< Two stop bits */ |
Kojto | 148:fd96258d940d | 81 | } usart_stop_bit_count_t; |
Kojto | 148:fd96258d940d | 82 | |
Kojto | 148:fd96258d940d | 83 | /*! @brief USART data size. */ |
Kojto | 148:fd96258d940d | 84 | typedef enum _usart_data_len { |
Kojto | 148:fd96258d940d | 85 | kUSART_7BitsPerChar = 0U, /*!< Seven bit mode */ |
Kojto | 148:fd96258d940d | 86 | kUSART_8BitsPerChar = 1U, /*!< Eight bit mode */ |
Kojto | 148:fd96258d940d | 87 | } usart_data_len_t; |
Kojto | 148:fd96258d940d | 88 | |
Kojto | 148:fd96258d940d | 89 | /*! @brief txFIFO watermark values */ |
Kojto | 148:fd96258d940d | 90 | typedef enum _usart_txfifo_watermark { |
Kojto | 148:fd96258d940d | 91 | kUSART_TxFifo0 = 0, /*!< USART tx watermark is empty */ |
Kojto | 148:fd96258d940d | 92 | kUSART_TxFifo1 = 1, /*!< USART tx watermark at 1 item */ |
Kojto | 148:fd96258d940d | 93 | kUSART_TxFifo2 = 2, /*!< USART tx watermark at 2 items */ |
Kojto | 148:fd96258d940d | 94 | kUSART_TxFifo3 = 3, /*!< USART tx watermark at 3 items */ |
Kojto | 148:fd96258d940d | 95 | kUSART_TxFifo4 = 4, /*!< USART tx watermark at 4 items */ |
Kojto | 148:fd96258d940d | 96 | kUSART_TxFifo5 = 5, /*!< USART tx watermark at 5 items */ |
Kojto | 148:fd96258d940d | 97 | kUSART_TxFifo6 = 6, /*!< USART tx watermark at 6 items */ |
Kojto | 148:fd96258d940d | 98 | kUSART_TxFifo7 = 7, /*!< USART tx watermark at 7 items */ |
Kojto | 148:fd96258d940d | 99 | } usart_txfifo_watermark_t; |
Kojto | 148:fd96258d940d | 100 | |
Kojto | 148:fd96258d940d | 101 | /*! @brief rxFIFO watermark values */ |
Kojto | 148:fd96258d940d | 102 | typedef enum _usart_rxfifo_watermark { |
Kojto | 148:fd96258d940d | 103 | kUSART_RxFifo1 = 0, /*!< USART rx watermark at 1 item */ |
Kojto | 148:fd96258d940d | 104 | kUSART_RxFifo2 = 1, /*!< USART rx watermark at 2 items */ |
Kojto | 148:fd96258d940d | 105 | kUSART_RxFifo3 = 2, /*!< USART rx watermark at 3 items */ |
Kojto | 148:fd96258d940d | 106 | kUSART_RxFifo4 = 3, /*!< USART rx watermark at 4 items */ |
Kojto | 148:fd96258d940d | 107 | kUSART_RxFifo5 = 4, /*!< USART rx watermark at 5 items */ |
Kojto | 148:fd96258d940d | 108 | kUSART_RxFifo6 = 5, /*!< USART rx watermark at 6 items */ |
Kojto | 148:fd96258d940d | 109 | kUSART_RxFifo7 = 6, /*!< USART rx watermark at 7 items */ |
Kojto | 148:fd96258d940d | 110 | kUSART_RxFifo8 = 7, /*!< USART rx watermark at 8 items */ |
Kojto | 148:fd96258d940d | 111 | } usart_rxfifo_watermark_t; |
Kojto | 148:fd96258d940d | 112 | |
Kojto | 148:fd96258d940d | 113 | /*! |
Kojto | 148:fd96258d940d | 114 | * @brief USART interrupt configuration structure, default settings all disabled. |
Kojto | 148:fd96258d940d | 115 | */ |
Kojto | 148:fd96258d940d | 116 | enum _usart_interrupt_enable |
Kojto | 148:fd96258d940d | 117 | { |
Kojto | 148:fd96258d940d | 118 | kUSART_TxErrorInterruptEnable = (USART_FIFOINTENSET_TXERR_MASK), |
Kojto | 148:fd96258d940d | 119 | kUSART_RxErrorInterruptEnable = (USART_FIFOINTENSET_RXERR_MASK), |
Kojto | 148:fd96258d940d | 120 | kUSART_TxLevelInterruptEnable = (USART_FIFOINTENSET_TXLVL_MASK), |
Kojto | 148:fd96258d940d | 121 | kUSART_RxLevelInterruptEnable = (USART_FIFOINTENSET_RXLVL_MASK), |
Kojto | 148:fd96258d940d | 122 | }; |
Kojto | 148:fd96258d940d | 123 | |
Kojto | 148:fd96258d940d | 124 | /*! |
Kojto | 148:fd96258d940d | 125 | * @brief USART status flags. |
Kojto | 148:fd96258d940d | 126 | * |
Kojto | 148:fd96258d940d | 127 | * This provides constants for the USART status flags for use in the USART functions. |
Kojto | 148:fd96258d940d | 128 | */ |
Kojto | 148:fd96258d940d | 129 | enum _usart_flags |
Kojto | 148:fd96258d940d | 130 | { |
Kojto | 148:fd96258d940d | 131 | kUSART_TxError = (USART_FIFOSTAT_TXERR_MASK), /*!< TXEMPT bit, sets if TX buffer is empty */ |
Kojto | 148:fd96258d940d | 132 | kUSART_RxError = (USART_FIFOSTAT_RXERR_MASK), /*!< TXEMPT bit, sets if TX buffer is empty */ |
Kojto | 148:fd96258d940d | 133 | kUSART_TxFifoEmptyFlag = (USART_FIFOSTAT_TXEMPTY_MASK), /*!< TXEMPT bit, sets if TX buffer is empty */ |
Kojto | 148:fd96258d940d | 134 | kUSART_TxFifoNotFullFlag = (USART_FIFOSTAT_TXNOTFULL_MASK), /*!< TXEMPT bit, sets if TX buffer is not full */ |
Kojto | 148:fd96258d940d | 135 | kUSART_RxFifoNotEmptyFlag = (USART_FIFOSTAT_RXNOTEMPTY_MASK), /*!< RXEMPT bit, sets if RX buffer is not empty */ |
Kojto | 148:fd96258d940d | 136 | kUSART_RxFifoFullFlag = (USART_FIFOSTAT_RXFULL_MASK), /*!< RXEMPT bit, sets if RX buffer is full */ |
Kojto | 148:fd96258d940d | 137 | }; |
Kojto | 148:fd96258d940d | 138 | |
Kojto | 148:fd96258d940d | 139 | /*! @brief USART configuration structure. */ |
Kojto | 148:fd96258d940d | 140 | typedef struct _usart_config |
Kojto | 148:fd96258d940d | 141 | { |
Kojto | 148:fd96258d940d | 142 | uint32_t baudRate_Bps; /*!< USART baud rate */ |
Kojto | 148:fd96258d940d | 143 | usart_parity_mode_t parityMode; /*!< Parity mode, disabled (default), even, odd */ |
Kojto | 148:fd96258d940d | 144 | usart_stop_bit_count_t stopBitCount; /*!< Number of stop bits, 1 stop bit (default) or 2 stop bits */ |
Kojto | 148:fd96258d940d | 145 | usart_data_len_t bitCountPerChar; /*!< Data length - 7 bit, 8 bit */ |
Kojto | 148:fd96258d940d | 146 | bool loopback; /*!< Enable peripheral loopback */ |
Kojto | 148:fd96258d940d | 147 | bool enableRx; /*!< Enable RX */ |
Kojto | 148:fd96258d940d | 148 | bool enableTx; /*!< Enable TX */ |
Kojto | 148:fd96258d940d | 149 | usart_txfifo_watermark_t txWatermark;/*!< txFIFO watermark */ |
Kojto | 148:fd96258d940d | 150 | usart_rxfifo_watermark_t rxWatermark;/*!< rxFIFO watermark */ |
Kojto | 148:fd96258d940d | 151 | } usart_config_t; |
Kojto | 148:fd96258d940d | 152 | |
Kojto | 148:fd96258d940d | 153 | /*! @brief USART transfer structure. */ |
Kojto | 148:fd96258d940d | 154 | typedef struct _usart_transfer |
Kojto | 148:fd96258d940d | 155 | { |
Kojto | 148:fd96258d940d | 156 | uint8_t *data; /*!< The buffer of data to be transfer.*/ |
Kojto | 148:fd96258d940d | 157 | size_t dataSize; /*!< The byte count to be transfer. */ |
Kojto | 148:fd96258d940d | 158 | } usart_transfer_t; |
Kojto | 148:fd96258d940d | 159 | |
Kojto | 148:fd96258d940d | 160 | /* Forward declaration of the handle typedef. */ |
Kojto | 148:fd96258d940d | 161 | typedef struct _usart_handle usart_handle_t; |
Kojto | 148:fd96258d940d | 162 | |
Kojto | 148:fd96258d940d | 163 | /*! @brief USART transfer callback function. */ |
Kojto | 148:fd96258d940d | 164 | typedef void (*usart_transfer_callback_t)(USART_Type *base, usart_handle_t *handle, status_t status, void *userData); |
Kojto | 148:fd96258d940d | 165 | |
Kojto | 148:fd96258d940d | 166 | /*! @brief USART handle structure. */ |
Kojto | 148:fd96258d940d | 167 | struct _usart_handle |
Kojto | 148:fd96258d940d | 168 | { |
Kojto | 148:fd96258d940d | 169 | uint8_t *volatile txData; /*!< Address of remaining data to send. */ |
Kojto | 148:fd96258d940d | 170 | volatile size_t txDataSize; /*!< Size of the remaining data to send. */ |
Kojto | 148:fd96258d940d | 171 | size_t txDataSizeAll; /*!< Size of the data to send out. */ |
Kojto | 148:fd96258d940d | 172 | uint8_t *volatile rxData; /*!< Address of remaining data to receive. */ |
Kojto | 148:fd96258d940d | 173 | volatile size_t rxDataSize; /*!< Size of the remaining data to receive. */ |
Kojto | 148:fd96258d940d | 174 | size_t rxDataSizeAll; /*!< Size of the data to receive. */ |
Kojto | 148:fd96258d940d | 175 | |
Kojto | 148:fd96258d940d | 176 | uint8_t *rxRingBuffer; /*!< Start address of the receiver ring buffer. */ |
Kojto | 148:fd96258d940d | 177 | size_t rxRingBufferSize; /*!< Size of the ring buffer. */ |
Kojto | 148:fd96258d940d | 178 | volatile uint16_t rxRingBufferHead; /*!< Index for the driver to store received data into ring buffer. */ |
Kojto | 148:fd96258d940d | 179 | volatile uint16_t rxRingBufferTail; /*!< Index for the user to get data from the ring buffer. */ |
Kojto | 148:fd96258d940d | 180 | |
Kojto | 148:fd96258d940d | 181 | usart_transfer_callback_t callback; /*!< Callback function. */ |
Kojto | 148:fd96258d940d | 182 | void *userData; /*!< USART callback function parameter.*/ |
Kojto | 148:fd96258d940d | 183 | |
Kojto | 148:fd96258d940d | 184 | volatile uint8_t txState; /*!< TX transfer state. */ |
Kojto | 148:fd96258d940d | 185 | volatile uint8_t rxState; /*!< RX transfer state */ |
Kojto | 148:fd96258d940d | 186 | |
Kojto | 148:fd96258d940d | 187 | usart_txfifo_watermark_t txWatermark; /*!< txFIFO watermark */ |
Kojto | 148:fd96258d940d | 188 | usart_rxfifo_watermark_t rxWatermark; /*!< rxFIFO watermark */ |
Kojto | 148:fd96258d940d | 189 | }; |
Kojto | 148:fd96258d940d | 190 | |
Kojto | 148:fd96258d940d | 191 | /******************************************************************************* |
Kojto | 148:fd96258d940d | 192 | * API |
Kojto | 148:fd96258d940d | 193 | ******************************************************************************/ |
Kojto | 148:fd96258d940d | 194 | |
Kojto | 148:fd96258d940d | 195 | #if defined(__cplusplus) |
Kojto | 148:fd96258d940d | 196 | extern "C" { |
Kojto | 148:fd96258d940d | 197 | #endif /* _cplusplus */ |
Kojto | 148:fd96258d940d | 198 | |
Kojto | 148:fd96258d940d | 199 | /*! |
Kojto | 148:fd96258d940d | 200 | * @name Initialization and deinitialization |
Kojto | 148:fd96258d940d | 201 | * @{ |
Kojto | 148:fd96258d940d | 202 | */ |
Kojto | 148:fd96258d940d | 203 | |
Kojto | 148:fd96258d940d | 204 | /*! |
Kojto | 148:fd96258d940d | 205 | * @brief Initializes a USART instance with user configuration structure and peripheral clock. |
Kojto | 148:fd96258d940d | 206 | * |
Kojto | 148:fd96258d940d | 207 | * This function configures the USART module with the user-defined settings. The user can configure the configuration |
Kojto | 148:fd96258d940d | 208 | * structure and also get the default configuration by using the USART_GetDefaultConfig() function. |
Kojto | 148:fd96258d940d | 209 | * Example below shows how to use this API to configure USART. |
Kojto | 148:fd96258d940d | 210 | * @code |
Kojto | 148:fd96258d940d | 211 | * usart_config_t usartConfig; |
Kojto | 148:fd96258d940d | 212 | * usartConfig.baudRate_Bps = 115200U; |
Kojto | 148:fd96258d940d | 213 | * usartConfig.parityMode = kUSART_ParityDisabled; |
Kojto | 148:fd96258d940d | 214 | * usartConfig.stopBitCount = kUSART_OneStopBit; |
Kojto | 148:fd96258d940d | 215 | * USART_Init(USART1, &usartConfig, 20000000U); |
Kojto | 148:fd96258d940d | 216 | * @endcode |
Kojto | 148:fd96258d940d | 217 | * |
Kojto | 148:fd96258d940d | 218 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 219 | * @param config Pointer to user-defined configuration structure. |
Kojto | 148:fd96258d940d | 220 | * @param srcClock_Hz USART clock source frequency in HZ. |
Kojto | 148:fd96258d940d | 221 | * @retval kStatus_USART_BaudrateNotSupport Baudrate is not support in current clock source. |
Kojto | 148:fd96258d940d | 222 | * @retval kStatus_InvalidArgument USART base address is not valid |
Kojto | 148:fd96258d940d | 223 | * @retval kStatus_Success Status USART initialize succeed |
Kojto | 148:fd96258d940d | 224 | */ |
Kojto | 148:fd96258d940d | 225 | status_t USART_Init(USART_Type *base, const usart_config_t *config, uint32_t srcClock_Hz); |
Kojto | 148:fd96258d940d | 226 | |
Kojto | 148:fd96258d940d | 227 | /*! |
Kojto | 148:fd96258d940d | 228 | * @brief Deinitializes a USART instance. |
Kojto | 148:fd96258d940d | 229 | * |
Kojto | 148:fd96258d940d | 230 | * This function waits for TX complete, disables TX and RX, and disables the USART clock. |
Kojto | 148:fd96258d940d | 231 | * |
Kojto | 148:fd96258d940d | 232 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 233 | */ |
Kojto | 148:fd96258d940d | 234 | void USART_Deinit(USART_Type *base); |
Kojto | 148:fd96258d940d | 235 | |
Kojto | 148:fd96258d940d | 236 | /*! |
Kojto | 148:fd96258d940d | 237 | * @brief Gets the default configuration structure. |
Kojto | 148:fd96258d940d | 238 | * |
Kojto | 148:fd96258d940d | 239 | * This function initializes the USART configuration structure to a default value. The default |
Kojto | 148:fd96258d940d | 240 | * values are: |
Kojto | 148:fd96258d940d | 241 | * usartConfig->baudRate_Bps = 115200U; |
Kojto | 148:fd96258d940d | 242 | * usartConfig->parityMode = kUSART_ParityDisabled; |
Kojto | 148:fd96258d940d | 243 | * usartConfig->stopBitCount = kUSART_OneStopBit; |
Kojto | 148:fd96258d940d | 244 | * usartConfig->bitCountPerChar = kUSART_8BitsPerChar; |
Kojto | 148:fd96258d940d | 245 | * usartConfig->loopback = false; |
Kojto | 148:fd96258d940d | 246 | * usartConfig->enableTx = false; |
Kojto | 148:fd96258d940d | 247 | * usartConfig->enableRx = false; |
Kojto | 148:fd96258d940d | 248 | * |
Kojto | 148:fd96258d940d | 249 | * @param config Pointer to configuration structure. |
Kojto | 148:fd96258d940d | 250 | */ |
Kojto | 148:fd96258d940d | 251 | void USART_GetDefaultConfig(usart_config_t *config); |
Kojto | 148:fd96258d940d | 252 | |
Kojto | 148:fd96258d940d | 253 | /*! |
Kojto | 148:fd96258d940d | 254 | * @brief Sets the USART instance baud rate. |
Kojto | 148:fd96258d940d | 255 | * |
Kojto | 148:fd96258d940d | 256 | * This function configures the USART module baud rate. This function is used to update |
Kojto | 148:fd96258d940d | 257 | * the USART module baud rate after the USART module is initialized by the USART_Init. |
Kojto | 148:fd96258d940d | 258 | * @code |
Kojto | 148:fd96258d940d | 259 | * USART_SetBaudRate(USART1, 115200U, 20000000U); |
Kojto | 148:fd96258d940d | 260 | * @endcode |
Kojto | 148:fd96258d940d | 261 | * |
Kojto | 148:fd96258d940d | 262 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 263 | * @param baudrate_Bps USART baudrate to be set. |
Kojto | 148:fd96258d940d | 264 | * @param srcClock_Hz USART clock source freqency in HZ. |
Kojto | 148:fd96258d940d | 265 | * @retval kStatus_USART_BaudrateNotSupport Baudrate is not support in current clock source. |
Kojto | 148:fd96258d940d | 266 | * @retval kStatus_Success Set baudrate succeed. |
Kojto | 148:fd96258d940d | 267 | * @retval kStatus_InvalidArgument One or more arguments are invalid. |
Kojto | 148:fd96258d940d | 268 | */ |
Kojto | 148:fd96258d940d | 269 | status_t USART_SetBaudRate(USART_Type *base, uint32_t baudrate_Bps, uint32_t srcClock_Hz); |
Kojto | 148:fd96258d940d | 270 | |
Kojto | 148:fd96258d940d | 271 | /* @} */ |
Kojto | 148:fd96258d940d | 272 | |
Kojto | 148:fd96258d940d | 273 | /*! |
Kojto | 148:fd96258d940d | 274 | * @name Status |
Kojto | 148:fd96258d940d | 275 | * @{ |
Kojto | 148:fd96258d940d | 276 | */ |
Kojto | 148:fd96258d940d | 277 | |
Kojto | 148:fd96258d940d | 278 | /*! |
Kojto | 148:fd96258d940d | 279 | * @brief Get USART status flags. |
Kojto | 148:fd96258d940d | 280 | * |
Kojto | 148:fd96258d940d | 281 | * This function get all USART status flags, the flags are returned as the logical |
Kojto | 148:fd96258d940d | 282 | * OR value of the enumerators @ref _usart_flags. To check a specific status, |
Kojto | 148:fd96258d940d | 283 | * compare the return value with enumerators in @ref _usart_flags. |
Kojto | 148:fd96258d940d | 284 | * For example, to check whether the TX is empty: |
Kojto | 148:fd96258d940d | 285 | * @code |
Kojto | 148:fd96258d940d | 286 | * if (kUSART_TxFifoNotFullFlag & USART_GetStatusFlags(USART1)) |
Kojto | 148:fd96258d940d | 287 | * { |
Kojto | 148:fd96258d940d | 288 | * ... |
Kojto | 148:fd96258d940d | 289 | * } |
Kojto | 148:fd96258d940d | 290 | * @endcode |
Kojto | 148:fd96258d940d | 291 | * |
Kojto | 148:fd96258d940d | 292 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 293 | * @return USART status flags which are ORed by the enumerators in the _usart_flags. |
Kojto | 148:fd96258d940d | 294 | */ |
Kojto | 148:fd96258d940d | 295 | static inline uint32_t USART_GetStatusFlags(USART_Type *base) |
Kojto | 148:fd96258d940d | 296 | { |
Kojto | 148:fd96258d940d | 297 | return base->FIFOSTAT; |
Kojto | 148:fd96258d940d | 298 | } |
Kojto | 148:fd96258d940d | 299 | |
Kojto | 148:fd96258d940d | 300 | /* @} */ |
Kojto | 148:fd96258d940d | 301 | |
Kojto | 148:fd96258d940d | 302 | /*! |
Kojto | 148:fd96258d940d | 303 | * @name Interrupts |
Kojto | 148:fd96258d940d | 304 | * @{ |
Kojto | 148:fd96258d940d | 305 | */ |
Kojto | 148:fd96258d940d | 306 | |
Kojto | 148:fd96258d940d | 307 | /*! |
Kojto | 148:fd96258d940d | 308 | * @brief Enables USART interrupts according to the provided mask. |
Kojto | 148:fd96258d940d | 309 | * |
Kojto | 148:fd96258d940d | 310 | * This function enables the USART interrupts according to the provided mask. The mask |
Kojto | 148:fd96258d940d | 311 | * is a logical OR of enumeration members. See @ref _usart_interrupt_enable. |
Kojto | 148:fd96258d940d | 312 | * For example, to enable TX empty interrupt and RX full interrupt: |
Kojto | 148:fd96258d940d | 313 | * @code |
Kojto | 148:fd96258d940d | 314 | * USART_EnableInterrupts(USART1, kUSART_TxLevelInterruptEnable | kUSART_RxLevelInterruptEnable); |
Kojto | 148:fd96258d940d | 315 | * @endcode |
Kojto | 148:fd96258d940d | 316 | * |
Kojto | 148:fd96258d940d | 317 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 318 | * @param mask The interrupts to enable. Logical OR of @ref _usart_interrupt_enable. |
Kojto | 148:fd96258d940d | 319 | */ |
Kojto | 148:fd96258d940d | 320 | static inline void USART_EnableInterrupts(USART_Type *base, uint32_t mask) |
Kojto | 148:fd96258d940d | 321 | { |
Kojto | 148:fd96258d940d | 322 | base->FIFOINTENSET = mask & 0xF; |
Kojto | 148:fd96258d940d | 323 | } |
Kojto | 148:fd96258d940d | 324 | |
Kojto | 148:fd96258d940d | 325 | /*! |
Kojto | 148:fd96258d940d | 326 | * @brief Disables USART interrupts according to a provided mask. |
Kojto | 148:fd96258d940d | 327 | * |
Kojto | 148:fd96258d940d | 328 | * This function disables the USART interrupts according to a provided mask. The mask |
Kojto | 148:fd96258d940d | 329 | * is a logical OR of enumeration members. See @ref _usart_interrupt_enable. |
Kojto | 148:fd96258d940d | 330 | * This example shows how to disable the TX empty interrupt and RX full interrupt: |
Kojto | 148:fd96258d940d | 331 | * @code |
Kojto | 148:fd96258d940d | 332 | * USART_DisableInterrupts(USART1, kUSART_TxLevelInterruptEnable | kUSART_RxLevelInterruptEnable); |
Kojto | 148:fd96258d940d | 333 | * @endcode |
Kojto | 148:fd96258d940d | 334 | * |
Kojto | 148:fd96258d940d | 335 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 336 | * @param mask The interrupts to disable. Logical OR of @ref _usart_interrupt_enable. |
Kojto | 148:fd96258d940d | 337 | */ |
Kojto | 148:fd96258d940d | 338 | static inline void USART_DisableInterrupts(USART_Type *base, uint32_t mask) |
Kojto | 148:fd96258d940d | 339 | { |
Kojto | 148:fd96258d940d | 340 | base->FIFOINTENSET = ~(mask & 0xF); |
Kojto | 148:fd96258d940d | 341 | } |
Kojto | 148:fd96258d940d | 342 | |
Kojto | 148:fd96258d940d | 343 | /*! |
Kojto | 148:fd96258d940d | 344 | * @brief Enable DMA for Tx |
Kojto | 148:fd96258d940d | 345 | */ |
Kojto | 148:fd96258d940d | 346 | static inline void USART_EnableTxDMA(USART_Type *base, bool enable) |
Kojto | 148:fd96258d940d | 347 | { |
Kojto | 148:fd96258d940d | 348 | if (enable) |
Kojto | 148:fd96258d940d | 349 | { |
Kojto | 148:fd96258d940d | 350 | base->FIFOCFG |= USART_FIFOCFG_DMATX_MASK; |
Kojto | 148:fd96258d940d | 351 | } |
Kojto | 148:fd96258d940d | 352 | else |
Kojto | 148:fd96258d940d | 353 | { |
Kojto | 148:fd96258d940d | 354 | base->FIFOCFG &= ~(USART_FIFOCFG_DMATX_MASK); |
Kojto | 148:fd96258d940d | 355 | } |
Kojto | 148:fd96258d940d | 356 | } |
Kojto | 148:fd96258d940d | 357 | |
Kojto | 148:fd96258d940d | 358 | /*! |
Kojto | 148:fd96258d940d | 359 | * @brief Enable DMA for Rx |
Kojto | 148:fd96258d940d | 360 | */ |
Kojto | 148:fd96258d940d | 361 | static inline void USART_EnableRxDMA(USART_Type *base, bool enable) |
Kojto | 148:fd96258d940d | 362 | { |
Kojto | 148:fd96258d940d | 363 | if (enable) |
Kojto | 148:fd96258d940d | 364 | { |
Kojto | 148:fd96258d940d | 365 | base->FIFOCFG |= USART_FIFOCFG_DMARX_MASK; |
Kojto | 148:fd96258d940d | 366 | } |
Kojto | 148:fd96258d940d | 367 | else |
Kojto | 148:fd96258d940d | 368 | { |
Kojto | 148:fd96258d940d | 369 | base->FIFOCFG &= ~(USART_FIFOCFG_DMARX_MASK); |
Kojto | 148:fd96258d940d | 370 | } |
Kojto | 148:fd96258d940d | 371 | } |
Kojto | 148:fd96258d940d | 372 | |
Kojto | 148:fd96258d940d | 373 | /* @} */ |
Kojto | 148:fd96258d940d | 374 | |
Kojto | 148:fd96258d940d | 375 | /*! |
Kojto | 148:fd96258d940d | 376 | * @name Bus Operations |
Kojto | 148:fd96258d940d | 377 | * @{ |
Kojto | 148:fd96258d940d | 378 | */ |
Kojto | 148:fd96258d940d | 379 | |
Kojto | 148:fd96258d940d | 380 | /*! |
Kojto | 148:fd96258d940d | 381 | * @brief Writes to the FIFOWR register. |
Kojto | 148:fd96258d940d | 382 | * |
Kojto | 148:fd96258d940d | 383 | * This function writes data to the txFIFO directly. The upper layer must ensure |
Kojto | 148:fd96258d940d | 384 | * that txFIFO has space for data to write before calling this function. |
Kojto | 148:fd96258d940d | 385 | * |
Kojto | 148:fd96258d940d | 386 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 387 | * @param data The byte to write. |
Kojto | 148:fd96258d940d | 388 | */ |
Kojto | 148:fd96258d940d | 389 | static inline void USART_WriteByte(USART_Type *base, uint8_t data) |
Kojto | 148:fd96258d940d | 390 | { |
Kojto | 148:fd96258d940d | 391 | base->FIFOWR = data; |
Kojto | 148:fd96258d940d | 392 | } |
Kojto | 148:fd96258d940d | 393 | |
Kojto | 148:fd96258d940d | 394 | /*! |
Kojto | 148:fd96258d940d | 395 | * @brief Reads the FIFORD register directly. |
Kojto | 148:fd96258d940d | 396 | * |
Kojto | 148:fd96258d940d | 397 | * This function reads data from the rxFIFO directly. The upper layer must |
Kojto | 148:fd96258d940d | 398 | * ensure that the rxFIFO is not empty before calling this function. |
Kojto | 148:fd96258d940d | 399 | * |
Kojto | 148:fd96258d940d | 400 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 401 | * @return The byte read from USART data register. |
Kojto | 148:fd96258d940d | 402 | */ |
Kojto | 148:fd96258d940d | 403 | static inline uint8_t USART_ReadByte(USART_Type *base) |
Kojto | 148:fd96258d940d | 404 | { |
Kojto | 148:fd96258d940d | 405 | return base->FIFORD; |
Kojto | 148:fd96258d940d | 406 | } |
Kojto | 148:fd96258d940d | 407 | |
Kojto | 148:fd96258d940d | 408 | /*! |
Kojto | 148:fd96258d940d | 409 | * @brief Writes to the TX register using a blocking method. |
Kojto | 148:fd96258d940d | 410 | * |
Kojto | 148:fd96258d940d | 411 | * This function polls the TX register, waits for the TX register to be empty or for the TX FIFO |
Kojto | 148:fd96258d940d | 412 | * to have room and writes data to the TX buffer. |
Kojto | 148:fd96258d940d | 413 | * |
Kojto | 148:fd96258d940d | 414 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 415 | * @param data Start address of the data to write. |
Kojto | 148:fd96258d940d | 416 | * @param length Size of the data to write. |
Kojto | 148:fd96258d940d | 417 | */ |
Kojto | 148:fd96258d940d | 418 | void USART_WriteBlocking(USART_Type *base, const uint8_t *data, size_t length); |
Kojto | 148:fd96258d940d | 419 | |
Kojto | 148:fd96258d940d | 420 | /*! |
Kojto | 148:fd96258d940d | 421 | * @brief Read RX data register using a blocking method. |
Kojto | 148:fd96258d940d | 422 | * |
Kojto | 148:fd96258d940d | 423 | * This function polls the RX register, waits for the RX register to be full or for RX FIFO to |
Kojto | 148:fd96258d940d | 424 | * have data and read data from the TX register. |
Kojto | 148:fd96258d940d | 425 | * |
Kojto | 148:fd96258d940d | 426 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 427 | * @param data Start address of the buffer to store the received data. |
Kojto | 148:fd96258d940d | 428 | * @param length Size of the buffer. |
Kojto | 148:fd96258d940d | 429 | * @retval kStatus_USART_FramingError Receiver overrun happened while receiving data. |
Kojto | 148:fd96258d940d | 430 | * @retval kStatus_USART_ParityError Noise error happened while receiving data. |
Kojto | 148:fd96258d940d | 431 | * @retval kStatus_USART_NoiseError Framing error happened while receiving data. |
Kojto | 148:fd96258d940d | 432 | * @retval kStatus_USART_RxError Overflow or underflow rxFIFO happened. |
Kojto | 148:fd96258d940d | 433 | * @retval kStatus_Success Successfully received all data. |
Kojto | 148:fd96258d940d | 434 | */ |
Kojto | 148:fd96258d940d | 435 | status_t USART_ReadBlocking(USART_Type *base, uint8_t *data, size_t length); |
Kojto | 148:fd96258d940d | 436 | |
Kojto | 148:fd96258d940d | 437 | /* @} */ |
Kojto | 148:fd96258d940d | 438 | |
Kojto | 148:fd96258d940d | 439 | /*! |
Kojto | 148:fd96258d940d | 440 | * @name Transactional |
Kojto | 148:fd96258d940d | 441 | * @{ |
Kojto | 148:fd96258d940d | 442 | */ |
Kojto | 148:fd96258d940d | 443 | |
Kojto | 148:fd96258d940d | 444 | /*! |
Kojto | 148:fd96258d940d | 445 | * @brief Initializes the USART handle. |
Kojto | 148:fd96258d940d | 446 | * |
Kojto | 148:fd96258d940d | 447 | * This function initializes the USART handle which can be used for other USART |
Kojto | 148:fd96258d940d | 448 | * transactional APIs. Usually, for a specified USART instance, |
Kojto | 148:fd96258d940d | 449 | * call this API once to get the initialized handle. |
Kojto | 148:fd96258d940d | 450 | * |
Kojto | 148:fd96258d940d | 451 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 452 | * @param handle USART handle pointer. |
Kojto | 148:fd96258d940d | 453 | * @param callback The callback function. |
Kojto | 148:fd96258d940d | 454 | * @param userData The parameter of the callback function. |
Kojto | 148:fd96258d940d | 455 | */ |
Kojto | 148:fd96258d940d | 456 | status_t USART_TransferCreateHandle(USART_Type *base, |
Kojto | 148:fd96258d940d | 457 | usart_handle_t *handle, |
Kojto | 148:fd96258d940d | 458 | usart_transfer_callback_t callback, |
Kojto | 148:fd96258d940d | 459 | void *userData); |
Kojto | 148:fd96258d940d | 460 | |
Kojto | 148:fd96258d940d | 461 | /*! |
Kojto | 148:fd96258d940d | 462 | * @brief Transmits a buffer of data using the interrupt method. |
Kojto | 148:fd96258d940d | 463 | * |
Kojto | 148:fd96258d940d | 464 | * This function sends data using an interrupt method. This is a non-blocking function, which |
Kojto | 148:fd96258d940d | 465 | * returns directly without waiting for all data to be written to the TX register. When |
Kojto | 148:fd96258d940d | 466 | * all data is written to the TX register in the IRQ handler, the USART driver calls the callback |
Kojto | 148:fd96258d940d | 467 | * function and passes the @ref kStatus_USART_TxIdle as status parameter. |
Kojto | 148:fd96258d940d | 468 | * |
Kojto | 148:fd96258d940d | 469 | * @note The kStatus_USART_TxIdle is passed to the upper layer when all data is written |
Kojto | 148:fd96258d940d | 470 | * to the TX register. However it does not ensure that all data are sent out. Before disabling the TX, |
Kojto | 148:fd96258d940d | 471 | * check the kUSART_TransmissionCompleteFlag to ensure that the TX is finished. |
Kojto | 148:fd96258d940d | 472 | * |
Kojto | 148:fd96258d940d | 473 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 474 | * @param handle USART handle pointer. |
Kojto | 148:fd96258d940d | 475 | * @param xfer USART transfer structure. See #usart_transfer_t. |
Kojto | 148:fd96258d940d | 476 | * @retval kStatus_Success Successfully start the data transmission. |
Kojto | 148:fd96258d940d | 477 | * @retval kStatus_USART_TxBusy Previous transmission still not finished, data not all written to TX register yet. |
Kojto | 148:fd96258d940d | 478 | * @retval kStatus_InvalidArgument Invalid argument. |
Kojto | 148:fd96258d940d | 479 | */ |
Kojto | 148:fd96258d940d | 480 | status_t USART_TransferSendNonBlocking(USART_Type *base, usart_handle_t *handle, usart_transfer_t *xfer); |
Kojto | 148:fd96258d940d | 481 | |
Kojto | 148:fd96258d940d | 482 | /*! |
Kojto | 148:fd96258d940d | 483 | * @brief Sets up the RX ring buffer. |
Kojto | 148:fd96258d940d | 484 | * |
Kojto | 148:fd96258d940d | 485 | * This function sets up the RX ring buffer to a specific USART handle. |
Kojto | 148:fd96258d940d | 486 | * |
Kojto | 148:fd96258d940d | 487 | * When the RX ring buffer is used, data received are stored into the ring buffer even when the |
Kojto | 148:fd96258d940d | 488 | * user doesn't call the USART_TransferReceiveNonBlocking() API. If there is already data received |
Kojto | 148:fd96258d940d | 489 | * in the ring buffer, the user can get the received data from the ring buffer directly. |
Kojto | 148:fd96258d940d | 490 | * |
Kojto | 148:fd96258d940d | 491 | * @note When using the RX ring buffer, one byte is reserved for internal use. In other |
Kojto | 148:fd96258d940d | 492 | * words, if @p ringBufferSize is 32, then only 31 bytes are used for saving data. |
Kojto | 148:fd96258d940d | 493 | * |
Kojto | 148:fd96258d940d | 494 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 495 | * @param handle USART handle pointer. |
Kojto | 148:fd96258d940d | 496 | * @param ringBuffer Start address of the ring buffer for background receiving. Pass NULL to disable the ring buffer. |
Kojto | 148:fd96258d940d | 497 | * @param ringBufferSize size of the ring buffer. |
Kojto | 148:fd96258d940d | 498 | */ |
Kojto | 148:fd96258d940d | 499 | void USART_TransferStartRingBuffer(USART_Type *base, |
Kojto | 148:fd96258d940d | 500 | usart_handle_t *handle, |
Kojto | 148:fd96258d940d | 501 | uint8_t *ringBuffer, |
Kojto | 148:fd96258d940d | 502 | size_t ringBufferSize); |
Kojto | 148:fd96258d940d | 503 | |
Kojto | 148:fd96258d940d | 504 | /*! |
Kojto | 148:fd96258d940d | 505 | * @brief Aborts the background transfer and uninstalls the ring buffer. |
Kojto | 148:fd96258d940d | 506 | * |
Kojto | 148:fd96258d940d | 507 | * This function aborts the background transfer and uninstalls the ring buffer. |
Kojto | 148:fd96258d940d | 508 | * |
Kojto | 148:fd96258d940d | 509 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 510 | * @param handle USART handle pointer. |
Kojto | 148:fd96258d940d | 511 | */ |
Kojto | 148:fd96258d940d | 512 | void USART_TransferStopRingBuffer(USART_Type *base, usart_handle_t *handle); |
Kojto | 148:fd96258d940d | 513 | |
Kojto | 148:fd96258d940d | 514 | /*! |
Kojto | 148:fd96258d940d | 515 | * @brief Aborts the interrupt-driven data transmit. |
Kojto | 148:fd96258d940d | 516 | * |
Kojto | 148:fd96258d940d | 517 | * This function aborts the interrupt driven data sending. The user can get the remainBtyes to find out |
Kojto | 148:fd96258d940d | 518 | * how many bytes are still not sent out. |
Kojto | 148:fd96258d940d | 519 | * |
Kojto | 148:fd96258d940d | 520 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 521 | * @param handle USART handle pointer. |
Kojto | 148:fd96258d940d | 522 | */ |
Kojto | 148:fd96258d940d | 523 | void USART_TransferAbortSend(USART_Type *base, usart_handle_t *handle); |
Kojto | 148:fd96258d940d | 524 | |
Kojto | 148:fd96258d940d | 525 | /*! |
Kojto | 148:fd96258d940d | 526 | * @brief Get the number of bytes that have been written to USART TX register. |
Kojto | 148:fd96258d940d | 527 | * |
Kojto | 148:fd96258d940d | 528 | * This function gets the number of bytes that have been written to USART TX |
Kojto | 148:fd96258d940d | 529 | * register by interrupt method. |
Kojto | 148:fd96258d940d | 530 | * |
Kojto | 148:fd96258d940d | 531 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 532 | * @param handle USART handle pointer. |
Kojto | 148:fd96258d940d | 533 | * @param count Send bytes count. |
Kojto | 148:fd96258d940d | 534 | * @retval kStatus_NoTransferInProgress No send in progress. |
Kojto | 148:fd96258d940d | 535 | * @retval kStatus_InvalidArgument Parameter is invalid. |
Kojto | 148:fd96258d940d | 536 | * @retval kStatus_Success Get successfully through the parameter \p count; |
Kojto | 148:fd96258d940d | 537 | */ |
Kojto | 148:fd96258d940d | 538 | status_t USART_TransferGetSendCount(USART_Type *base, usart_handle_t *handle, uint32_t *count); |
Kojto | 148:fd96258d940d | 539 | |
Kojto | 148:fd96258d940d | 540 | /*! |
Kojto | 148:fd96258d940d | 541 | * @brief Receives a buffer of data using an interrupt method. |
Kojto | 148:fd96258d940d | 542 | * |
Kojto | 148:fd96258d940d | 543 | * This function receives data using an interrupt method. This is a non-blocking function, which |
Kojto | 148:fd96258d940d | 544 | * returns without waiting for all data to be received. |
Kojto | 148:fd96258d940d | 545 | * If the RX ring buffer is used and not empty, the data in the ring buffer is copied and |
Kojto | 148:fd96258d940d | 546 | * the parameter @p receivedBytes shows how many bytes are copied from the ring buffer. |
Kojto | 148:fd96258d940d | 547 | * After copying, if the data in the ring buffer is not enough to read, the receive |
Kojto | 148:fd96258d940d | 548 | * request is saved by the USART driver. When the new data arrives, the receive request |
Kojto | 148:fd96258d940d | 549 | * is serviced first. When all data is received, the USART driver notifies the upper layer |
Kojto | 148:fd96258d940d | 550 | * through a callback function and passes the status parameter @ref kStatus_USART_RxIdle. |
Kojto | 148:fd96258d940d | 551 | * For example, the upper layer needs 10 bytes but there are only 5 bytes in the ring buffer. |
Kojto | 148:fd96258d940d | 552 | * The 5 bytes are copied to the xfer->data and this function returns with the |
Kojto | 148:fd96258d940d | 553 | * parameter @p receivedBytes set to 5. For the left 5 bytes, newly arrived data is |
Kojto | 148:fd96258d940d | 554 | * saved from the xfer->data[5]. When 5 bytes are received, the USART driver notifies the upper layer. |
Kojto | 148:fd96258d940d | 555 | * If the RX ring buffer is not enabled, this function enables the RX and RX interrupt |
Kojto | 148:fd96258d940d | 556 | * to receive data to the xfer->data. When all data is received, the upper layer is notified. |
Kojto | 148:fd96258d940d | 557 | * |
Kojto | 148:fd96258d940d | 558 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 559 | * @param handle USART handle pointer. |
Kojto | 148:fd96258d940d | 560 | * @param xfer USART transfer structure, see #usart_transfer_t. |
Kojto | 148:fd96258d940d | 561 | * @param receivedBytes Bytes received from the ring buffer directly. |
Kojto | 148:fd96258d940d | 562 | * @retval kStatus_Success Successfully queue the transfer into transmit queue. |
Kojto | 148:fd96258d940d | 563 | * @retval kStatus_USART_RxBusy Previous receive request is not finished. |
Kojto | 148:fd96258d940d | 564 | * @retval kStatus_InvalidArgument Invalid argument. |
Kojto | 148:fd96258d940d | 565 | */ |
Kojto | 148:fd96258d940d | 566 | status_t USART_TransferReceiveNonBlocking(USART_Type *base, |
Kojto | 148:fd96258d940d | 567 | usart_handle_t *handle, |
Kojto | 148:fd96258d940d | 568 | usart_transfer_t *xfer, |
Kojto | 148:fd96258d940d | 569 | size_t *receivedBytes); |
Kojto | 148:fd96258d940d | 570 | |
Kojto | 148:fd96258d940d | 571 | /*! |
Kojto | 148:fd96258d940d | 572 | * @brief Aborts the interrupt-driven data receiving. |
Kojto | 148:fd96258d940d | 573 | * |
Kojto | 148:fd96258d940d | 574 | * This function aborts the interrupt-driven data receiving. The user can get the remainBytes to find out |
Kojto | 148:fd96258d940d | 575 | * how many bytes not received yet. |
Kojto | 148:fd96258d940d | 576 | * |
Kojto | 148:fd96258d940d | 577 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 578 | * @param handle USART handle pointer. |
Kojto | 148:fd96258d940d | 579 | */ |
Kojto | 148:fd96258d940d | 580 | void USART_TransferAbortReceive(USART_Type *base, usart_handle_t *handle); |
Kojto | 148:fd96258d940d | 581 | |
Kojto | 148:fd96258d940d | 582 | /*! |
Kojto | 148:fd96258d940d | 583 | * @brief Get the number of bytes that have been received. |
Kojto | 148:fd96258d940d | 584 | * |
Kojto | 148:fd96258d940d | 585 | * This function gets the number of bytes that have been received. |
Kojto | 148:fd96258d940d | 586 | * |
Kojto | 148:fd96258d940d | 587 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 588 | * @param handle USART handle pointer. |
Kojto | 148:fd96258d940d | 589 | * @param count Receive bytes count. |
Kojto | 148:fd96258d940d | 590 | * @retval kStatus_NoTransferInProgress No receive in progress. |
Kojto | 148:fd96258d940d | 591 | * @retval kStatus_InvalidArgument Parameter is invalid. |
Kojto | 148:fd96258d940d | 592 | * @retval kStatus_Success Get successfully through the parameter \p count; |
Kojto | 148:fd96258d940d | 593 | */ |
Kojto | 148:fd96258d940d | 594 | status_t USART_TransferGetReceiveCount(USART_Type *base, usart_handle_t *handle, uint32_t *count); |
Kojto | 148:fd96258d940d | 595 | |
Kojto | 148:fd96258d940d | 596 | /*! |
Kojto | 148:fd96258d940d | 597 | * @brief USART IRQ handle function. |
Kojto | 148:fd96258d940d | 598 | * |
Kojto | 148:fd96258d940d | 599 | * This function handles the USART transmit and receive IRQ request. |
Kojto | 148:fd96258d940d | 600 | * |
Kojto | 148:fd96258d940d | 601 | * @param base USART peripheral base address. |
Kojto | 148:fd96258d940d | 602 | * @param handle USART handle pointer. |
Kojto | 148:fd96258d940d | 603 | */ |
Kojto | 148:fd96258d940d | 604 | void USART_TransferHandleIRQ(USART_Type *base, usart_handle_t *handle); |
Kojto | 148:fd96258d940d | 605 | |
Kojto | 148:fd96258d940d | 606 | /* @} */ |
Kojto | 148:fd96258d940d | 607 | |
Kojto | 148:fd96258d940d | 608 | #if defined(__cplusplus) |
Kojto | 148:fd96258d940d | 609 | } |
Kojto | 148:fd96258d940d | 610 | #endif |
Kojto | 148:fd96258d940d | 611 | |
Kojto | 148:fd96258d940d | 612 | /*! @}*/ |
Kojto | 148:fd96258d940d | 613 | |
Kojto | 148:fd96258d940d | 614 | #endif /* _FSL_USART_H_ */ |