mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Fri Jul 17 09:15:10 2015 +0100
Revision:
592:a274ee790e56
Parent:
579:53297373a894
Synchronized with git revision e7144f83a8d75df80c4877936b6ffe552b0be9e6

Full URL: https://github.com/mbedmicro/mbed/commit/e7144f83a8d75df80c4877936b6ffe552b0be9e6/

More API implementation for SAMR21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 579:53297373a894 1 #ifndef USART_H_INCLUDED
mbed_official 579:53297373a894 2 #define USART_H_INCLUDED
mbed_official 579:53297373a894 3
mbed_official 579:53297373a894 4 /**
mbed_official 579:53297373a894 5 * \defgroup asfdoc_sam0_sercom_usart_group SAM Serial USART Driver (SERCOM USART)
mbed_official 579:53297373a894 6 *
mbed_official 579:53297373a894 7 * This driver for Atmel庐 | SMART SAM devices provides an interface for the configuration
mbed_official 579:53297373a894 8 * and management of the SERCOM module in its USART mode to transfer or receive
mbed_official 579:53297373a894 9 * USART data frames. The following driver API modes are covered by this
mbed_official 579:53297373a894 10 * manual:
mbed_official 579:53297373a894 11 *
mbed_official 579:53297373a894 12 * - Polled APIs
mbed_official 579:53297373a894 13 * \if USART_CALLBACK_MODE
mbed_official 579:53297373a894 14 * - Callback APIs
mbed_official 579:53297373a894 15 * \endif
mbed_official 579:53297373a894 16 *
mbed_official 579:53297373a894 17 * The following peripherals are used by this module:
mbed_official 579:53297373a894 18 * - SERCOM (Serial Communication Interface)
mbed_official 579:53297373a894 19 *
mbed_official 579:53297373a894 20 * The following devices can use this module:
mbed_official 579:53297373a894 21 * - Atmel | SMART SAM D20/D21
mbed_official 579:53297373a894 22 * - Atmel | SMART SAM R21
mbed_official 579:53297373a894 23 * - Atmel | SMART SAM D10/D11
mbed_official 579:53297373a894 24 * - Atmel | SMART SAM L21
mbed_official 579:53297373a894 25 *
mbed_official 579:53297373a894 26 * The outline of this documentation is as follows:
mbed_official 579:53297373a894 27 * - \ref asfdoc_sam0_sercom_usart_prerequisites
mbed_official 579:53297373a894 28 * - \ref asfdoc_sam0_sercom_usart_overview
mbed_official 579:53297373a894 29 * - \ref asfdoc_sam0_sercom_usart_special_considerations
mbed_official 579:53297373a894 30 * - \ref asfdoc_sam0_sercom_usart_extra_info
mbed_official 579:53297373a894 31 * - \ref asfdoc_sam0_sercom_usart_examples
mbed_official 579:53297373a894 32 * - \ref asfdoc_sam0_sercom_usart_api_overview
mbed_official 579:53297373a894 33 *
mbed_official 579:53297373a894 34 * \section asfdoc_sam0_sercom_usart_prerequisites Prerequisites
mbed_official 579:53297373a894 35 *
mbed_official 579:53297373a894 36 * To use the USART you need to have a GCLK generator enabled and running
mbed_official 579:53297373a894 37 * that can be used as the SERCOM clock source. This can either be configured
mbed_official 579:53297373a894 38 * in conf_clocks.h or by using the system clock driver.
mbed_official 579:53297373a894 39 *
mbed_official 579:53297373a894 40 * \section asfdoc_sam0_sercom_usart_overview Module Overview
mbed_official 579:53297373a894 41 *
mbed_official 579:53297373a894 42 * This driver will use one (or more) SERCOM interfaces on the system
mbed_official 579:53297373a894 43 * and configure it to run as a USART interface in either synchronous
mbed_official 579:53297373a894 44 * or asynchronous mode.
mbed_official 579:53297373a894 45 *
mbed_official 579:53297373a894 46 * \subsection asfdoc_sam0_sercom_usart_features Driver Feature Macro Definition
mbed_official 579:53297373a894 47 * <table>
mbed_official 579:53297373a894 48 * <tr>
mbed_official 579:53297373a894 49 * <th>Driver Feature Macro</th>
mbed_official 579:53297373a894 50 * <th>Supported devices</th>
mbed_official 579:53297373a894 51 * </tr>
mbed_official 579:53297373a894 52 * <tr>
mbed_official 579:53297373a894 53 * <td>FEATURE_USART_SYNC_SCHEME_V2</td>
mbed_official 579:53297373a894 54 * <td>SAM D21/R21/D10/D11/L21</td>
mbed_official 579:53297373a894 55 * </tr>
mbed_official 579:53297373a894 56 * <tr>
mbed_official 579:53297373a894 57 * <td>FEATURE_USART_OVER_SAMPLE</td>
mbed_official 579:53297373a894 58 * <td>SAM D21/R21/D10/D11/L21</td>
mbed_official 579:53297373a894 59 * </tr>
mbed_official 579:53297373a894 60 * <tr>
mbed_official 579:53297373a894 61 * <td>FEATURE_USART_HARDWARE_FLOW_CONTROL</td>
mbed_official 579:53297373a894 62 * <td>SAM D21/R21/D10/D11/L21</td>
mbed_official 579:53297373a894 63 * </tr>
mbed_official 579:53297373a894 64 * <tr>
mbed_official 579:53297373a894 65 * <td>FEATURE_USART_IRDA</td>
mbed_official 579:53297373a894 66 * <td>SAM D21/R21/D10/D11/L21</td>
mbed_official 579:53297373a894 67 * </tr>
mbed_official 579:53297373a894 68 * <tr>
mbed_official 579:53297373a894 69 * <td>FEATURE_USART_LIN_SLAVE</td>
mbed_official 579:53297373a894 70 * <td>SAM D21/R21/D10/D11/L21</td>
mbed_official 579:53297373a894 71 * </tr>
mbed_official 579:53297373a894 72 * <tr>
mbed_official 579:53297373a894 73 * <td>FEATURE_USART_COLLISION_DECTION</td>
mbed_official 579:53297373a894 74 * <td>SAM D21/R21/D10/D11/L21</td>
mbed_official 579:53297373a894 75 * </tr>
mbed_official 579:53297373a894 76 * <tr>
mbed_official 579:53297373a894 77 * <td>FEATURE_USART_START_FRAME_DECTION</td>
mbed_official 579:53297373a894 78 * <td>SAM D21/R21/D10/D11/L21</td>
mbed_official 579:53297373a894 79 * </tr>
mbed_official 579:53297373a894 80 * <tr>
mbed_official 579:53297373a894 81 * <td>FEATURE_USART_IMMEDIATE_BUFFER_OVERFLOW_NOTIFICATION</td>
mbed_official 579:53297373a894 82 * <td>SAM D21/R21/D10/D11/L21</td>
mbed_official 579:53297373a894 83 * </tr>
mbed_official 579:53297373a894 84 * </table>
mbed_official 579:53297373a894 85 * \note The specific features are only available in the driver when the
mbed_official 579:53297373a894 86 * selected device supports those features.
mbed_official 579:53297373a894 87 *
mbed_official 579:53297373a894 88 * \subsection asfdoc_sam0_sercom_usart_overview_frame_format Frame Format
mbed_official 579:53297373a894 89 *
mbed_official 579:53297373a894 90 * Communication is based on frames, where the frame format can be customized
mbed_official 579:53297373a894 91 * to accommodate a wide range of standards. A frame consists of a start bit,
mbed_official 579:53297373a894 92 * a number of data bits, an optional parity bit for error detection as well
mbed_official 579:53297373a894 93 * as a configurable length stop bit(s) - see
mbed_official 579:53297373a894 94 * \ref asfdoc_sam0_sercom_usart_frame_diagram "the figure below".
mbed_official 579:53297373a894 95 * \ref asfdoc_sam0_sercom_usart_frame_params "The table below" shows the
mbed_official 579:53297373a894 96 * available parameters you can change in a frame.
mbed_official 579:53297373a894 97 *
mbed_official 579:53297373a894 98 * \anchor asfdoc_sam0_sercom_usart_frame_params
mbed_official 579:53297373a894 99 * <table>
mbed_official 579:53297373a894 100 * <caption>USART Frame Parameters</caption>
mbed_official 579:53297373a894 101 * <tr>
mbed_official 579:53297373a894 102 * <th>Parameter</th>
mbed_official 579:53297373a894 103 * <th>Options</th>
mbed_official 579:53297373a894 104 * </tr>
mbed_official 579:53297373a894 105 * <tr>
mbed_official 579:53297373a894 106 * <td>Start bit</td>
mbed_official 579:53297373a894 107 * <td>1</td>
mbed_official 579:53297373a894 108 * </tr>
mbed_official 579:53297373a894 109 * <tr>
mbed_official 579:53297373a894 110 * <td>Data bits</td>
mbed_official 579:53297373a894 111 * <td>5, 6, 7, 8, 9</td>
mbed_official 579:53297373a894 112 * </tr>
mbed_official 579:53297373a894 113 * <tr>
mbed_official 579:53297373a894 114 * <td>Parity bit</td>
mbed_official 579:53297373a894 115 * <td>None, Even, Odd</td>
mbed_official 579:53297373a894 116 * </tr>
mbed_official 579:53297373a894 117 * <tr>
mbed_official 579:53297373a894 118 * <td>Stop bits</td>
mbed_official 579:53297373a894 119 * <td>1, 2</td>
mbed_official 579:53297373a894 120 * </tr>
mbed_official 579:53297373a894 121 * </table>
mbed_official 579:53297373a894 122 *
mbed_official 579:53297373a894 123 * \anchor asfdoc_sam0_sercom_usart_frame_diagram
mbed_official 579:53297373a894 124 * \image html usart_frame.svg "USART Frame Overview" width=100%
mbed_official 579:53297373a894 125 *
mbed_official 579:53297373a894 126 * \subsection asfdoc_sam0_sercom_usart_overview_sync Synchronous Mode
mbed_official 579:53297373a894 127 *
mbed_official 579:53297373a894 128 * In synchronous mode a dedicated clock line is provided; either by the USART
mbed_official 579:53297373a894 129 * itself if in master mode, or by an external master if in slave mode.
mbed_official 579:53297373a894 130 * Maximum transmission speed is the same as the GCLK clocking the USART
mbed_official 579:53297373a894 131 * peripheral when in slave mode, and the GCLK divided by two if in
mbed_official 579:53297373a894 132 * master mode. In synchronous mode the interface needs three lines to
mbed_official 579:53297373a894 133 * communicate:
mbed_official 579:53297373a894 134 * - TX (Transmit pin)
mbed_official 579:53297373a894 135 * - RX (Receive pin)
mbed_official 579:53297373a894 136 * - XCK (Clock pin)
mbed_official 579:53297373a894 137 *
mbed_official 579:53297373a894 138 * \subsubsection asfdoc_sam0_sercom_usart_overview_sync_sampling Data Sampling
mbed_official 579:53297373a894 139 * In synchronous mode the data is sampled on either the rising or falling edge
mbed_official 579:53297373a894 140 * of the clock signal. This is configured by setting the clock polarity in the
mbed_official 579:53297373a894 141 * configuration struct.
mbed_official 579:53297373a894 142 *
mbed_official 579:53297373a894 143 * \subsection asfdoc_sam0_sercom_usart_overview_async Asynchronous Mode
mbed_official 579:53297373a894 144 *
mbed_official 579:53297373a894 145 * In asynchronous mode no dedicated clock line is used, and the communication
mbed_official 579:53297373a894 146 * is based on matching the clock speed on the transmitter and receiver. The
mbed_official 579:53297373a894 147 * clock is generated from the internal SERCOM baudrate generator, and the
mbed_official 579:53297373a894 148 * frames are synchronized by using the frame start bits. Maximum transmission
mbed_official 579:53297373a894 149 * speed is limited to the SERCOM GCLK divided by 16.
mbed_official 579:53297373a894 150 * In asynchronous mode the interface only needs two lines to communicate:
mbed_official 579:53297373a894 151 * - TX (Transmit pin)
mbed_official 579:53297373a894 152 * - RX (Receive pin)
mbed_official 579:53297373a894 153 *
mbed_official 579:53297373a894 154 * \subsubsection asfdoc_sam0_sercom_usart_overview_async_clock_matching Transmitter/receiver Clock Matching
mbed_official 579:53297373a894 155 *
mbed_official 579:53297373a894 156 * For successful transmit and receive using the asynchronous mode the receiver
mbed_official 579:53297373a894 157 * and transmitter clocks needs to be closely matched. When receiving a frame
mbed_official 579:53297373a894 158 * that does not match the selected baudrate closely enough the receiver will
mbed_official 579:53297373a894 159 * be unable to synchronize the frame(s), and garbage transmissions will
mbed_official 579:53297373a894 160 * result.
mbed_official 579:53297373a894 161 *
mbed_official 579:53297373a894 162 * \subsection asfdoc_sam0_sercom_usart_parity Parity
mbed_official 579:53297373a894 163 * Parity can be enabled to detect if a transmission was in error. This is done
mbed_official 579:53297373a894 164 * by counting the number of "1" bits in the frame. When using Even parity the
mbed_official 579:53297373a894 165 * parity bit will be set if the total number of "1"s in the frame are an even
mbed_official 579:53297373a894 166 * number. If using Odd parity the parity bit will be set if the total number
mbed_official 579:53297373a894 167 * of "1"s are Odd.
mbed_official 579:53297373a894 168 *
mbed_official 579:53297373a894 169 * When receiving a character the receiver will count the number of "1"s in the
mbed_official 579:53297373a894 170 * frame and give an error if the received frame and parity bit disagree.
mbed_official 579:53297373a894 171 *
mbed_official 579:53297373a894 172 * \subsection asfdoc_sam0_sercom_usart_overview_pin_configuration GPIO Configuration
mbed_official 579:53297373a894 173 *
mbed_official 579:53297373a894 174 * The SERCOM module has four internal pads; the RX pin can be placed freely on
mbed_official 579:53297373a894 175 * any one of the four pads, and the TX and XCK pins have two predefined
mbed_official 579:53297373a894 176 * positions that can be selected as a pair. The pads can then be routed to an
mbed_official 579:53297373a894 177 * external GPIO pin using the normal pin multiplexing scheme on the SAM.
mbed_official 579:53297373a894 178 *
mbed_official 579:53297373a894 179 * \section asfdoc_sam0_sercom_usart_special_considerations Special Considerations
mbed_official 579:53297373a894 180 *
mbed_official 579:53297373a894 181 * \if USART_CALLBACK_MODE
mbed_official 579:53297373a894 182 * Never execute large portions of code in the callbacks. These
mbed_official 579:53297373a894 183 * are run from the interrupt routine, and thus having long callbacks will
mbed_official 579:53297373a894 184 * keep the processor in the interrupt handler for an equally long time.
mbed_official 579:53297373a894 185 * A common way to handle this is to use global flags signaling the
mbed_official 579:53297373a894 186 * main application that an interrupt event has happened, and only do the
mbed_official 579:53297373a894 187 * minimal needed processing in the callback.
mbed_official 579:53297373a894 188 * \else
mbed_official 579:53297373a894 189 * No special considerations.
mbed_official 579:53297373a894 190 * \endif
mbed_official 579:53297373a894 191 *
mbed_official 579:53297373a894 192 * \section asfdoc_sam0_sercom_usart_extra_info Extra Information
mbed_official 579:53297373a894 193 *
mbed_official 579:53297373a894 194 * For extra information, see \ref asfdoc_sam0_sercom_usart_extra. This includes:
mbed_official 579:53297373a894 195 * - \ref asfdoc_sam0_sercom_usart_extra_acronyms
mbed_official 579:53297373a894 196 * - \ref asfdoc_sam0_sercom_usart_extra_dependencies
mbed_official 579:53297373a894 197 * - \ref asfdoc_sam0_sercom_usart_extra_errata
mbed_official 579:53297373a894 198 * - \ref asfdoc_sam0_sercom_usart_extra_history
mbed_official 579:53297373a894 199 *
mbed_official 579:53297373a894 200 * \section asfdoc_sam0_sercom_usart_examples Examples
mbed_official 579:53297373a894 201 *
mbed_official 579:53297373a894 202 * For a list of examples related to this driver, see
mbed_official 579:53297373a894 203 * \ref asfdoc_sam0_sercom_usart_exqsg.
mbed_official 579:53297373a894 204 *
mbed_official 579:53297373a894 205 * \section asfdoc_sam0_sercom_usart_api_overview API Overview
mbed_official 579:53297373a894 206 * @{
mbed_official 579:53297373a894 207 */
mbed_official 579:53297373a894 208
mbed_official 579:53297373a894 209 #include <compiler.h>
mbed_official 579:53297373a894 210 #include <sercom.h>
mbed_official 579:53297373a894 211 #include <pinmux.h>
mbed_official 579:53297373a894 212
mbed_official 579:53297373a894 213 #define USART_CALLBACK_MODE true
mbed_official 579:53297373a894 214
mbed_official 579:53297373a894 215 #if USART_CALLBACK_MODE == true
mbed_official 579:53297373a894 216 # include <sercom_interrupt.h>
mbed_official 579:53297373a894 217 #endif
mbed_official 579:53297373a894 218
mbed_official 579:53297373a894 219 #ifdef __cplusplus
mbed_official 579:53297373a894 220 extern "C" {
mbed_official 579:53297373a894 221 #endif
mbed_official 579:53297373a894 222
mbed_official 579:53297373a894 223 /**
mbed_official 579:53297373a894 224 * \name Driver Feature Definition
mbed_official 579:53297373a894 225 * Define SERCOM USART features set according to different device family.
mbed_official 579:53297373a894 226 * @{
mbed_official 579:53297373a894 227 */
mbed_official 579:53297373a894 228 #if (SAMD21) || (SAMR21) || (SAMD10) || (SAMD11) || (SAML21) || defined(__DOXYGEN__)
mbed_official 579:53297373a894 229 /** Usart sync scheme version 2. */
mbed_official 579:53297373a894 230 # define FEATURE_USART_SYNC_SCHEME_V2
mbed_official 579:53297373a894 231 /** Usart over sampling. */
mbed_official 579:53297373a894 232 # define FEATURE_USART_OVER_SAMPLE
mbed_official 579:53297373a894 233 /** Usart hardware control flow. */
mbed_official 579:53297373a894 234 # define FEATURE_USART_HARDWARE_FLOW_CONTROL
mbed_official 579:53297373a894 235 /** IrDA mode. */
mbed_official 579:53297373a894 236 # define FEATURE_USART_IRDA
mbed_official 579:53297373a894 237 /** LIN slave mode. */
mbed_official 579:53297373a894 238 # define FEATURE_USART_LIN_SLAVE
mbed_official 579:53297373a894 239 /** Usart collision detection. */
mbed_official 579:53297373a894 240 # define FEATURE_USART_COLLISION_DECTION
mbed_official 579:53297373a894 241 /** Usart start frame detection. */
mbed_official 579:53297373a894 242 # define FEATURE_USART_START_FRAME_DECTION
mbed_official 579:53297373a894 243 /** Usart start buffer overflow notification. */
mbed_official 579:53297373a894 244 # define FEATURE_USART_IMMEDIATE_BUFFER_OVERFLOW_NOTIFICATION
mbed_official 579:53297373a894 245 #endif
mbed_official 579:53297373a894 246 /*@}*/
mbed_official 579:53297373a894 247
mbed_official 579:53297373a894 248 #ifndef PINMUX_DEFAULT
mbed_official 579:53297373a894 249 /** Default pinmux. */
mbed_official 579:53297373a894 250 # define PINMUX_DEFAULT 0
mbed_official 579:53297373a894 251 #endif
mbed_official 579:53297373a894 252
mbed_official 579:53297373a894 253 #ifndef PINMUX_UNUSED
mbed_official 579:53297373a894 254 /** Unused pinmux. */
mbed_official 579:53297373a894 255 # define PINMUX_UNUSED 0xFFFFFFFF
mbed_official 579:53297373a894 256 #endif
mbed_official 579:53297373a894 257
mbed_official 579:53297373a894 258 #ifndef USART_TIMEOUT
mbed_official 579:53297373a894 259 /** USART timeout value. */
mbed_official 579:53297373a894 260 # define USART_TIMEOUT 0xFFFF
mbed_official 579:53297373a894 261 #endif
mbed_official 579:53297373a894 262
mbed_official 579:53297373a894 263 #if USART_CALLBACK_MODE == true
mbed_official 579:53297373a894 264 /**
mbed_official 579:53297373a894 265 * \brief USART Callback enum
mbed_official 579:53297373a894 266 *
mbed_official 579:53297373a894 267 * Callbacks for the Asynchronous USART driver.
mbed_official 579:53297373a894 268 */
mbed_official 579:53297373a894 269 enum usart_callback {
mbed_official 579:53297373a894 270 /** Callback for buffer transmitted. */
mbed_official 579:53297373a894 271 USART_CALLBACK_BUFFER_TRANSMITTED,
mbed_official 579:53297373a894 272 /** Callback for buffer received. */
mbed_official 579:53297373a894 273 USART_CALLBACK_BUFFER_RECEIVED,
mbed_official 579:53297373a894 274 /** Callback for error. */
mbed_official 579:53297373a894 275 USART_CALLBACK_ERROR,
mbed_official 579:53297373a894 276 #ifdef FEATURE_USART_LIN_SLAVE
mbed_official 579:53297373a894 277 /** Callback for break character is received. */
mbed_official 579:53297373a894 278 USART_CALLBACK_BREAK_RECEIVED,
mbed_official 579:53297373a894 279 #endif
mbed_official 579:53297373a894 280 #ifdef FEATURE_USART_HARDWARE_FLOW_CONTROL
mbed_official 579:53297373a894 281 /** Callback for a change is detected on the CTS pin. */
mbed_official 579:53297373a894 282 USART_CALLBACK_CTS_INPUT_CHANGE,
mbed_official 579:53297373a894 283 #endif
mbed_official 579:53297373a894 284 #ifdef FEATURE_USART_START_FRAME_DECTION
mbed_official 579:53297373a894 285 /** Callback for a start condition is detected on the RxD line. */
mbed_official 579:53297373a894 286 USART_CALLBACK_START_RECEIVED,
mbed_official 579:53297373a894 287 #endif
mbed_official 579:53297373a894 288 # if !defined(__DOXYGEN__)
mbed_official 579:53297373a894 289 /** Number of available callbacks. */
mbed_official 579:53297373a894 290 USART_CALLBACK_N,
mbed_official 579:53297373a894 291 # endif
mbed_official 579:53297373a894 292 };
mbed_official 579:53297373a894 293 #endif
mbed_official 579:53297373a894 294
mbed_official 579:53297373a894 295 /**
mbed_official 579:53297373a894 296 * \brief USART Data Order enum
mbed_official 579:53297373a894 297 *
mbed_official 579:53297373a894 298 * The data order decides which of MSB or LSB is shifted out first when data is
mbed_official 579:53297373a894 299 * transferred.
mbed_official 579:53297373a894 300 */
mbed_official 579:53297373a894 301 enum usart_dataorder {
mbed_official 579:53297373a894 302 /** The MSB will be shifted out first during transmission,
mbed_official 579:53297373a894 303 * and shifted in first during reception. */
mbed_official 579:53297373a894 304 USART_DATAORDER_MSB = 0,
mbed_official 579:53297373a894 305 /** The LSB will be shifted out first during transmission,
mbed_official 579:53297373a894 306 * and shifted in first during reception. */
mbed_official 579:53297373a894 307 USART_DATAORDER_LSB = SERCOM_USART_CTRLA_DORD,
mbed_official 579:53297373a894 308 };
mbed_official 579:53297373a894 309
mbed_official 579:53297373a894 310 /**
mbed_official 579:53297373a894 311 * \brief USART Transfer mode enum
mbed_official 579:53297373a894 312 *
mbed_official 579:53297373a894 313 * Select USART transfer mode.
mbed_official 579:53297373a894 314 */
mbed_official 579:53297373a894 315 enum usart_transfer_mode {
mbed_official 579:53297373a894 316 /** Transfer of data is done synchronously. */
mbed_official 579:53297373a894 317 USART_TRANSFER_SYNCHRONOUSLY = (SERCOM_USART_CTRLA_CMODE),
mbed_official 579:53297373a894 318 /** Transfer of data is done asynchronously. */
mbed_official 579:53297373a894 319 USART_TRANSFER_ASYNCHRONOUSLY = 0
mbed_official 579:53297373a894 320 };
mbed_official 579:53297373a894 321
mbed_official 579:53297373a894 322 /**
mbed_official 579:53297373a894 323 * \brief USART Parity enum
mbed_official 579:53297373a894 324 *
mbed_official 579:53297373a894 325 * Select parity USART parity mode.
mbed_official 579:53297373a894 326 */
mbed_official 579:53297373a894 327 enum usart_parity {
mbed_official 579:53297373a894 328 /** For odd parity checking, the parity bit will be set if number of
mbed_official 579:53297373a894 329 * ones being transferred is even. */
mbed_official 579:53297373a894 330 USART_PARITY_ODD = SERCOM_USART_CTRLB_PMODE,
mbed_official 579:53297373a894 331
mbed_official 579:53297373a894 332 /** For even parity checking, the parity bit will be set if number of
mbed_official 579:53297373a894 333 * ones being received is odd. */
mbed_official 579:53297373a894 334 USART_PARITY_EVEN = 0,
mbed_official 579:53297373a894 335
mbed_official 579:53297373a894 336 /** No parity checking will be executed, and there will be no parity bit
mbed_official 579:53297373a894 337 * in the received frame. */
mbed_official 579:53297373a894 338 USART_PARITY_NONE = 0xFF,
mbed_official 579:53297373a894 339 };
mbed_official 579:53297373a894 340
mbed_official 579:53297373a894 341 /**
mbed_official 579:53297373a894 342 * \brief USART signal MUX settings
mbed_official 579:53297373a894 343 *
mbed_official 579:53297373a894 344 * Set the functionality of the SERCOM pins.
mbed_official 579:53297373a894 345 *
mbed_official 579:53297373a894 346 * See \ref asfdoc_sam0_sercom_usart_mux_settings for a description of the
mbed_official 579:53297373a894 347 * various MUX setting options.
mbed_official 579:53297373a894 348 */
mbed_official 579:53297373a894 349 enum usart_signal_mux_settings {
mbed_official 579:53297373a894 350 #ifdef FEATURE_USART_HARDWARE_FLOW_CONTROL
mbed_official 579:53297373a894 351 /** MUX setting RX_0_TX_0_XCK_1. */
mbed_official 579:53297373a894 352 USART_RX_0_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(0) | SERCOM_USART_CTRLA_TXPO(0)),
mbed_official 579:53297373a894 353 /** MUX setting RX_0_TX_2_XCK_3. */
mbed_official 579:53297373a894 354 USART_RX_0_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(0) | SERCOM_USART_CTRLA_TXPO(1)),
mbed_official 579:53297373a894 355 /** MUX setting USART_RX_0_TX_0_RTS_2_CTS_3. */
mbed_official 579:53297373a894 356 USART_RX_0_TX_0_RTS_2_CTS_3 = (SERCOM_USART_CTRLA_RXPO(0) | SERCOM_USART_CTRLA_TXPO(2)),
mbed_official 579:53297373a894 357 /** MUX setting RX_1_TX_0_XCK_1. */
mbed_official 579:53297373a894 358 USART_RX_1_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(1) | SERCOM_USART_CTRLA_TXPO(0)),
mbed_official 579:53297373a894 359 /** MUX setting RX_1_TX_2_XCK_3. */
mbed_official 579:53297373a894 360 USART_RX_1_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(1) | SERCOM_USART_CTRLA_TXPO(1)),
mbed_official 579:53297373a894 361 /** MUX setting USART_RX_1_TX_0_RTS_2_CTS_3. */
mbed_official 579:53297373a894 362 USART_RX_1_TX_0_RTS_2_CTS_3 = (SERCOM_USART_CTRLA_RXPO(1) | SERCOM_USART_CTRLA_TXPO(2)),
mbed_official 579:53297373a894 363 /** MUX setting RX_2_TX_0_XCK_1. */
mbed_official 579:53297373a894 364 USART_RX_2_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(2) | SERCOM_USART_CTRLA_TXPO(0)),
mbed_official 579:53297373a894 365 /** MUX setting RX_2_TX_2_XCK_3. */
mbed_official 579:53297373a894 366 USART_RX_2_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(2) | SERCOM_USART_CTRLA_TXPO(1)),
mbed_official 579:53297373a894 367 /** MUX setting USART_RX_2_TX_0_RTS_2_CTS_3. */
mbed_official 579:53297373a894 368 USART_RX_2_TX_0_RTS_2_CTS_3 = (SERCOM_USART_CTRLA_RXPO(2) | SERCOM_USART_CTRLA_TXPO(2)),
mbed_official 579:53297373a894 369 /** MUX setting RX_3_TX_0_XCK_1. */
mbed_official 579:53297373a894 370 USART_RX_3_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO(0)),
mbed_official 579:53297373a894 371 /** MUX setting RX_3_TX_2_XCK_3. */
mbed_official 579:53297373a894 372 USART_RX_3_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO(1)),
mbed_official 579:53297373a894 373 /** MUX setting USART_RX_3_TX_0_RTS_2_CTS_3. */
mbed_official 579:53297373a894 374 USART_RX_3_TX_0_RTS_2_CTS_3 = (SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO(2)),
mbed_official 579:53297373a894 375 #else
mbed_official 579:53297373a894 376 /** MUX setting RX_0_TX_0_XCK_1. */
mbed_official 579:53297373a894 377 USART_RX_0_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(0)),
mbed_official 579:53297373a894 378 /** MUX setting RX_0_TX_2_XCK_3. */
mbed_official 579:53297373a894 379 USART_RX_0_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(0) | SERCOM_USART_CTRLA_TXPO),
mbed_official 579:53297373a894 380 /** MUX setting RX_1_TX_0_XCK_1. */
mbed_official 579:53297373a894 381 USART_RX_1_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(1)),
mbed_official 579:53297373a894 382 /** MUX setting RX_1_TX_2_XCK_3. */
mbed_official 579:53297373a894 383 USART_RX_1_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(1) | SERCOM_USART_CTRLA_TXPO),
mbed_official 579:53297373a894 384 /** MUX setting RX_2_TX_0_XCK_1. */
mbed_official 579:53297373a894 385 USART_RX_2_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(2)),
mbed_official 579:53297373a894 386 /** MUX setting RX_2_TX_2_XCK_3. */
mbed_official 579:53297373a894 387 USART_RX_2_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(2) | SERCOM_USART_CTRLA_TXPO),
mbed_official 579:53297373a894 388 /** MUX setting RX_3_TX_0_XCK_1. */
mbed_official 579:53297373a894 389 USART_RX_3_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(3)),
mbed_official 579:53297373a894 390 /** MUX setting RX_3_TX_2_XCK_3. */
mbed_official 579:53297373a894 391 USART_RX_3_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO),
mbed_official 579:53297373a894 392 #endif
mbed_official 579:53297373a894 393 };
mbed_official 579:53297373a894 394
mbed_official 579:53297373a894 395 /**
mbed_official 579:53297373a894 396 * \brief USART Stop Bits enum
mbed_official 579:53297373a894 397 *
mbed_official 579:53297373a894 398 * Number of stop bits for a frame.
mbed_official 579:53297373a894 399 */
mbed_official 579:53297373a894 400 enum usart_stopbits {
mbed_official 579:53297373a894 401 /** Each transferred frame contains one stop bit. */
mbed_official 579:53297373a894 402 USART_STOPBITS_1 = 0,
mbed_official 579:53297373a894 403 /** Each transferred frame contains two stop bits. */
mbed_official 579:53297373a894 404 USART_STOPBITS_2 = SERCOM_USART_CTRLB_SBMODE,
mbed_official 579:53297373a894 405 };
mbed_official 579:53297373a894 406
mbed_official 579:53297373a894 407 /**
mbed_official 579:53297373a894 408 * \brief USART Character Size
mbed_official 579:53297373a894 409 *
mbed_official 579:53297373a894 410 * Number of bits for the character sent in a frame.
mbed_official 579:53297373a894 411 */
mbed_official 579:53297373a894 412 enum usart_character_size {
mbed_official 579:53297373a894 413 /** The char being sent in a frame is five bits long. */
mbed_official 579:53297373a894 414 USART_CHARACTER_SIZE_5BIT = SERCOM_USART_CTRLB_CHSIZE(5),
mbed_official 579:53297373a894 415 /** The char being sent in a frame is six bits long. */
mbed_official 579:53297373a894 416 USART_CHARACTER_SIZE_6BIT = SERCOM_USART_CTRLB_CHSIZE(6),
mbed_official 579:53297373a894 417 /** The char being sent in a frame is seven bits long. */
mbed_official 579:53297373a894 418 USART_CHARACTER_SIZE_7BIT = SERCOM_USART_CTRLB_CHSIZE(7),
mbed_official 579:53297373a894 419 /** The char being sent in a frame is eight bits long. */
mbed_official 579:53297373a894 420 USART_CHARACTER_SIZE_8BIT = SERCOM_USART_CTRLB_CHSIZE(0),
mbed_official 579:53297373a894 421 /** The char being sent in a frame is nine bits long. */
mbed_official 579:53297373a894 422 USART_CHARACTER_SIZE_9BIT = SERCOM_USART_CTRLB_CHSIZE(1),
mbed_official 579:53297373a894 423 };
mbed_official 579:53297373a894 424
mbed_official 579:53297373a894 425 #ifdef FEATURE_USART_OVER_SAMPLE
mbed_official 579:53297373a894 426 /**
mbed_official 579:53297373a894 427 * \brief USART Sample Rate
mbed_official 579:53297373a894 428 *
mbed_official 579:53297373a894 429 * The value of sample rate and baudrate generation mode.
mbed_official 579:53297373a894 430 */
mbed_official 579:53297373a894 431 enum usart_sample_rate {
mbed_official 579:53297373a894 432 /** 16x over-sampling using arithmetic baudrate generation. */
mbed_official 579:53297373a894 433 USART_SAMPLE_RATE_16X_ARITHMETIC = SERCOM_USART_CTRLA_SAMPR(0),
mbed_official 579:53297373a894 434 /** 16x over-sampling using fractional baudrate generation. */
mbed_official 579:53297373a894 435 USART_SAMPLE_RATE_16X_FRACTIONAL = SERCOM_USART_CTRLA_SAMPR(1),
mbed_official 579:53297373a894 436 /** 8x over-sampling using arithmetic baudrate generation. */
mbed_official 579:53297373a894 437 USART_SAMPLE_RATE_8X_ARITHMETIC = SERCOM_USART_CTRLA_SAMPR(2),
mbed_official 579:53297373a894 438 /** 8x over-sampling using fractional baudrate generation. */
mbed_official 579:53297373a894 439 USART_SAMPLE_RATE_8X_FRACTIONAL = SERCOM_USART_CTRLA_SAMPR(3),
mbed_official 579:53297373a894 440 /** 3x over-sampling using arithmetic baudrate generation. */
mbed_official 579:53297373a894 441 USART_SAMPLE_RATE_3X_ARITHMETIC = SERCOM_USART_CTRLA_SAMPR(4),
mbed_official 579:53297373a894 442 };
mbed_official 579:53297373a894 443
mbed_official 579:53297373a894 444 /**
mbed_official 579:53297373a894 445 * \brief USART Sample Adjustment
mbed_official 579:53297373a894 446 *
mbed_official 579:53297373a894 447 * The value of sample number used for majority voting.
mbed_official 579:53297373a894 448 */
mbed_official 579:53297373a894 449 enum usart_sample_adjustment {
mbed_official 579:53297373a894 450 /** The first, middle and last sample number used for majority voting is 7-8-9. */
mbed_official 579:53297373a894 451 USART_SAMPLE_ADJUSTMENT_7_8_9 = SERCOM_USART_CTRLA_SAMPA(0),
mbed_official 579:53297373a894 452 /** The first, middle and last sample number used for majority voting is 9-10-11. */
mbed_official 579:53297373a894 453 USART_SAMPLE_ADJUSTMENT_9_10_11 = SERCOM_USART_CTRLA_SAMPA(1),
mbed_official 579:53297373a894 454 /** The first, middle and last sample number used for majority voting is 11-12-13. */
mbed_official 579:53297373a894 455 USART_SAMPLE_ADJUSTMENT_11_12_13 = SERCOM_USART_CTRLA_SAMPA(2),
mbed_official 579:53297373a894 456 /** The first, middle and last sample number used for majority voting is 13-14-15. */
mbed_official 579:53297373a894 457 USART_SAMPLE_ADJUSTMENT_13_14_15 = SERCOM_USART_CTRLA_SAMPA(3),
mbed_official 579:53297373a894 458 };
mbed_official 579:53297373a894 459 #endif
mbed_official 579:53297373a894 460
mbed_official 579:53297373a894 461 /**
mbed_official 579:53297373a894 462 * \brief USART Transceiver
mbed_official 579:53297373a894 463 *
mbed_official 579:53297373a894 464 * Select Receiver or Transmitter.
mbed_official 579:53297373a894 465 */
mbed_official 579:53297373a894 466 enum usart_transceiver_type {
mbed_official 579:53297373a894 467 /** The parameter is for the Receiver. */
mbed_official 579:53297373a894 468 USART_TRANSCEIVER_RX,
mbed_official 579:53297373a894 469 /** The parameter is for the Transmitter. */
mbed_official 579:53297373a894 470 USART_TRANSCEIVER_TX,
mbed_official 579:53297373a894 471 };
mbed_official 579:53297373a894 472
mbed_official 579:53297373a894 473 /**
mbed_official 579:53297373a894 474 * \brief USART configuration struct
mbed_official 579:53297373a894 475 *
mbed_official 579:53297373a894 476 * Configuration options for USART.
mbed_official 579:53297373a894 477 */
mbed_official 579:53297373a894 478 struct usart_config {
mbed_official 579:53297373a894 479 /** USART bit order (MSB or LSB first). */
mbed_official 579:53297373a894 480 enum usart_dataorder data_order;
mbed_official 579:53297373a894 481 /** USART in asynchronous or synchronous mode. */
mbed_official 579:53297373a894 482 enum usart_transfer_mode transfer_mode;
mbed_official 579:53297373a894 483 /** USART parity. */
mbed_official 579:53297373a894 484 enum usart_parity parity;
mbed_official 579:53297373a894 485 /** Number of stop bits. */
mbed_official 579:53297373a894 486 enum usart_stopbits stopbits;
mbed_official 579:53297373a894 487 /** USART character size. */
mbed_official 579:53297373a894 488 enum usart_character_size character_size;
mbed_official 579:53297373a894 489 /** USART pin out. */
mbed_official 579:53297373a894 490 enum usart_signal_mux_settings mux_setting;
mbed_official 579:53297373a894 491 #ifdef FEATURE_USART_OVER_SAMPLE
mbed_official 579:53297373a894 492 /** USART sample rate. */
mbed_official 579:53297373a894 493 enum usart_sample_rate sample_rate;
mbed_official 579:53297373a894 494 /** USART sample adjustment. */
mbed_official 579:53297373a894 495 enum usart_sample_adjustment sample_adjustment;
mbed_official 579:53297373a894 496 #endif
mbed_official 579:53297373a894 497 #ifdef FEATURE_USART_IMMEDIATE_BUFFER_OVERFLOW_NOTIFICATION
mbed_official 579:53297373a894 498 /** Controls when the buffer overflow status bit is asserted when a buffer overflow occurs.*/
mbed_official 579:53297373a894 499 bool immediate_buffer_overflow_notification;
mbed_official 579:53297373a894 500 #endif
mbed_official 579:53297373a894 501 #ifdef FEATURE_USART_IRDA
mbed_official 579:53297373a894 502 /** Enable IrDA encoding format. */
mbed_official 579:53297373a894 503 bool encoding_format_enable;
mbed_official 579:53297373a894 504 /** The minimum pulse length that is required for a pulse to be accepted by the IrDA receiver. */
mbed_official 579:53297373a894 505 uint8_t receive_pulse_length;
mbed_official 579:53297373a894 506 #endif
mbed_official 579:53297373a894 507 #ifdef FEATURE_USART_LIN_SLAVE
mbed_official 579:53297373a894 508 /** Enable LIN Slave Support. */
mbed_official 579:53297373a894 509 bool lin_slave_enable;
mbed_official 579:53297373a894 510 #endif
mbed_official 579:53297373a894 511 #ifdef FEATURE_USART_START_FRAME_DECTION
mbed_official 579:53297373a894 512 /** Enable start of frame dection. */
mbed_official 579:53297373a894 513 bool start_frame_detection_enable;
mbed_official 579:53297373a894 514 #endif
mbed_official 579:53297373a894 515 #ifdef FEATURE_USART_COLLISION_DECTION
mbed_official 579:53297373a894 516 /** Enable collision dection. */
mbed_official 579:53297373a894 517 bool collision_detection_enable;
mbed_official 579:53297373a894 518 #endif
mbed_official 579:53297373a894 519 /** USART baudrate. */
mbed_official 579:53297373a894 520 uint32_t baudrate;
mbed_official 579:53297373a894 521 /** Enable receiver. */
mbed_official 579:53297373a894 522 bool receiver_enable;
mbed_official 579:53297373a894 523 /** Enable transmitter. */
mbed_official 579:53297373a894 524 bool transmitter_enable;
mbed_official 579:53297373a894 525
mbed_official 579:53297373a894 526 /** USART Clock Polarity.
mbed_official 579:53297373a894 527 * If true, data changes on falling XCK edge and
mbed_official 579:53297373a894 528 * is sampled at rising edge.
mbed_official 579:53297373a894 529 * If false, data changes on rising XCK edge and
mbed_official 579:53297373a894 530 * is sampled at falling edge.
mbed_official 579:53297373a894 531 * */
mbed_official 579:53297373a894 532 bool clock_polarity_inverted;
mbed_official 579:53297373a894 533
mbed_official 579:53297373a894 534 /** States whether to use the external clock applied to the XCK pin.
mbed_official 579:53297373a894 535 * In synchronous mode the shift register will act directly on the XCK clock.
mbed_official 579:53297373a894 536 * In asynchronous mode the XCK will be the input to the USART hardware module.
mbed_official 579:53297373a894 537 */
mbed_official 579:53297373a894 538 bool use_external_clock;
mbed_official 579:53297373a894 539 /** External clock frequency in synchronous mode.
mbed_official 579:53297373a894 540 * This must be set if \c use_external_clock is true. */
mbed_official 579:53297373a894 541 uint32_t ext_clock_freq;
mbed_official 579:53297373a894 542 /** If true the USART will be kept running in Standby sleep mode. */
mbed_official 579:53297373a894 543 bool run_in_standby;
mbed_official 579:53297373a894 544 /** GCLK generator source. */
mbed_official 579:53297373a894 545 enum gclk_generator generator_source;
mbed_official 579:53297373a894 546 /** PAD0 pinmux. */
mbed_official 579:53297373a894 547 uint32_t pinmux_pad0;
mbed_official 579:53297373a894 548 /** PAD1 pinmux. */
mbed_official 579:53297373a894 549 uint32_t pinmux_pad1;
mbed_official 579:53297373a894 550 /** PAD2 pinmux. */
mbed_official 579:53297373a894 551 uint32_t pinmux_pad2;
mbed_official 579:53297373a894 552 /** PAD3 pinmux. */
mbed_official 579:53297373a894 553 uint32_t pinmux_pad3;
mbed_official 579:53297373a894 554 };
mbed_official 579:53297373a894 555
mbed_official 579:53297373a894 556 #if USART_CALLBACK_MODE == true
mbed_official 579:53297373a894 557 /**
mbed_official 579:53297373a894 558 * \brief USART module instance
mbed_official 579:53297373a894 559 *
mbed_official 579:53297373a894 560 * Forward Declaration for the device instance.
mbed_official 579:53297373a894 561 */
mbed_official 579:53297373a894 562 struct usart_module;
mbed_official 579:53297373a894 563
mbed_official 579:53297373a894 564 /**
mbed_official 579:53297373a894 565 * \brief USART callback type
mbed_official 579:53297373a894 566 *
mbed_official 579:53297373a894 567 * Type of the callback functions.
mbed_official 579:53297373a894 568 */
mbed_official 579:53297373a894 569 typedef void (*usart_callback_t)(const struct usart_module *const module);
mbed_official 579:53297373a894 570 #endif
mbed_official 579:53297373a894 571
mbed_official 579:53297373a894 572 /**
mbed_official 579:53297373a894 573 * \brief SERCOM USART driver software device instance structure.
mbed_official 579:53297373a894 574 *
mbed_official 579:53297373a894 575 * SERCOM USART driver software instance structure, used to retain software
mbed_official 579:53297373a894 576 * state information of an associated hardware module instance.
mbed_official 579:53297373a894 577 *
mbed_official 579:53297373a894 578 * \note The fields of this structure should not be altered by the user
mbed_official 579:53297373a894 579 * application; they are reserved for module-internal use only.
mbed_official 579:53297373a894 580 */
mbed_official 579:53297373a894 581 struct usart_module {
mbed_official 579:53297373a894 582 #if !defined(__DOXYGEN__)
mbed_official 579:53297373a894 583 /** Pointer to the hardware instance. */
mbed_official 579:53297373a894 584 Sercom *hw;
mbed_official 579:53297373a894 585 /** Module lock. */
mbed_official 579:53297373a894 586 volatile bool locked;
mbed_official 579:53297373a894 587 /** Character size of the data being transferred. */
mbed_official 579:53297373a894 588 enum usart_character_size character_size;
mbed_official 579:53297373a894 589 /** Receiver enabled. */
mbed_official 579:53297373a894 590 bool receiver_enabled;
mbed_official 579:53297373a894 591 /** Transmitter enabled. */
mbed_official 579:53297373a894 592 bool transmitter_enabled;
mbed_official 579:53297373a894 593 #ifdef FEATURE_USART_LIN_SLAVE
mbed_official 579:53297373a894 594 /** LIN Slave Support enabled. */
mbed_official 579:53297373a894 595 bool lin_slave_enabled;
mbed_official 579:53297373a894 596 #endif
mbed_official 579:53297373a894 597 #ifdef FEATURE_USART_START_FRAME_DECTION
mbed_official 579:53297373a894 598 /** Start of frame dection enabled. */
mbed_official 579:53297373a894 599 bool start_frame_detection_enabled;
mbed_official 579:53297373a894 600 #endif
mbed_official 579:53297373a894 601 # if USART_CALLBACK_MODE == true
mbed_official 579:53297373a894 602 /** Array to store callback function pointers in. */
mbed_official 579:53297373a894 603 usart_callback_t callback[USART_CALLBACK_N];
mbed_official 579:53297373a894 604 /** Buffer pointer to where the next received character will be put. */
mbed_official 579:53297373a894 605 volatile uint8_t *rx_buffer_ptr;
mbed_official 579:53297373a894 606
mbed_official 579:53297373a894 607 /** Buffer pointer to where the next character will be transmitted from.
mbed_official 579:53297373a894 608 **/
mbed_official 579:53297373a894 609 volatile uint8_t *tx_buffer_ptr;
mbed_official 579:53297373a894 610 /** Remaining characters to receive. */
mbed_official 579:53297373a894 611 volatile uint16_t remaining_rx_buffer_length;
mbed_official 579:53297373a894 612 /** Remaining characters to transmit. */
mbed_official 579:53297373a894 613 volatile uint16_t remaining_tx_buffer_length;
mbed_official 579:53297373a894 614 /** Bit mask for callbacks registered. */
mbed_official 579:53297373a894 615 uint8_t callback_reg_mask;
mbed_official 579:53297373a894 616 /** Bit mask for callbacks enabled. */
mbed_official 579:53297373a894 617 uint8_t callback_enable_mask;
mbed_official 579:53297373a894 618 /** Holds the status of the ongoing or last read operation. */
mbed_official 579:53297373a894 619 volatile enum status_code rx_status;
mbed_official 579:53297373a894 620 /** Holds the status of the ongoing or last write operation. */
mbed_official 579:53297373a894 621 volatile enum status_code tx_status;
mbed_official 579:53297373a894 622 # endif
mbed_official 579:53297373a894 623 #endif
mbed_official 579:53297373a894 624 };
mbed_official 579:53297373a894 625
mbed_official 579:53297373a894 626 /**
mbed_official 579:53297373a894 627 * \name Lock/Unlock
mbed_official 579:53297373a894 628 * @{
mbed_official 579:53297373a894 629 */
mbed_official 579:53297373a894 630
mbed_official 579:53297373a894 631 /**
mbed_official 579:53297373a894 632 * \brief Attempt to get lock on driver instance
mbed_official 579:53297373a894 633 *
mbed_official 579:53297373a894 634 * This function checks the instance's lock, which indicates whether or not it
mbed_official 579:53297373a894 635 * is currently in use, and sets the lock if it was not already set.
mbed_official 579:53297373a894 636 *
mbed_official 579:53297373a894 637 * The purpose of this is to enable exclusive access to driver instances, so
mbed_official 579:53297373a894 638 * that, e.g., transactions by different services will not interfere with each
mbed_official 579:53297373a894 639 * other.
mbed_official 579:53297373a894 640 *
mbed_official 579:53297373a894 641 * \param[in,out] module Pointer to the driver instance to lock
mbed_official 579:53297373a894 642 *
mbed_official 579:53297373a894 643 * \retval STATUS_OK If the module was locked
mbed_official 579:53297373a894 644 * \retval STATUS_BUSY If the module was already locked
mbed_official 579:53297373a894 645 */
mbed_official 579:53297373a894 646 static inline enum status_code usart_lock(
mbed_official 579:53297373a894 647 struct usart_module *const module)
mbed_official 579:53297373a894 648 {
mbed_official 579:53297373a894 649 enum status_code status;
mbed_official 579:53297373a894 650
mbed_official 579:53297373a894 651 system_interrupt_enter_critical_section();
mbed_official 579:53297373a894 652
mbed_official 579:53297373a894 653 if (module->locked) {
mbed_official 579:53297373a894 654 status = STATUS_BUSY;
mbed_official 579:53297373a894 655 } else {
mbed_official 579:53297373a894 656 module->locked = true;
mbed_official 579:53297373a894 657 status = STATUS_OK;
mbed_official 579:53297373a894 658 }
mbed_official 579:53297373a894 659
mbed_official 579:53297373a894 660 system_interrupt_leave_critical_section();
mbed_official 579:53297373a894 661
mbed_official 579:53297373a894 662 return status;
mbed_official 579:53297373a894 663 }
mbed_official 579:53297373a894 664
mbed_official 579:53297373a894 665 /**
mbed_official 579:53297373a894 666 * \brief Unlock driver instance
mbed_official 579:53297373a894 667 *
mbed_official 579:53297373a894 668 * This function clears the instance lock, indicating that it is available for
mbed_official 579:53297373a894 669 * use.
mbed_official 579:53297373a894 670 *
mbed_official 579:53297373a894 671 * \param[in,out] module Pointer to the driver instance to lock
mbed_official 579:53297373a894 672 *
mbed_official 579:53297373a894 673 */
mbed_official 579:53297373a894 674 static inline void usart_unlock(struct usart_module *const module)
mbed_official 579:53297373a894 675 {
mbed_official 579:53297373a894 676 module->locked = false;
mbed_official 579:53297373a894 677 }
mbed_official 579:53297373a894 678
mbed_official 579:53297373a894 679 /** @} */
mbed_official 579:53297373a894 680
mbed_official 579:53297373a894 681 /**
mbed_official 579:53297373a894 682 * \brief Check if peripheral is busy syncing registers across clock domains
mbed_official 579:53297373a894 683 *
mbed_official 579:53297373a894 684 * Return peripheral synchronization status. If doing a non-blocking
mbed_official 579:53297373a894 685 * implementation this function can be used to check the sync state and hold of
mbed_official 579:53297373a894 686 * any new actions until sync is complete. If this functions is not run; the
mbed_official 579:53297373a894 687 * functions will block until the sync has completed.
mbed_official 579:53297373a894 688 *
mbed_official 579:53297373a894 689 * \param[in] module Pointer to peripheral module
mbed_official 579:53297373a894 690 *
mbed_official 579:53297373a894 691 * \return Peripheral sync status.
mbed_official 579:53297373a894 692 *
mbed_official 579:53297373a894 693 * \retval true Peripheral is busy syncing
mbed_official 579:53297373a894 694 * \retval false Peripheral is not busy syncing and can be read/written without
mbed_official 579:53297373a894 695 * stalling the bus.
mbed_official 579:53297373a894 696 */
mbed_official 579:53297373a894 697 static inline bool usart_is_syncing(
mbed_official 579:53297373a894 698 const struct usart_module *const module)
mbed_official 579:53297373a894 699 {
mbed_official 579:53297373a894 700 /* Sanity check arguments */
mbed_official 579:53297373a894 701 Assert(module);
mbed_official 579:53297373a894 702 Assert(module->hw);
mbed_official 579:53297373a894 703
mbed_official 579:53297373a894 704 SercomUsart *const usart_hw = &(module->hw->USART);
mbed_official 579:53297373a894 705
mbed_official 579:53297373a894 706 #ifdef FEATURE_USART_SYNC_SCHEME_V2
mbed_official 579:53297373a894 707 return (usart_hw->SYNCBUSY.reg);
mbed_official 579:53297373a894 708 #else
mbed_official 579:53297373a894 709 return (usart_hw->STATUS.reg & SERCOM_USART_STATUS_SYNCBUSY);
mbed_official 579:53297373a894 710 #endif
mbed_official 579:53297373a894 711 }
mbed_official 579:53297373a894 712
mbed_official 579:53297373a894 713 #if !defined (__DOXYGEN__)
mbed_official 579:53297373a894 714 /**
mbed_official 579:53297373a894 715 * \internal
mbed_official 579:53297373a894 716 * Waits until synchronization is complete
mbed_official 579:53297373a894 717 */
mbed_official 579:53297373a894 718 static inline void _usart_wait_for_sync(
mbed_official 579:53297373a894 719 const struct usart_module *const module)
mbed_official 579:53297373a894 720 {
mbed_official 579:53297373a894 721 /* Sanity check. */
mbed_official 579:53297373a894 722 Assert(module);
mbed_official 579:53297373a894 723
mbed_official 579:53297373a894 724 while (usart_is_syncing(module)) {
mbed_official 579:53297373a894 725 /* Wait until the synchronization is complete */
mbed_official 579:53297373a894 726 }
mbed_official 579:53297373a894 727 }
mbed_official 579:53297373a894 728 #endif
mbed_official 579:53297373a894 729
mbed_official 579:53297373a894 730 /**
mbed_official 579:53297373a894 731 * \brief Initializes the device to predefined defaults
mbed_official 579:53297373a894 732 *
mbed_official 579:53297373a894 733 * Initialize the USART device to predefined defaults:
mbed_official 579:53297373a894 734 * - 8-bit asynchronous USART
mbed_official 579:53297373a894 735 * - No parity
mbed_official 579:53297373a894 736 * - One stop bit
mbed_official 579:53297373a894 737 * - 9600 baud
mbed_official 579:53297373a894 738 * - Transmitter enabled
mbed_official 579:53297373a894 739 * - Receiver enabled
mbed_official 579:53297373a894 740 * - GCLK generator 0 as clock source
mbed_official 579:53297373a894 741 * - Default pin configuration
mbed_official 579:53297373a894 742 *
mbed_official 579:53297373a894 743 * The configuration struct will be updated with the default
mbed_official 579:53297373a894 744 * configuration.
mbed_official 579:53297373a894 745 *
mbed_official 579:53297373a894 746 * \param[in,out] config Pointer to configuration struct
mbed_official 579:53297373a894 747 */
mbed_official 579:53297373a894 748 static inline void usart_get_config_defaults(
mbed_official 579:53297373a894 749 struct usart_config *const config)
mbed_official 579:53297373a894 750 {
mbed_official 579:53297373a894 751 /* Sanity check arguments */
mbed_official 579:53297373a894 752 Assert(config);
mbed_official 579:53297373a894 753
mbed_official 579:53297373a894 754 /* Set default config in the config struct */
mbed_official 579:53297373a894 755 config->data_order = USART_DATAORDER_LSB;
mbed_official 579:53297373a894 756 config->transfer_mode = USART_TRANSFER_ASYNCHRONOUSLY;
mbed_official 579:53297373a894 757 config->parity = USART_PARITY_NONE;
mbed_official 579:53297373a894 758 config->stopbits = USART_STOPBITS_1;
mbed_official 579:53297373a894 759 config->character_size = USART_CHARACTER_SIZE_8BIT;
mbed_official 579:53297373a894 760 config->baudrate = 9600;
mbed_official 579:53297373a894 761 config->receiver_enable = true;
mbed_official 579:53297373a894 762 config->transmitter_enable = true;
mbed_official 579:53297373a894 763 config->clock_polarity_inverted = false;
mbed_official 579:53297373a894 764 config->use_external_clock = false;
mbed_official 579:53297373a894 765 config->ext_clock_freq = 0;
mbed_official 579:53297373a894 766 config->mux_setting = USART_RX_1_TX_2_XCK_3;
mbed_official 579:53297373a894 767 config->run_in_standby = false;
mbed_official 579:53297373a894 768 config->generator_source = GCLK_GENERATOR_0;
mbed_official 579:53297373a894 769 config->pinmux_pad0 = PINMUX_DEFAULT;
mbed_official 579:53297373a894 770 config->pinmux_pad1 = PINMUX_DEFAULT;
mbed_official 579:53297373a894 771 config->pinmux_pad2 = PINMUX_DEFAULT;
mbed_official 579:53297373a894 772 config->pinmux_pad3 = PINMUX_DEFAULT;
mbed_official 579:53297373a894 773 #ifdef FEATURE_USART_OVER_SAMPLE
mbed_official 579:53297373a894 774 config->sample_adjustment = USART_SAMPLE_ADJUSTMENT_7_8_9;
mbed_official 579:53297373a894 775 config->sample_rate = USART_SAMPLE_RATE_16X_ARITHMETIC;
mbed_official 579:53297373a894 776 #endif
mbed_official 579:53297373a894 777 #ifdef FEATURE_USART_LIN_SLAVE
mbed_official 579:53297373a894 778 config->lin_slave_enable = false;
mbed_official 579:53297373a894 779 #endif
mbed_official 579:53297373a894 780 #ifdef FEATURE_USART_IMMEDIATE_BUFFER_OVERFLOW_NOTIFICATION
mbed_official 579:53297373a894 781 config->immediate_buffer_overflow_notification = false;
mbed_official 579:53297373a894 782 #endif
mbed_official 579:53297373a894 783 #ifdef FEATURE_USART_START_FRAME_DECTION
mbed_official 579:53297373a894 784 config->start_frame_detection_enable = false;
mbed_official 579:53297373a894 785 #endif
mbed_official 579:53297373a894 786 #ifdef FEATURE_USART_IRDA
mbed_official 579:53297373a894 787 config->encoding_format_enable = false;
mbed_official 579:53297373a894 788 config->receive_pulse_length = 19;
mbed_official 579:53297373a894 789 #endif
mbed_official 579:53297373a894 790 #ifdef FEATURE_USART_COLLISION_DECTION
mbed_official 579:53297373a894 791 config->collision_detection_enable = false;
mbed_official 579:53297373a894 792 #endif
mbed_official 579:53297373a894 793 }
mbed_official 579:53297373a894 794
mbed_official 579:53297373a894 795 enum status_code usart_init(
mbed_official 579:53297373a894 796 struct usart_module *const module,
mbed_official 579:53297373a894 797 Sercom *const hw,
mbed_official 579:53297373a894 798 const struct usart_config *const config);
mbed_official 579:53297373a894 799
mbed_official 579:53297373a894 800 /**
mbed_official 579:53297373a894 801 * \brief Enable the module
mbed_official 579:53297373a894 802 *
mbed_official 579:53297373a894 803 * Enables the USART module.
mbed_official 579:53297373a894 804 *
mbed_official 579:53297373a894 805 * \param[in] module Pointer to USART software instance struct
mbed_official 579:53297373a894 806 */
mbed_official 579:53297373a894 807 static inline void usart_enable(
mbed_official 579:53297373a894 808 const struct usart_module *const module)
mbed_official 579:53297373a894 809 {
mbed_official 579:53297373a894 810 /* Sanity check arguments */
mbed_official 579:53297373a894 811 Assert(module);
mbed_official 579:53297373a894 812 Assert(module->hw);
mbed_official 579:53297373a894 813
mbed_official 579:53297373a894 814 /* Get a pointer to the hardware module instance */
mbed_official 579:53297373a894 815 SercomUsart *const usart_hw = &(module->hw->USART);
mbed_official 579:53297373a894 816
mbed_official 579:53297373a894 817 #if USART_CALLBACK_MODE == true
mbed_official 579:53297373a894 818 /* Enable Global interrupt for module */
mbed_official 579:53297373a894 819 system_interrupt_enable(_sercom_get_interrupt_vector(module->hw));
mbed_official 579:53297373a894 820 #endif
mbed_official 579:53297373a894 821
mbed_official 579:53297373a894 822 /* Wait until synchronization is complete */
mbed_official 579:53297373a894 823 _usart_wait_for_sync(module);
mbed_official 579:53297373a894 824
mbed_official 579:53297373a894 825 /* Enable USART module */
mbed_official 579:53297373a894 826 usart_hw->CTRLA.reg |= SERCOM_USART_CTRLA_ENABLE;
mbed_official 579:53297373a894 827 }
mbed_official 579:53297373a894 828
mbed_official 579:53297373a894 829 /**
mbed_official 579:53297373a894 830 * \brief Disable module
mbed_official 579:53297373a894 831 *
mbed_official 579:53297373a894 832 * Disables the USART module.
mbed_official 579:53297373a894 833 *
mbed_official 579:53297373a894 834 * \param[in] module Pointer to USART software instance struct
mbed_official 579:53297373a894 835 */
mbed_official 579:53297373a894 836 static inline void usart_disable(
mbed_official 579:53297373a894 837 const struct usart_module *const module)
mbed_official 579:53297373a894 838 {
mbed_official 579:53297373a894 839 /* Sanity check arguments */
mbed_official 579:53297373a894 840 Assert(module);
mbed_official 579:53297373a894 841 Assert(module->hw);
mbed_official 579:53297373a894 842
mbed_official 579:53297373a894 843 /* Get a pointer to the hardware module instance */
mbed_official 579:53297373a894 844 SercomUsart *const usart_hw = &(module->hw->USART);
mbed_official 579:53297373a894 845
mbed_official 579:53297373a894 846 #if USART_CALLBACK_MODE == true
mbed_official 579:53297373a894 847 /* Disable Global interrupt for module */
mbed_official 579:53297373a894 848 system_interrupt_disable(_sercom_get_interrupt_vector(module->hw));
mbed_official 579:53297373a894 849 #endif
mbed_official 579:53297373a894 850 /* Wait until synchronization is complete */
mbed_official 579:53297373a894 851 _usart_wait_for_sync(module);
mbed_official 579:53297373a894 852
mbed_official 579:53297373a894 853 /* Disable USART module */
mbed_official 579:53297373a894 854 usart_hw->CTRLA.reg &= ~SERCOM_USART_CTRLA_ENABLE;
mbed_official 579:53297373a894 855 }
mbed_official 579:53297373a894 856
mbed_official 579:53297373a894 857 /**
mbed_official 579:53297373a894 858 * \brief Resets the USART module
mbed_official 579:53297373a894 859 *
mbed_official 579:53297373a894 860 * Disables and resets the USART module.
mbed_official 579:53297373a894 861 *
mbed_official 579:53297373a894 862 * \param[in] module Pointer to the USART software instance struct
mbed_official 579:53297373a894 863 */
mbed_official 579:53297373a894 864 static inline void usart_reset(
mbed_official 579:53297373a894 865 const struct usart_module *const module)
mbed_official 579:53297373a894 866 {
mbed_official 579:53297373a894 867 /* Sanity check arguments */
mbed_official 579:53297373a894 868 Assert(module);
mbed_official 579:53297373a894 869 Assert(module->hw);
mbed_official 579:53297373a894 870
mbed_official 579:53297373a894 871 /* Get a pointer to the hardware module instance */
mbed_official 579:53297373a894 872 SercomUsart *const usart_hw = &(module->hw->USART);
mbed_official 579:53297373a894 873
mbed_official 579:53297373a894 874 usart_disable(module);
mbed_official 579:53297373a894 875
mbed_official 579:53297373a894 876 /* Wait until synchronization is complete */
mbed_official 579:53297373a894 877 _usart_wait_for_sync(module);
mbed_official 579:53297373a894 878
mbed_official 579:53297373a894 879 /* Reset module */
mbed_official 579:53297373a894 880 usart_hw->CTRLA.reg = SERCOM_USART_CTRLA_SWRST;
mbed_official 579:53297373a894 881 }
mbed_official 579:53297373a894 882
mbed_official 579:53297373a894 883 /**
mbed_official 579:53297373a894 884 * \name Writing and Reading
mbed_official 579:53297373a894 885 * @{
mbed_official 579:53297373a894 886 */
mbed_official 579:53297373a894 887 enum status_code usart_write_wait(
mbed_official 579:53297373a894 888 struct usart_module *const module,
mbed_official 579:53297373a894 889 const uint16_t tx_data);
mbed_official 579:53297373a894 890
mbed_official 579:53297373a894 891 enum status_code usart_read_wait(
mbed_official 579:53297373a894 892 struct usart_module *const module,
mbed_official 579:53297373a894 893 uint16_t *const rx_data);
mbed_official 579:53297373a894 894
mbed_official 579:53297373a894 895 enum status_code usart_write_buffer_wait(
mbed_official 579:53297373a894 896 struct usart_module *const module,
mbed_official 579:53297373a894 897 const uint8_t *tx_data,
mbed_official 579:53297373a894 898 uint16_t length);
mbed_official 579:53297373a894 899
mbed_official 579:53297373a894 900 enum status_code usart_read_buffer_wait(
mbed_official 579:53297373a894 901 struct usart_module *const module,
mbed_official 579:53297373a894 902 uint8_t *rx_data,
mbed_official 579:53297373a894 903 uint16_t length);
mbed_official 579:53297373a894 904 /** @} */
mbed_official 579:53297373a894 905
mbed_official 579:53297373a894 906 /**
mbed_official 579:53297373a894 907 * \name Enabling/Disabling Receiver and Transmitter
mbed_official 579:53297373a894 908 * @{
mbed_official 579:53297373a894 909 */
mbed_official 579:53297373a894 910
mbed_official 579:53297373a894 911 /**
mbed_official 579:53297373a894 912 * \brief Enable Transceiver
mbed_official 579:53297373a894 913 *
mbed_official 579:53297373a894 914 * Enable the given transceiver. Either RX or TX.
mbed_official 579:53297373a894 915 *
mbed_official 579:53297373a894 916 * \param[in] module Pointer to USART software instance struct
mbed_official 579:53297373a894 917 * \param[in] transceiver_type Transceiver type
mbed_official 579:53297373a894 918 */
mbed_official 579:53297373a894 919 static inline void usart_enable_transceiver(
mbed_official 579:53297373a894 920 struct usart_module *const module,
mbed_official 579:53297373a894 921 enum usart_transceiver_type transceiver_type)
mbed_official 579:53297373a894 922 {
mbed_official 579:53297373a894 923 /* Sanity check arguments */
mbed_official 579:53297373a894 924 Assert(module);
mbed_official 579:53297373a894 925 Assert(module->hw);
mbed_official 579:53297373a894 926
mbed_official 579:53297373a894 927 /* Get a pointer to the hardware module instance */
mbed_official 579:53297373a894 928 SercomUsart *const usart_hw = &(module->hw->USART);
mbed_official 579:53297373a894 929
mbed_official 579:53297373a894 930 /* Wait until synchronization is complete */
mbed_official 579:53297373a894 931 _usart_wait_for_sync(module);
mbed_official 579:53297373a894 932
mbed_official 579:53297373a894 933 switch (transceiver_type) {
mbed_official 579:53297373a894 934 case USART_TRANSCEIVER_RX:
mbed_official 579:53297373a894 935 /* Enable RX */
mbed_official 579:53297373a894 936 usart_hw->CTRLB.reg |= SERCOM_USART_CTRLB_RXEN;
mbed_official 579:53297373a894 937 module->receiver_enabled = true;
mbed_official 579:53297373a894 938 break;
mbed_official 579:53297373a894 939
mbed_official 579:53297373a894 940 case USART_TRANSCEIVER_TX:
mbed_official 579:53297373a894 941 /* Enable TX */
mbed_official 579:53297373a894 942 usart_hw->CTRLB.reg |= SERCOM_USART_CTRLB_TXEN;
mbed_official 579:53297373a894 943 module->transmitter_enabled = true;
mbed_official 579:53297373a894 944 break;
mbed_official 579:53297373a894 945 }
mbed_official 579:53297373a894 946 }
mbed_official 579:53297373a894 947
mbed_official 579:53297373a894 948 /**
mbed_official 579:53297373a894 949 * \brief Disable Transceiver
mbed_official 579:53297373a894 950 *
mbed_official 579:53297373a894 951 * Disable the given transceiver (RX or TX).
mbed_official 579:53297373a894 952 *
mbed_official 579:53297373a894 953 * \param[in] module Pointer to USART software instance struct
mbed_official 579:53297373a894 954 * \param[in] transceiver_type Transceiver type
mbed_official 579:53297373a894 955 */
mbed_official 579:53297373a894 956 static inline void usart_disable_transceiver(
mbed_official 579:53297373a894 957 struct usart_module *const module,
mbed_official 579:53297373a894 958 enum usart_transceiver_type transceiver_type)
mbed_official 579:53297373a894 959 {
mbed_official 579:53297373a894 960 /* Sanity check arguments */
mbed_official 579:53297373a894 961 Assert(module);
mbed_official 579:53297373a894 962 Assert(module->hw);
mbed_official 579:53297373a894 963
mbed_official 579:53297373a894 964 /* Get a pointer to the hardware module instance */
mbed_official 579:53297373a894 965 SercomUsart *const usart_hw = &(module->hw->USART);
mbed_official 579:53297373a894 966
mbed_official 579:53297373a894 967 /* Wait until synchronization is complete */
mbed_official 579:53297373a894 968 _usart_wait_for_sync(module);
mbed_official 579:53297373a894 969
mbed_official 579:53297373a894 970 switch (transceiver_type) {
mbed_official 579:53297373a894 971 case USART_TRANSCEIVER_RX:
mbed_official 579:53297373a894 972 /* Disable RX */
mbed_official 579:53297373a894 973 usart_hw->CTRLB.reg &= ~SERCOM_USART_CTRLB_RXEN;
mbed_official 579:53297373a894 974 module->receiver_enabled = false;
mbed_official 579:53297373a894 975 break;
mbed_official 579:53297373a894 976
mbed_official 579:53297373a894 977 case USART_TRANSCEIVER_TX:
mbed_official 579:53297373a894 978 /* Disable TX */
mbed_official 579:53297373a894 979 usart_hw->CTRLB.reg &= ~SERCOM_USART_CTRLB_TXEN;
mbed_official 579:53297373a894 980 module->transmitter_enabled = false;
mbed_official 579:53297373a894 981 break;
mbed_official 579:53297373a894 982 }
mbed_official 579:53297373a894 983 }
mbed_official 579:53297373a894 984
mbed_official 579:53297373a894 985 /** @} */
mbed_official 579:53297373a894 986
mbed_official 579:53297373a894 987 #ifdef __cplusplus
mbed_official 579:53297373a894 988 }
mbed_official 579:53297373a894 989 #endif
mbed_official 579:53297373a894 990
mbed_official 579:53297373a894 991 /** @} */
mbed_official 579:53297373a894 992
mbed_official 579:53297373a894 993 /**
mbed_official 579:53297373a894 994 * \page asfdoc_sam0_sercom_usart_extra Extra Information for SERCOM USART Driver
mbed_official 579:53297373a894 995 *
mbed_official 579:53297373a894 996 * \section asfdoc_sam0_sercom_usart_extra_acronyms Acronyms
mbed_official 579:53297373a894 997 *
mbed_official 579:53297373a894 998 * Below is a table listing the acronyms used in this module, along with their
mbed_official 579:53297373a894 999 * intended meanings.
mbed_official 579:53297373a894 1000 *
mbed_official 579:53297373a894 1001 * <table>
mbed_official 579:53297373a894 1002 * <tr>
mbed_official 579:53297373a894 1003 * <th>Acronym</th>
mbed_official 579:53297373a894 1004 * <th>Description</th>
mbed_official 579:53297373a894 1005 * </tr>
mbed_official 579:53297373a894 1006 * <tr>
mbed_official 579:53297373a894 1007 * <td>SERCOM</td>
mbed_official 579:53297373a894 1008 * <td>Serial Communication Interface</td>
mbed_official 579:53297373a894 1009 * </tr>
mbed_official 579:53297373a894 1010 * <tr>
mbed_official 579:53297373a894 1011 * <td>USART</td>
mbed_official 579:53297373a894 1012 * <td>Universal Synchronous and Asynchronous Serial Receiver and Transmitter</td>
mbed_official 579:53297373a894 1013 * </tr>
mbed_official 579:53297373a894 1014 * <tr>
mbed_official 579:53297373a894 1015 * <td>LSB</td>
mbed_official 579:53297373a894 1016 * <td>Least Significant Bit</td>
mbed_official 579:53297373a894 1017 * </tr>
mbed_official 579:53297373a894 1018 * <tr>
mbed_official 579:53297373a894 1019 * <td>MSB</td>
mbed_official 579:53297373a894 1020 * <td>Most Significant Bit</td>
mbed_official 579:53297373a894 1021 * </tr>
mbed_official 579:53297373a894 1022 * <tr>
mbed_official 579:53297373a894 1023 * <td>DMA</td>
mbed_official 579:53297373a894 1024 * <td>Direct Memory Access</td>
mbed_official 579:53297373a894 1025 * </tr>
mbed_official 579:53297373a894 1026 * </table>
mbed_official 579:53297373a894 1027 *
mbed_official 579:53297373a894 1028 *
mbed_official 579:53297373a894 1029 * \section asfdoc_sam0_sercom_usart_extra_dependencies Dependencies
mbed_official 579:53297373a894 1030 * This driver has the following dependencies:
mbed_official 579:53297373a894 1031 *
mbed_official 579:53297373a894 1032 * - \ref asfdoc_sam0_system_pinmux_group "System Pin Multiplexer Driver"
mbed_official 579:53297373a894 1033 * - \ref asfdoc_sam0_system_clock_group "System clock configuration"
mbed_official 579:53297373a894 1034 *
mbed_official 579:53297373a894 1035 *
mbed_official 579:53297373a894 1036 * \section asfdoc_sam0_sercom_usart_extra_errata Errata
mbed_official 579:53297373a894 1037 * There are no errata related to this driver.
mbed_official 579:53297373a894 1038 *
mbed_official 579:53297373a894 1039 *
mbed_official 579:53297373a894 1040 * \section asfdoc_sam0_sercom_usart_extra_history Module History
mbed_official 579:53297373a894 1041 * An overview of the module history is presented in the table below, with
mbed_official 579:53297373a894 1042 * details on the enhancements and fixes made to the module since its first
mbed_official 579:53297373a894 1043 * release. The current version of this corresponds to the newest version in
mbed_official 579:53297373a894 1044 * the table.
mbed_official 579:53297373a894 1045 *
mbed_official 579:53297373a894 1046 * <table>
mbed_official 579:53297373a894 1047 * <tr>
mbed_official 579:53297373a894 1048 * <th>Changelog</th>
mbed_official 579:53297373a894 1049 * </tr>
mbed_official 579:53297373a894 1050 * <tr>
mbed_official 579:53297373a894 1051 * <td>Add support for SAML21 (same features as SAMD21)</td>
mbed_official 579:53297373a894 1052 * </tr>
mbed_official 579:53297373a894 1053 * <tr>
mbed_official 579:53297373a894 1054 * <td>Add support for SAMD10/D11 (same features as SAMD21)</td>
mbed_official 579:53297373a894 1055 * </tr>
mbed_official 579:53297373a894 1056 * <tr>
mbed_official 579:53297373a894 1057 * <td>Add support for SAMR21 (same features as SAMD21)</td>
mbed_official 579:53297373a894 1058 * </tr>
mbed_official 579:53297373a894 1059 * <tr>
mbed_official 579:53297373a894 1060 * <td>Add support for SAMD21 and added new feature as below:
mbed_official 579:53297373a894 1061 \li Oversample
mbed_official 579:53297373a894 1062 \li Buffer overflow notification
mbed_official 579:53297373a894 1063 \li Irda
mbed_official 579:53297373a894 1064 \li Lin slave
mbed_official 579:53297373a894 1065 \li Start frame detection
mbed_official 579:53297373a894 1066 \li Hardware flow control
mbed_official 579:53297373a894 1067 \li Collision detection
mbed_official 579:53297373a894 1068 \li DMA support </td>
mbed_official 579:53297373a894 1069 * </tr>
mbed_official 579:53297373a894 1070 * <tr>
mbed_official 579:53297373a894 1071 * <td>\li Added new \c transmitter_enable and \c receiver_enable Boolean
mbed_official 579:53297373a894 1072 * values to \c struct usart_config
mbed_official 579:53297373a894 1073 * \li Altered \c usart_write_* and usart_read_* functions to abort with
mbed_official 579:53297373a894 1074 * an error code if the relevant transceiver is not enabled
mbed_official 579:53297373a894 1075 * \li Fixed \c usart_write_buffer_wait() and \c usart_read_buffer_wait()
mbed_official 579:53297373a894 1076 * not aborting correctly when a timeout condition occurs</td>
mbed_official 579:53297373a894 1077 * </tr>
mbed_official 579:53297373a894 1078 * <tr>
mbed_official 579:53297373a894 1079 * <td>Initial Release</td>
mbed_official 579:53297373a894 1080 * </tr>
mbed_official 579:53297373a894 1081 * </table>
mbed_official 579:53297373a894 1082 */
mbed_official 579:53297373a894 1083
mbed_official 579:53297373a894 1084 /**
mbed_official 579:53297373a894 1085 * \page asfdoc_sam0_sercom_usart_exqsg Examples for SERCOM USART Driver
mbed_official 579:53297373a894 1086 *
mbed_official 579:53297373a894 1087 * This is a list of the available Quick Start guides (QSGs) and example
mbed_official 579:53297373a894 1088 * applications for \ref asfdoc_sam0_sercom_usart_group. QSGs are simple examples with
mbed_official 579:53297373a894 1089 * step-by-step instructions to configure and use this driver in a selection of
mbed_official 579:53297373a894 1090 * use cases. Note that QSGs can be compiled as a standalone application or be
mbed_official 579:53297373a894 1091 * added to the user application.
mbed_official 579:53297373a894 1092 *
mbed_official 579:53297373a894 1093 * - \subpage asfdoc_sam0_sercom_usart_basic_use_case
mbed_official 579:53297373a894 1094 * \if USART_CALLBACK_MODE
mbed_official 579:53297373a894 1095 * - \subpage asfdoc_sam0_sercom_usart_callback_use_case
mbed_official 579:53297373a894 1096 * \endif
mbed_official 579:53297373a894 1097 * - \subpage asfdoc_sam0_sercom_usart_dma_use_case
mbed_official 579:53297373a894 1098 */
mbed_official 579:53297373a894 1099
mbed_official 579:53297373a894 1100 /**
mbed_official 579:53297373a894 1101 * \page asfdoc_sam0_sercom_usart_mux_settings SERCOM USART MUX Settings
mbed_official 579:53297373a894 1102 *
mbed_official 579:53297373a894 1103 * The following lists the possible internal SERCOM module pad function
mbed_official 579:53297373a894 1104 * assignments, for the four SERCOM pads when in USART mode. Note that this is
mbed_official 579:53297373a894 1105 * in addition to the physical GPIO pin MUX of the device, and can be used in
mbed_official 579:53297373a894 1106 * conjunction to optimize the serial data pin-out.
mbed_official 579:53297373a894 1107 *
mbed_official 579:53297373a894 1108 * When TX and RX are connected to the same pin, the USART will operate in
mbed_official 579:53297373a894 1109 * half-duplex mode if both the transmitter and receivers are enabled.
mbed_official 579:53297373a894 1110 *
mbed_official 579:53297373a894 1111 * \note When RX and XCK are connected to the same pin, the receiver must not
mbed_official 579:53297373a894 1112 * be enabled if the USART is configured to use an external clock.
mbed_official 579:53297373a894 1113 *
mbed_official 579:53297373a894 1114 *
mbed_official 579:53297373a894 1115 * <table>
mbed_official 579:53297373a894 1116 * <tr>
mbed_official 579:53297373a894 1117 * <th>MUX/Pad</th>
mbed_official 579:53297373a894 1118 * <th>PAD 0</th>
mbed_official 579:53297373a894 1119 * <th>PAD 1</th>
mbed_official 579:53297373a894 1120 * <th>PAD 2</th>
mbed_official 579:53297373a894 1121 * <th>PAD 3</th>
mbed_official 579:53297373a894 1122 * </tr>
mbed_official 579:53297373a894 1123 * <tr>
mbed_official 579:53297373a894 1124 * <td>RX_0_TX_0_XCK_1</td>
mbed_official 579:53297373a894 1125 * <td>TX / RX</td>
mbed_official 579:53297373a894 1126 * <td>XCK</td>
mbed_official 579:53297373a894 1127 * <td>-</td>
mbed_official 579:53297373a894 1128 * <td>-</td>
mbed_official 579:53297373a894 1129 * </tr>
mbed_official 579:53297373a894 1130 * <tr>
mbed_official 579:53297373a894 1131 * <td>RX_0_TX_2_XCK_3</td>
mbed_official 579:53297373a894 1132 * <td>RX</td>
mbed_official 579:53297373a894 1133 * <td>-</td>
mbed_official 579:53297373a894 1134 * <td>TX</td>
mbed_official 579:53297373a894 1135 * <td>XCK</td>
mbed_official 579:53297373a894 1136 * </tr>
mbed_official 579:53297373a894 1137 * <tr>
mbed_official 579:53297373a894 1138 * <td>RX_1_TX_0_XCK_1</td>
mbed_official 579:53297373a894 1139 * <td>TX</td>
mbed_official 579:53297373a894 1140 * <td>RX / XCK</td>
mbed_official 579:53297373a894 1141 * <td>-</td>
mbed_official 579:53297373a894 1142 * <td>-</td>
mbed_official 579:53297373a894 1143 * </tr>
mbed_official 579:53297373a894 1144 * <tr>
mbed_official 579:53297373a894 1145 * <td>RX_1_TX_2_XCK_3</td>
mbed_official 579:53297373a894 1146 * <td>-</td>
mbed_official 579:53297373a894 1147 * <td>RX</td>
mbed_official 579:53297373a894 1148 * <td>TX</td>
mbed_official 579:53297373a894 1149 * <td>XCK</td>
mbed_official 579:53297373a894 1150 * </tr>
mbed_official 579:53297373a894 1151 * <tr>
mbed_official 579:53297373a894 1152 * <td>RX_2_TX_0_XCK_1</td>
mbed_official 579:53297373a894 1153 * <td>TX</td>
mbed_official 579:53297373a894 1154 * <td>XCK</td>
mbed_official 579:53297373a894 1155 * <td>RX</td>
mbed_official 579:53297373a894 1156 * <td>-</td>
mbed_official 579:53297373a894 1157 * </tr>
mbed_official 579:53297373a894 1158 * <tr>
mbed_official 579:53297373a894 1159 * <td>RX_2_TX_2_XCK_3</td>
mbed_official 579:53297373a894 1160 * <td>-</td>
mbed_official 579:53297373a894 1161 * <td>-</td>
mbed_official 579:53297373a894 1162 * <td>TX / RX</td>
mbed_official 579:53297373a894 1163 * <td>XCK</td>
mbed_official 579:53297373a894 1164 * </tr>
mbed_official 579:53297373a894 1165 * <tr>
mbed_official 579:53297373a894 1166 * <td>RX_3_TX_0_XCK_1</td>
mbed_official 579:53297373a894 1167 * <td>TX</td>
mbed_official 579:53297373a894 1168 * <td>XCK</td>
mbed_official 579:53297373a894 1169 * <td>-</td>
mbed_official 579:53297373a894 1170 * <td>RX</td>
mbed_official 579:53297373a894 1171 * </tr>
mbed_official 579:53297373a894 1172 * <tr>
mbed_official 579:53297373a894 1173 * <td>RX_3_TX_2_XCK_3</td>
mbed_official 579:53297373a894 1174 * <td>-</td>
mbed_official 579:53297373a894 1175 * <td>-</td>
mbed_official 579:53297373a894 1176 * <td>TX</td>
mbed_official 579:53297373a894 1177 * <td>RX / XCK</td>
mbed_official 579:53297373a894 1178 * </tr>
mbed_official 579:53297373a894 1179 * </table>
mbed_official 579:53297373a894 1180 *
mbed_official 579:53297373a894 1181 * \page asfdoc_sam0_sercom_usart_document_revision_history Document Revision History
mbed_official 579:53297373a894 1182 *
mbed_official 579:53297373a894 1183 * <table>
mbed_official 579:53297373a894 1184 * <tr>
mbed_official 579:53297373a894 1185 * <th>Doc. Rev.</td>
mbed_official 579:53297373a894 1186 * <th>Date</td>
mbed_official 579:53297373a894 1187 * <th>Comments</td>
mbed_official 579:53297373a894 1188 * </tr>
mbed_official 579:53297373a894 1189 * <tr>
mbed_official 579:53297373a894 1190 * <td>F</td>
mbed_official 579:53297373a894 1191 * <td>11/2014</td>
mbed_official 579:53297373a894 1192 * <td>Add support for SAML21.</td>
mbed_official 579:53297373a894 1193 * </tr>
mbed_official 579:53297373a894 1194 * <tr>
mbed_official 579:53297373a894 1195 * <td>E</td>
mbed_official 579:53297373a894 1196 * <td>12/2014</td>
mbed_official 579:53297373a894 1197 * <td>Add support for SAMR21 and SAMD10/D11.</td>
mbed_official 579:53297373a894 1198 * </tr>
mbed_official 579:53297373a894 1199 * <tr>
mbed_official 579:53297373a894 1200 * <td>D</td>
mbed_official 579:53297373a894 1201 * <td>01/2014</td>
mbed_official 579:53297373a894 1202 * <td>Add support for SAMD21.</td>
mbed_official 579:53297373a894 1203 * </tr>
mbed_official 579:53297373a894 1204 * <tr>
mbed_official 579:53297373a894 1205 * <td>C</td>
mbed_official 579:53297373a894 1206 * <td>10/2013</td>
mbed_official 579:53297373a894 1207 * <td>Replaced the pad multiplexing documentation with a condensed table.</td>
mbed_official 579:53297373a894 1208 * </tr>
mbed_official 579:53297373a894 1209 * <tr>
mbed_official 579:53297373a894 1210 * <td>B</td>
mbed_official 579:53297373a894 1211 * <td>06/2013</td>
mbed_official 579:53297373a894 1212 * <td>Corrected documentation typos.</td>
mbed_official 579:53297373a894 1213 * </tr>
mbed_official 579:53297373a894 1214 * <tr>
mbed_official 579:53297373a894 1215 * <td>A</td>
mbed_official 579:53297373a894 1216 * <td>06/2013</td>
mbed_official 579:53297373a894 1217 * <td>Initial release</td>
mbed_official 579:53297373a894 1218 * </tr>
mbed_official 579:53297373a894 1219 * </table>
mbed_official 579:53297373a894 1220 */
mbed_official 579:53297373a894 1221 #endif /* USART_H_INCLUDED */