Microchip® Advanced Software Framework

usart.h File Reference

SAM SERCOM USART Driver.

Copyright (c) 2012-2020 Microchip Technology Inc. and its subsidiaries.

#include <compiler.h>
#include <sercom.h>
#include <pinmux.h>
#include <sercom_interrupt.h>

Data Structures

struct  iso7816_config_t
 ISO7816 configuration struct. More...
 
struct  usart_config
 USART configuration struct. More...
 
struct  usart_module
 SERCOM USART driver software device instance structure. More...
 

Macros

#define PINMUX_DEFAULT   0
 Default pinmux. More...
 
#define PINMUX_UNUSED   0xFFFFFFFF
 Unused pinmux. More...
 
#define USART_TIMEOUT   0xFFFF
 USART timeout value. More...
 
Driver Feature Definition

Define SERCOM USART features set according to different device family.

#define FEATURE_USART_SYNC_SCHEME_V2
 USART sync scheme version 2. More...
 
#define FEATURE_USART_OVER_SAMPLE
 USART oversampling. More...
 
#define FEATURE_USART_HARDWARE_FLOW_CONTROL
 USART hardware control flow. More...
 
#define FEATURE_USART_IRDA
 IrDA mode. More...
 
#define FEATURE_USART_LIN_SLAVE
 LIN slave mode. More...
 
#define FEATURE_USART_COLLISION_DECTION
 USART collision detection. More...
 
#define FEATURE_USART_START_FRAME_DECTION
 USART start frame detection. More...
 
#define FEATURE_USART_IMMEDIATE_BUFFER_OVERFLOW_NOTIFICATION
 USART start buffer overflow notification. More...
 
#define FEATURE_USART_ISO7816
 ISO7816 for smart card interfacing. More...
 
#define FEATURE_USART_LIN_MASTER
 LIN master mode. More...
 
#define FEATURE_USART_RS485
 RS485 mode. More...
 

Typedefs

typedef void(* usart_callback_t )(struct usart_module *const module)
 USART callback type. More...
 

Enumerations

enum  iso7816_guard_time {
  ISO7816_GUARD_TIME_2_BIT = 2,
  ISO7816_GUARD_TIME_3_BIT,
  ISO7816_GUARD_TIME_4_BIT,
  ISO7816_GUARD_TIME_5_BIT,
  ISO7816_GUARD_TIME_6_BIT,
  ISO7816_GUARD_TIME_7_BIT
}
 ISO7816 guard time. More...
 
enum  iso7816_inhibit_nack {
  ISO7816_INHIBIT_NACK_DISABLE = (0x0ul << SERCOM_USART_CTRLC_INACK_Pos),
  ISO7816_INHIBIT_NACK_ENABLE = SERCOM_USART_CTRLC_INACK
}
 ISO7816 receive NACK inhibit. More...
 
enum  iso7816_protocol_type {
  ISO7816_PROTOCOL_T_0 = SERCOM_USART_CTRLA_CMODE,
  ISO7816_PROTOCOL_T_1 = (0x0ul << SERCOM_USART_CTRLA_CMODE_Pos)
}
 ISO7816 protocol type. More...
 
enum  iso7816_successive_recv_nack {
  ISO7816_SUCCESSIVE_RECV_NACK_DISABLE = (0x0ul << SERCOM_USART_CTRLC_INACK_Pos),
  ISO7816_SUCCESSIVE_RECV_NACK_ENABLE = SERCOM_USART_CTRLC_DSNACK
}
 ISO7816 disable successive receive NACK. More...
 
enum  lin_master_break_length {
  LIN_MASTER_BREAK_LENGTH_13_BIT = SERCOM_USART_CTRLC_BRKLEN(0x0),
  LIN_MASTER_BREAK_LENGTH_17_BIT = SERCOM_USART_CTRLC_BRKLEN(0x1),
  LIN_MASTER_BREAK_LENGTH_21_BIT = SERCOM_USART_CTRLC_BRKLEN(0x2),
  LIN_MASTER_BREAK_LENGTH_26_BIT = SERCOM_USART_CTRLC_BRKLEN(0x3)
}
 LIN master break length. More...
 
enum  lin_master_cmd {
  LIN_MASTER_SOFTWARE_CONTROL_TRANSMIT_CMD = SERCOM_USART_CTRLB_LINCMD(0x01),
  LIN_MASTER_AUTO_TRANSMIT_CMD = SERCOM_USART_CTRLB_LINCMD(0x02)
}
 LIN master command enum. More...
 
