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

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_SAMD21G18A/TARGET_Atmel/TARGET_SAM_CortexM0P/drivers/sercom/usart/usart.h@111:4336505e4b1c
mbed library. Release version 164

Who changed what in which revision?

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