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.

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?

UserRevisionLine numberNew contents of line
AnnaBridge 167:84c0a372a020 1 /**
AnnaBridge 167:84c0a372a020 2 * @file
AnnaBridge 167:84c0a372a020 3 * @brief UART data types, definitions and function prototypes.
AnnaBridge 167:84c0a372a020 4 */
AnnaBridge 167:84c0a372a020 5 /* ****************************************************************************
AnnaBridge 167:84c0a372a020 6 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
AnnaBridge 167:84c0a372a020 7 *
AnnaBridge 167:84c0a372a020 8 * Permission is hereby granted, free of charge, to any person obtaining a
AnnaBridge 167:84c0a372a020 9 * copy of this software and associated documentation files (the "Software"),
AnnaBridge 167:84c0a372a020 10 * to deal in the Software without restriction, including without limitation
AnnaBridge 167:84c0a372a020 11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
AnnaBridge 167:84c0a372a020 12 * and/or sell copies of the Software, and to permit persons to whom the
AnnaBridge 167:84c0a372a020 13 * Software is furnished to do so, subject to the following conditions:
AnnaBridge 167:84c0a372a020 14 *
AnnaBridge 167:84c0a372a020 15 * The above copyright notice and this permission notice shall be included
AnnaBridge 167:84c0a372a020 16 * in all copies or substantial portions of the Software.
AnnaBridge 167:84c0a372a020 17 *
AnnaBridge 167:84c0a372a020 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
AnnaBridge 167:84c0a372a020 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
AnnaBridge 167:84c0a372a020 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
AnnaBridge 167:84c0a372a020 21 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
AnnaBridge 167:84c0a372a020 22 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
AnnaBridge 167:84c0a372a020 23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
AnnaBridge 167:84c0a372a020 24 * OTHER DEALINGS IN THE SOFTWARE.
AnnaBridge 167:84c0a372a020 25 *
AnnaBridge 167:84c0a372a020 26 * Except as contained in this notice, the name of Maxim Integrated
AnnaBridge 167:84c0a372a020 27 * Products, Inc. shall not be used except as stated in the Maxim Integrated
AnnaBridge 167:84c0a372a020 28 * Products, Inc. Branding Policy.
AnnaBridge 167:84c0a372a020 29 *
AnnaBridge 167:84c0a372a020 30 * The mere transfer of this software does not imply any licenses
AnnaBridge 167:84c0a372a020 31 * of trade secrets, proprietary technology, copyrights, patents,
AnnaBridge 167:84c0a372a020 32 * trademarks, maskwork rights, or any other form of intellectual
AnnaBridge 167:84c0a372a020 33 * property whatsoever. Maxim Integrated Products, Inc. retains all
AnnaBridge 167:84c0a372a020 34 * ownership rights.
AnnaBridge 167:84c0a372a020 35 *
AnnaBridge 167:84c0a372a020 36 * $Date: 2017-02-27 18:18:01 -0600 (Mon, 27 Feb 2017) $
AnnaBridge 167:84c0a372a020 37 * $Revision: 26714 $
AnnaBridge 167:84c0a372a020 38 *
AnnaBridge 167:84c0a372a020 39 **************************************************************************** */
AnnaBridge 167:84c0a372a020 40
AnnaBridge 167:84c0a372a020 41 /* **** Includes **** */
AnnaBridge 167:84c0a372a020 42 #include "mxc_config.h"
AnnaBridge 167:84c0a372a020 43 #include "mxc_sys.h"
AnnaBridge 167:84c0a372a020 44 #include "uart_regs.h"
AnnaBridge 167:84c0a372a020 45
AnnaBridge 167:84c0a372a020 46 /* Define to prevent redundant inclusion */
AnnaBridge 167:84c0a372a020 47 #ifndef _UART_H_
AnnaBridge 167:84c0a372a020 48 #define _UART_H_
AnnaBridge 167:84c0a372a020 49 /**
AnnaBridge 167:84c0a372a020 50 * @ingroup periphlibs
AnnaBridge 167:84c0a372a020 51 * @defgroup uart_top UART API and Registers
AnnaBridge 167:84c0a372a020 52 * @{
AnnaBridge 167:84c0a372a020 53 */
AnnaBridge 167:84c0a372a020 54 #ifdef __cplusplus
AnnaBridge 167:84c0a372a020 55 extern "C" {
AnnaBridge 167:84c0a372a020 56 #endif
AnnaBridge 167:84c0a372a020 57
AnnaBridge 167:84c0a372a020 58
AnnaBridge 167:84c0a372a020 59
AnnaBridge 167:84c0a372a020 60 /* **** Definitions **** */
AnnaBridge 167:84c0a372a020 61
AnnaBridge 167:84c0a372a020 62 /**
AnnaBridge 167:84c0a372a020 63 * Enumeration type for defining the number of bits per character.
AnnaBridge 167:84c0a372a020 64 */
AnnaBridge 167:84c0a372a020 65 typedef enum {
AnnaBridge 167:84c0a372a020 66 UART_DATA_SIZE_5_BITS = MXC_V_UART_CTRL_DATA_SIZE_5_BITS, /**< 5 Data bits per UART character. */
AnnaBridge 167:84c0a372a020 67 UART_DATA_SIZE_6_BITS = MXC_V_UART_CTRL_DATA_SIZE_6_BITS, /**< 6 Data bits per UART character. */
AnnaBridge 167:84c0a372a020 68 UART_DATA_SIZE_7_BITS = MXC_V_UART_CTRL_DATA_SIZE_7_BITS, /**< 7 Data bits per UART character. */
AnnaBridge 167:84c0a372a020 69 UART_DATA_SIZE_8_BITS = MXC_V_UART_CTRL_DATA_SIZE_8_BITS /**< 8 Data bits per UART character. */
AnnaBridge 167:84c0a372a020 70 }
AnnaBridge 167:84c0a372a020 71 uart_data_size_t;
AnnaBridge 167:84c0a372a020 72
AnnaBridge 167:84c0a372a020 73 /**
AnnaBridge 167:84c0a372a020 74 * Enumeration type for selecting Parity and type.
AnnaBridge 167:84c0a372a020 75 */
AnnaBridge 167:84c0a372a020 76 typedef enum {
AnnaBridge 167:84c0a372a020 77 UART_PARITY_DISABLE = MXC_V_UART_CTRL_PARITY_DISABLE, /**< Parity disabled. */
AnnaBridge 167:84c0a372a020 78 UART_PARITY_ODD = MXC_V_UART_CTRL_PARITY_ODD, /**< Odd parity. */
AnnaBridge 167:84c0a372a020 79 UART_PARITY_EVEN = MXC_V_UART_CTRL_PARITY_EVEN, /**< Even parity. */
AnnaBridge 167:84c0a372a020 80 UART_PARITY_MARK = MXC_V_UART_CTRL_PARITY_MARK /**< Mark parity. */
AnnaBridge 167:84c0a372a020 81 } uart_parity_t;
AnnaBridge 167:84c0a372a020 82
AnnaBridge 167:84c0a372a020 83 /**
AnnaBridge 167:84c0a372a020 84 * Configuration structure type for a UART port.
AnnaBridge 167:84c0a372a020 85 */
AnnaBridge 167:84c0a372a020 86 typedef struct {
AnnaBridge 167:84c0a372a020 87 uint8_t extra_stop; /**< @c 0 for one stop bit, @c 1 for two stop bits*/
AnnaBridge 167:84c0a372a020 88 uint8_t cts; /**< CTS Enable/Disable, @c 1 to enable CTS, @c 0 to disable CTS.*/
AnnaBridge 167:84c0a372a020 89 uint8_t rts; /**< @c 1 to enable RTS, @c 0 to disable RTS. */
AnnaBridge 167:84c0a372a020 90 uint32_t baud; /**< Baud rate in Hz. */
AnnaBridge 167:84c0a372a020 91 uart_data_size_t size; /**< Set the number of bits per character, see uart_data_size_t. */
AnnaBridge 167:84c0a372a020 92 uart_parity_t parity; /**< Set the parity, see uart_parity_t for supported parity types. */
AnnaBridge 167:84c0a372a020 93 } uart_cfg_t;
AnnaBridge 167:84c0a372a020 94 /** @} */
AnnaBridge 167:84c0a372a020 95 /**
AnnaBridge 167:84c0a372a020 96 * @ingroup uart_top
AnnaBridge 167:84c0a372a020 97 * @defgroup uart_async UART Asynchronous Functions
AnnaBridge 167:84c0a372a020 98 * @{
AnnaBridge 167:84c0a372a020 99 */
AnnaBridge 167:84c0a372a020 100
AnnaBridge 167:84c0a372a020 101 /**
AnnaBridge 167:84c0a372a020 102 * Structure type for a UART asynchronous transaction request.
AnnaBridge 167:84c0a372a020 103 */
AnnaBridge 167:84c0a372a020 104 typedef struct uart_req uart_req_t;
AnnaBridge 167:84c0a372a020 105
AnnaBridge 167:84c0a372a020 106 /**
AnnaBridge 167:84c0a372a020 107 * @brief Type alias for a UART callback function used for asynchronous operations.
AnnaBridge 167:84c0a372a020 108 * @details
AnnaBridge 167:84c0a372a020 109 * Type alias \c uart_async_callback for a callback function with signature of:
AnnaBridge 167:84c0a372a020 110 * @code{.c}
AnnaBridge 167:84c0a372a020 111 * void callback_fn(uart_req_t *request , int error_code);
AnnaBridge 167:84c0a372a020 112 * @endcode
AnnaBridge 167:84c0a372a020 113 * @p uart_req_t * Pointer to the transaction request.
AnnaBridge 167:84c0a372a020 114 * @p error_code Return code for the UART request. See @ref MXC_Error_Codes for possible codes.
AnnaBridge 167:84c0a372a020 115 */
AnnaBridge 167:84c0a372a020 116 typedef void (*uart_async_callback)(uart_req_t*, int);
AnnaBridge 167:84c0a372a020 117
AnnaBridge 167:84c0a372a020 118 /**
AnnaBridge 167:84c0a372a020 119 * Structure for a UART asynchronous transaction request.
AnnaBridge 167:84c0a372a020 120 * @note When using this structure for an asynchronous operation, the
AnnaBridge 167:84c0a372a020 121 * structure must remain allocated until the callback is completed.
AnnaBridge 167:84c0a372a020 122 */
AnnaBridge 167:84c0a372a020 123 struct uart_req {
AnnaBridge 167:84c0a372a020 124 uint8_t *data; /**< Data buffer for characters. */
AnnaBridge 167:84c0a372a020 125 unsigned len; /**< Length of characters in data to send or receive. */
AnnaBridge 167:84c0a372a020 126 unsigned num; /**< Number of characters actually sent or received. */
AnnaBridge 167:84c0a372a020 127 uart_async_callback callback; /**< Pointer to a callback function of type uart_async_callback() */
AnnaBridge 167:84c0a372a020 128 };
AnnaBridge 167:84c0a372a020 129
AnnaBridge 167:84c0a372a020 130 /** @} */
AnnaBridge 167:84c0a372a020 131 /* **** Globals **** */
AnnaBridge 167:84c0a372a020 132
AnnaBridge 167:84c0a372a020 133 /* **** Function Prototypes **** */
AnnaBridge 167:84c0a372a020 134 /**
AnnaBridge 167:84c0a372a020 135 * @ingroup uart_top
AnnaBridge 167:84c0a372a020 136 * @{
AnnaBridge 167:84c0a372a020 137 */
AnnaBridge 167:84c0a372a020 138 /**
AnnaBridge 167:84c0a372a020 139 * @brief Initialize and enable UART module.
AnnaBridge 167:84c0a372a020 140 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 141 * @param cfg Pointer to UART configuration.
AnnaBridge 167:84c0a372a020 142 * @param sys_cfg Pointer to system configuration object
AnnaBridge 167:84c0a372a020 143 * @returns #E_NO_ERROR UART initialized successfully, @ref MXC_Error_Codes "error" if
AnnaBridge 167:84c0a372a020 144 * unsuccessful.
AnnaBridge 167:84c0a372a020 145 */
AnnaBridge 167:84c0a372a020 146 int UART_Init(mxc_uart_regs_t *uart, const uart_cfg_t *cfg, const sys_cfg_uart_t *sys_cfg);
AnnaBridge 167:84c0a372a020 147
AnnaBridge 167:84c0a372a020 148 /**
AnnaBridge 167:84c0a372a020 149 * @brief Shutdown UART module.
AnnaBridge 167:84c0a372a020 150 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 151 * @returns #E_NO_ERROR UART shutdown successfully, @ref MXC_Error_Codes "error" if
AnnaBridge 167:84c0a372a020 152 * unsuccessful.
AnnaBridge 167:84c0a372a020 153 */
AnnaBridge 167:84c0a372a020 154 int UART_Shutdown(mxc_uart_regs_t *uart);
AnnaBridge 167:84c0a372a020 155 /**@}*/
AnnaBridge 167:84c0a372a020 156 /**
AnnaBridge 167:84c0a372a020 157 * @ingroup uart_top
AnnaBridge 167:84c0a372a020 158 * @defgroup uart_sync UART Synchronous Functions
AnnaBridge 167:84c0a372a020 159 * @brief Synchronous/blocking Functions for the UART peripheral.
AnnaBridge 167:84c0a372a020 160 * @{
AnnaBridge 167:84c0a372a020 161 */
AnnaBridge 167:84c0a372a020 162
AnnaBridge 167:84c0a372a020 163 /**
AnnaBridge 167:84c0a372a020 164 * @brief Write UART data. This function blocks until the write transaction
AnnaBridge 167:84c0a372a020 165 * is complete.
AnnaBridge 167:84c0a372a020 166 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 167 * @param data Pointer to buffer for write data.
AnnaBridge 167:84c0a372a020 168 * @param len Number of bytes to write.
AnnaBridge 167:84c0a372a020 169 * @note Will return once data has been put into FIFO, not necessarily
AnnaBridge 167:84c0a372a020 170 * transmitted.
AnnaBridge 167:84c0a372a020 171 * @return Number of bytes written if successful, error if unsuccessful.
AnnaBridge 167:84c0a372a020 172 */
AnnaBridge 167:84c0a372a020 173 int UART_Write(mxc_uart_regs_t *uart, uint8_t* data, int len);
AnnaBridge 167:84c0a372a020 174
AnnaBridge 167:84c0a372a020 175 /**
AnnaBridge 167:84c0a372a020 176 * @brief Read UART data, <em>blocking</em> until transaction is complete.
AnnaBridge 167:84c0a372a020 177 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 178 * @param data Pointer to buffer to save the data read.
AnnaBridge 167:84c0a372a020 179 * @param len Number of bytes to read.
AnnaBridge 167:84c0a372a020 180 * @param num Pointer to store the number of bytes actually read, pass NULL if not needed.
AnnaBridge 167:84c0a372a020 181 *
AnnaBridge 167:84c0a372a020 182 * @return Number of bytes read, @ref MXC_Error_Codes "error" if
AnnaBridge 167:84c0a372a020 183 * unsuccessful.
AnnaBridge 167:84c0a372a020 184 */
AnnaBridge 167:84c0a372a020 185 int UART_Read(mxc_uart_regs_t *uart, uint8_t* data, int len, int *num);
AnnaBridge 167:84c0a372a020 186 /** @} */
AnnaBridge 167:84c0a372a020 187 /**
AnnaBridge 167:84c0a372a020 188 * @ingroup uart_async
AnnaBridge 167:84c0a372a020 189 * @{
AnnaBridge 167:84c0a372a020 190 */
AnnaBridge 167:84c0a372a020 191 /**
AnnaBridge 167:84c0a372a020 192 * @brief Asynchronously write/transmit data to the UART.
AnnaBridge 167:84c0a372a020 193 *
AnnaBridge 167:84c0a372a020 194 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 195 * @param req Request for a UART transaction.
AnnaBridge 167:84c0a372a020 196 * @note Request struct must remain allocated until callback.
AnnaBridge 167:84c0a372a020 197 *
AnnaBridge 167:84c0a372a020 198 * @return #E_NO_ERROR Asynchronous write successfully started, @ref
AnnaBridge 167:84c0a372a020 199 * MXC_Error_Codes "error" if unsuccessful.
AnnaBridge 167:84c0a372a020 200 */
AnnaBridge 167:84c0a372a020 201 int UART_WriteAsync(mxc_uart_regs_t *uart, uart_req_t *req);
AnnaBridge 167:84c0a372a020 202
AnnaBridge 167:84c0a372a020 203 /**
AnnaBridge 167:84c0a372a020 204 * Asynchronously Read UART data.
AnnaBridge 167:84c0a372a020 205 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 206 * @param req Pointer to request for a UART transaction.
AnnaBridge 167:84c0a372a020 207 *
AnnaBridge 167:84c0a372a020 208 * @return #E_NO_ERROR Asynchronous read successfully started, @ref
AnnaBridge 167:84c0a372a020 209 * MXC_Error_Codes "error" if unsuccessful.
AnnaBridge 167:84c0a372a020 210 * @note Request struct must remain allocated until callback function is called.
AnnaBridge 167:84c0a372a020 211 */
AnnaBridge 167:84c0a372a020 212 int UART_ReadAsync(mxc_uart_regs_t *uart, uart_req_t *req);
AnnaBridge 167:84c0a372a020 213
AnnaBridge 167:84c0a372a020 214 /**
AnnaBridge 167:84c0a372a020 215 * Abort asynchronous request.
AnnaBridge 167:84c0a372a020 216 * @param req Pointer to a request for a UART transaction, see #uart_req.
AnnaBridge 167:84c0a372a020 217 * @return #E_NO_ERROR Asynchronous request aborted successfully, error if unsuccessful.
AnnaBridge 167:84c0a372a020 218 */
AnnaBridge 167:84c0a372a020 219 int UART_AbortAsync(uart_req_t *req);
AnnaBridge 167:84c0a372a020 220
AnnaBridge 167:84c0a372a020 221 /**
AnnaBridge 167:84c0a372a020 222 * @brief UART interrupt handler.
AnnaBridge 167:84c0a372a020 223 * @details This function should be called by the application from the
AnnaBridge 167:84c0a372a020 224 * interrupt handler if UART interrupts are enabled. Alternately,
AnnaBridge 167:84c0a372a020 225 * this function can be periodically called by the application if
AnnaBridge 167:84c0a372a020 226 * UART interrupts are disabled. Only necessary to call this when
AnnaBridge 167:84c0a372a020 227 * using asynchronous functions.
AnnaBridge 167:84c0a372a020 228 *
AnnaBridge 167:84c0a372a020 229 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 230 */
AnnaBridge 167:84c0a372a020 231 void UART_Handler(mxc_uart_regs_t *uart);
AnnaBridge 167:84c0a372a020 232
AnnaBridge 167:84c0a372a020 233 /**
AnnaBridge 167:84c0a372a020 234 * @brief Check to see if the UART is busy.
AnnaBridge 167:84c0a372a020 235 *
AnnaBridge 167:84c0a372a020 236 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 237 *
AnnaBridge 167:84c0a372a020 238 * @return #E_NO_ERROR UART is idle.
AnnaBridge 167:84c0a372a020 239 * @return #E_BUSY UART is in use.
AnnaBridge 167:84c0a372a020 240 */
AnnaBridge 167:84c0a372a020 241 int UART_Busy(mxc_uart_regs_t *uart);
AnnaBridge 167:84c0a372a020 242 /** @}*/
AnnaBridge 167:84c0a372a020 243 /**
AnnaBridge 167:84c0a372a020 244 * @ingroup uart_top
AnnaBridge 167:84c0a372a020 245 * @{
AnnaBridge 167:84c0a372a020 246 */
AnnaBridge 167:84c0a372a020 247 /**
AnnaBridge 167:84c0a372a020 248 * @brief Prepare the UART for entry into a Low-Power mode (LP0/LP1).
AnnaBridge 167:84c0a372a020 249 * @details Checks for any ongoing transactions. Disables interrupts if the
AnnaBridge 167:84c0a372a020 250 * UART is idle.
AnnaBridge 167:84c0a372a020 251 *
AnnaBridge 167:84c0a372a020 252 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 253 * @return #E_NO_ERROR UART is ready to enter Low-Power modes (LP0/LP1).
AnnaBridge 167:84c0a372a020 254 * @return #E_BUSY UART is active and busy and not ready to enter a
AnnaBridge 167:84c0a372a020 255 * Low-Power mode (LP0/LP1).
AnnaBridge 167:84c0a372a020 256 */
AnnaBridge 167:84c0a372a020 257 int UART_PrepForSleep(mxc_uart_regs_t *uart);
AnnaBridge 167:84c0a372a020 258
AnnaBridge 167:84c0a372a020 259 /**
AnnaBridge 167:84c0a372a020 260 * @brief Enables the UART.
AnnaBridge 167:84c0a372a020 261 * @note This function does not change the existing UART configuration.
AnnaBridge 167:84c0a372a020 262 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 263 */
AnnaBridge 167:84c0a372a020 264 __STATIC_INLINE void UART_Enable(mxc_uart_regs_t *uart)
AnnaBridge 167:84c0a372a020 265 {
AnnaBridge 167:84c0a372a020 266 uart->ctrl |= (MXC_F_UART_CTRL_UART_EN | MXC_F_UART_CTRL_TX_FIFO_EN |
AnnaBridge 167:84c0a372a020 267 MXC_F_UART_CTRL_RX_FIFO_EN);
AnnaBridge 167:84c0a372a020 268 }
AnnaBridge 167:84c0a372a020 269
AnnaBridge 167:84c0a372a020 270 /**
AnnaBridge 167:84c0a372a020 271 * @brief Drains/empties and data in the RX FIFO.
AnnaBridge 167:84c0a372a020 272 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 273 */
AnnaBridge 167:84c0a372a020 274 __STATIC_INLINE void UART_DrainRX(mxc_uart_regs_t *uart)
AnnaBridge 167:84c0a372a020 275 {
AnnaBridge 167:84c0a372a020 276 uint32_t ctrl_save = uart->ctrl;
AnnaBridge 167:84c0a372a020 277 uart->ctrl = (ctrl_save & ~MXC_F_UART_CTRL_RX_FIFO_EN);
AnnaBridge 167:84c0a372a020 278 uart->ctrl = ctrl_save;
AnnaBridge 167:84c0a372a020 279 }
AnnaBridge 167:84c0a372a020 280
AnnaBridge 167:84c0a372a020 281 /**
AnnaBridge 167:84c0a372a020 282 * @brief Drains/empties any data in the TX FIFO.
AnnaBridge 167:84c0a372a020 283 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 284 */
AnnaBridge 167:84c0a372a020 285 __STATIC_INLINE void UART_DrainTX(mxc_uart_regs_t *uart)
AnnaBridge 167:84c0a372a020 286 {
AnnaBridge 167:84c0a372a020 287 uint32_t ctrl_save = uart->ctrl;
AnnaBridge 167:84c0a372a020 288 uart->ctrl = (ctrl_save & ~MXC_F_UART_CTRL_TX_FIFO_EN);
AnnaBridge 167:84c0a372a020 289 uart->ctrl = ctrl_save;
AnnaBridge 167:84c0a372a020 290 }
AnnaBridge 167:84c0a372a020 291
AnnaBridge 167:84c0a372a020 292 /**
AnnaBridge 167:84c0a372a020 293 * @brief Returns the number of unused bytes available in the UART TX FIFO.
AnnaBridge 167:84c0a372a020 294 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 295 * @return Number of unused bytes in the TX FIFO.
AnnaBridge 167:84c0a372a020 296 */
AnnaBridge 167:84c0a372a020 297 __STATIC_INLINE unsigned UART_NumWriteAvail(mxc_uart_regs_t *uart)
AnnaBridge 167:84c0a372a020 298 {
AnnaBridge 167:84c0a372a020 299 return (MXC_UART_FIFO_DEPTH - (uart->tx_fifo_ctrl & MXC_F_UART_TX_FIFO_CTRL_FIFO_ENTRY));
AnnaBridge 167:84c0a372a020 300 }
AnnaBridge 167:84c0a372a020 301
AnnaBridge 167:84c0a372a020 302 /**
AnnaBridge 167:84c0a372a020 303 * @brief Returns the number of bytes available to be read from the RX
AnnaBridge 167:84c0a372a020 304 * FIFO.
AnnaBridge 167:84c0a372a020 305 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 306 * @return The number of bytes available to read in the RX FIFO.
AnnaBridge 167:84c0a372a020 307 */
AnnaBridge 167:84c0a372a020 308 __STATIC_INLINE unsigned UART_NumReadAvail(mxc_uart_regs_t *uart)
AnnaBridge 167:84c0a372a020 309 {
AnnaBridge 167:84c0a372a020 310 return (uart->rx_fifo_ctrl & MXC_F_UART_RX_FIFO_CTRL_FIFO_ENTRY);
AnnaBridge 167:84c0a372a020 311 }
AnnaBridge 167:84c0a372a020 312
AnnaBridge 167:84c0a372a020 313 /**
AnnaBridge 167:84c0a372a020 314 * @brief Clear interrupt flags.
AnnaBridge 167:84c0a372a020 315 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 316 * @param mask Mask of the UART interrupts to clear, see @ref UART_INTFL_Register Register.
AnnaBridge 167:84c0a372a020 317 */
AnnaBridge 167:84c0a372a020 318 __STATIC_INLINE void UART_ClearFlags(mxc_uart_regs_t *uart, uint32_t mask)
AnnaBridge 167:84c0a372a020 319 {
AnnaBridge 167:84c0a372a020 320 uart->intfl = mask;
AnnaBridge 167:84c0a372a020 321 }
AnnaBridge 167:84c0a372a020 322
AnnaBridge 167:84c0a372a020 323 /**
AnnaBridge 167:84c0a372a020 324 * @brief Get interrupt flags.
AnnaBridge 167:84c0a372a020 325 * @param uart Pointer to the UART registers.
AnnaBridge 167:84c0a372a020 326 * @return Mask of active flags.
AnnaBridge 167:84c0a372a020 327 */
AnnaBridge 167:84c0a372a020 328 __STATIC_INLINE unsigned UART_GetFlags(mxc_uart_regs_t *uart)
AnnaBridge 167:84c0a372a020 329 {
AnnaBridge 167:84c0a372a020 330 return (uart->intfl);
AnnaBridge 167:84c0a372a020 331 }
AnnaBridge 167:84c0a372a020 332 /** @} */
AnnaBridge 167:84c0a372a020 333 #ifdef __cplusplus
AnnaBridge 167:84c0a372a020 334 }
AnnaBridge 167:84c0a372a020 335 #endif
AnnaBridge 167:84c0a372a020 336
AnnaBridge 167:84c0a372a020 337 #endif /* _UART_H_ */