enum  lin_master_header_delay {
  LIN_MASTER_HEADER_DELAY_0 = SERCOM_USART_CTRLC_HDRDLY(0x0),
  LIN_MASTER_HEADER_DELAY_1 = SERCOM_USART_CTRLC_HDRDLY(0x01),
  LIN_MASTER_HEADER_DELAY_2 = SERCOM_USART_CTRLC_HDRDLY(0x02),
  LIN_MASTER_HEADER_DELAY_3 = SERCOM_USART_CTRLC_HDRDLY(0x03)
}
 LIN master header delay. More...
 
enum  lin_node_type {
  LIN_MASTER_NODE = SERCOM_USART_CTRLA_FORM(0x02),
  LIN_SLAVE_NODE = SERCOM_USART_CTRLA_FORM(0x04),
  LIN_INVALID_MODE = SERCOM_USART_CTRLA_FORM(0x00)
}
 LIN node type. More...
 
enum  rs485_guard_time {
  RS485_GUARD_TIME_0_BIT = 0,
  RS485_GUARD_TIME_1_BIT,
  RS485_GUARD_TIME_2_BIT,
  RS485_GUARD_TIME_3_BIT,
  RS485_GUARD_TIME_4_BIT,
  RS485_GUARD_TIME_5_BIT,
  RS485_GUARD_TIME_6_BIT,
  RS485_GUARD_TIME_7_BIT
}
 RS485 Guard Time. More...
 
enum  usart_callback {
  USART_CALLBACK_BUFFER_TRANSMITTED,
  USART_CALLBACK_BUFFER_RECEIVED,
  USART_CALLBACK_ERROR,
  USART_CALLBACK_BREAK_RECEIVED,
  USART_CALLBACK_CTS_INPUT_CHANGE,
  USART_CALLBACK_START_RECEIVED
}
 USART callback enum. More...
 
enum  usart_character_size {
  USART_CHARACTER_SIZE_5BIT = SERCOM_USART_CTRLB_CHSIZE(5),
  USART_CHARACTER_SIZE_6BIT = SERCOM_USART_CTRLB_CHSIZE(6),
  USART_CHARACTER_SIZE_7BIT = SERCOM_USART_CTRLB_CHSIZE(7),
  USART_CHARACTER_SIZE_8BIT = SERCOM_USART_CTRLB_CHSIZE(0),
  USART_CHARACTER_SIZE_9BIT = SERCOM_USART_CTRLB_CHSIZE(1)
}
 USART Character Size. More...
 
enum  usart_dataorder {
  USART_DATAORDER_MSB = 0,
  USART_DATAORDER_LSB = SERCOM_USART_CTRLA_DORD
}
 USART Data Order enum. More...
 
enum  usart_parity {
  USART_PARITY_ODD = SERCOM_USART_CTRLB_PMODE,
  USART_PARITY_EVEN = 0,
  USART_PARITY_NONE = 0xFF
}
 USART Parity enum. More...
 
enum  usart_sample_adjustment {
  USART_SAMPLE_ADJUSTMENT_7_8_9 = SERCOM_USART_CTRLA_SAMPA(0),
  USART_SAMPLE_ADJUSTMENT_9_10_11 = SERCOM_USART_CTRLA_SAMPA(1),
  USART_SAMPLE_ADJUSTMENT_11_12_13 = SERCOM_USART_CTRLA_SAMPA(2),
  USART_SAMPLE_ADJUSTMENT_13_14_15 = SERCOM_USART_CTRLA_SAMPA(3)
}
 USART Sample Adjustment. More...
 
enum  usart_sample_rate {
  USART_SAMPLE_RATE_16X_ARITHMETIC = SERCOM_USART_CTRLA_SAMPR(0),
  USART_SAMPLE_RATE_16X_FRACTIONAL = SERCOM_USART_CTRLA_SAMPR(1),
  USART_SAMPLE_RATE_8X_ARITHMETIC = SERCOM_USART_CTRLA_SAMPR(2),
  USART_SAMPLE_RATE_8X_FRACTIONAL = SERCOM_USART_CTRLA_SAMPR(3),
  USART_SAMPLE_RATE_3X_ARITHMETIC = SERCOM_USART_CTRLA_SAMPR(4)
}
 USART Sample Rate. More...
 
