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