enum  usart_signal_mux_settings {
  USART_RX_0_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(0) | SERCOM_USART_CTRLA_TXPO(0)),
  USART_RX_0_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(0) | SERCOM_USART_CTRLA_TXPO(1)),
  USART_RX_0_TX_0_RTS_2_CTS_3 = (SERCOM_USART_CTRLA_RXPO(0) | SERCOM_USART_CTRLA_TXPO(2)),
  USART_RX_1_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(1) | SERCOM_USART_CTRLA_TXPO(0)),
  USART_RX_1_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(1) | SERCOM_USART_CTRLA_TXPO(1)),
  USART_RX_1_TX_0_RTS_2_CTS_3 = (SERCOM_USART_CTRLA_RXPO(1) | SERCOM_USART_CTRLA_TXPO(2)),
  USART_RX_2_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(2) | SERCOM_USART_CTRLA_TXPO(0)),
  USART_RX_2_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(2) | SERCOM_USART_CTRLA_TXPO(1)),
  USART_RX_2_TX_0_RTS_2_CTS_3 = (SERCOM_USART_CTRLA_RXPO(2) | SERCOM_USART_CTRLA_TXPO(2)),
  USART_RX_3_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO(0)),
  USART_RX_3_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO(1)),
  USART_RX_3_TX_0_RTS_2_CTS_3 = (SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO(2)),
  USART_RX_0_TX_0_XCK_1_TE_2 = (SERCOM_USART_CTRLA_RXPO(0) | SERCOM_USART_CTRLA_TXPO(3)),
  USART_RX_1_TX_0_XCK_1_TE_2 = (SERCOM_USART_CTRLA_RXPO(1) | SERCOM_USART_CTRLA_TXPO(3)),
  USART_RX_2_TX_0_XCK_1_TE_2 = (SERCOM_USART_CTRLA_RXPO(2) | SERCOM_USART_CTRLA_TXPO(3)),
  USART_RX_3_TX_0_XCK_1_TE_2 = (SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO(3))
}
 USART signal MUX settings. More...
 
enum  usart_stopbits {
  USART_STOPBITS_1 = 0,
  USART_STOPBITS_2 = SERCOM_USART_CTRLB_SBMODE
}
 USART Stop Bits enum. More...
 
enum  usart_transceiver_type {
  USART_TRANSCEIVER_RX,
  USART_TRANSCEIVER_TX
}
 USART Transceiver. More...
 
enum  usart_transfer_mode {
  USART_TRANSFER_SYNCHRONOUSLY = (SERCOM_USART_CTRLA_CMODE),
  USART_TRANSFER_ASYNCHRONOUSLY = (0x0ul << SERCOM_USART_CTRLA_CMODE_Pos)
}
 USART Transfer mode enum. More...
 

Functions

static void usart_disable (const struct usart_module *const module)
 Disable module. More...
 
static void usart_enable (const struct usart_module *const module)
 Enable the module. More...
 
static void usart_get_config_defaults (struct usart_config *const config)
 Initializes the device to predefined defaults. More...
 
enum status_code usart_init (struct usart_module *const module, Sercom *const hw, const struct usart_config *const config)
 Initializes the device. More...
 
static bool usart_is_syncing (const struct usart_module *const module)
 Check if peripheral is busy syncing registers across clock domains. More...
 
static void usart_reset (const struct usart_module *const module)
 Resets the USART module. More...
 
Lock/Unlock
static enum status_code usart_lock (struct usart_module *const module)
 Attempt to get lock on driver instance. More...
 
static void usart_unlock (struct usart_module *const module)
 Unlock driver instance. More...
 
Writing and Reading
enum status_code usart_write_wait (struct usart_module *const module, const uint16_t tx_data)
 Transmit a character via the USART. More...
 
enum status_code usart_read_wait (struct usart_module *const module, uint16_t *const rx_data)
 Receive a character via the USART. More...
 
enum status_code usart_write_buffer_wait (struct usart_module *const module, const uint8_t *tx_data, uint16_t length)
 Transmit a buffer of characters via the USART. More...
 
enum status_code usart_read_buffer_wait (struct usart_module *const module, uint8_t *rx_data, uint16_t length)
 Receive a buffer of length characters via the USART. More...
 
Enabling/Disabling Receiver and Transmitter
static void usart_enable_transceiver (struct usart_module *const module, enum usart_transceiver_type transceiver_type)
 Enable Transceiver. More...
 
static void usart_disable_transceiver (struct usart_module *const module, enum usart_transceiver_type transceiver_type)
 Disable Transceiver. More...
 
LIN Master Command and Status
static void lin_master_send_cmd (struct usart_module *const module, enum lin_master_cmd cmd)
 Sending LIN command. More...
 
static bool lin_master_transmission_status (struct usart_module *const module)
 Get LIN transmission status. More...