SAM4SD32 (SAM4S-EK2)
Loading...
Searching...
No Matches
usart.c File Reference

Universal Synchronous Asynchronous Receiver Transmitter (USART) driver for SAM. More...

#include "usart.h"

Go to the source code of this file.

Macros

#define HIGH_FRQ_SAMPLE_DIV   16
#define ISO7816_T_0   0
#define ISO7816_T_1   1
#define LOW_FRQ_SAMPLE_DIV   8
#define MAX_CD_VALUE   US_BRGR_CD_Msk
#define MAX_TRAN_GUARD_TIME   US_TTGR_TG_Msk
#define MIN_CD_VALUE   0x01
#define MIN_CD_VALUE_SPI   0x04
#define US_WPMR_WPKEY_PASSWD   US_WPMR_WPKEY(0x555341U)
#define USART_PARITY_ERROR   5

Functions

void usart_disable_interrupt (Usart *p_usart, uint32_t ul_sources)
 Disable USART interrupts.
void usart_disable_rx (Usart *p_usart)
 Disable USART receiver.
void usart_disable_tx (Usart *p_usart)
 Disable USART transmitter.
void usart_disable_writeprotect (Usart *p_usart)
 Disable write protect of USART registers.
void usart_drive_DTR_pin_high (Usart *p_usart)
 Drive the pin DTR to 1.
void usart_drive_DTR_pin_low (Usart *p_usart)
 Drive the pin DTR to 0.
void usart_drive_RTS_pin_high (Usart *p_usart)
 Drive the pin RTS to 1.
void usart_drive_RTS_pin_low (Usart *p_usart)
 Drive the pin RTS to 0.
void usart_enable_interrupt (Usart *p_usart, uint32_t ul_sources)
 Enable USART interrupts.
void usart_enable_rx (Usart *p_usart)
 Enable USART receiver.
void usart_enable_tx (Usart *p_usart)
 Enable USART transmitter.
void usart_enable_writeprotect (Usart *p_usart)
 Enable write protect of USART registers.
uint8_t usart_get_error_number (Usart *p_usart)
 Get the total number of errors that occur during an ISO7816 transfer.
uint32_t usart_get_interrupt_mask (Usart *p_usart)
 Read USART interrupt mask.
Pdc * usart_get_pdc_base (Usart *p_usart)
 Get USART PDC base address.
uint32_t usart_get_status (Usart *p_usart)
 Get current status.
uint32_t usart_get_writeprotect_status (Usart *p_usart)
 Get write protect status.
uint32_t usart_getchar (Usart *p_usart, uint32_t *c)
 Read from USART Receive Holding Register.
uint32_t usart_init_hw_handshaking (Usart *p_usart, const sam_usart_opt_t *p_usart_opt, uint32_t ul_mck)
 Configure USART to work in hardware handshaking mode.
uint32_t usart_init_irda (Usart *p_usart, const sam_usart_opt_t *p_usart_opt, uint32_t ul_mck)
 Configure USART to work in IrDA mode.
uint32_t usart_init_iso7816 (Usart *p_usart, const usart_iso7816_opt_t *p_usart_opt, uint32_t ul_mck)
 Configure USART to work in ISO7816 mode.
uint32_t usart_init_modem (Usart *p_usart, const sam_usart_opt_t *p_usart_opt, uint32_t ul_mck)
 Configure USART to work in modem mode.
uint32_t usart_init_rs232 (Usart *p_usart, const sam_usart_opt_t *p_usart_opt, uint32_t ul_mck)
 Configure USART to work in RS232 mode.
uint32_t usart_init_rs485 (Usart *p_usart, const sam_usart_opt_t *p_usart_opt, uint32_t ul_mck)
 Configure USART to work in RS485 mode.
uint32_t usart_init_spi_master (Usart *p_usart, const usart_spi_opt_t *p_usart_opt, uint32_t ul_mck)
 Configure USART to work in SPI mode and act as a master.
uint32_t usart_init_spi_slave (Usart *p_usart, const usart_spi_opt_t *p_usart_opt)
 Configure USART to work in SPI mode and act as a slave.
uint32_t usart_init_sync_master (Usart *p_usart, const sam_usart_opt_t *p_usart_opt, uint32_t ul_mck)
 Configure USART to work in SYNC mode and act as a master.
uint32_t usart_init_sync_slave (Usart *p_usart, const sam_usart_opt_t *p_usart_opt)
 Configure USART to work in SYNC mode and act as a slave.
uint32_t usart_is_rx_buf_end (Usart *p_usart)
 Check if one receive buffer is filled.
uint32_t usart_is_rx_buf_full (Usart *p_usart)
 Check if both receive buffers are full.
uint32_t usart_is_rx_ready (Usart *p_usart)
 Check if the received data are ready.
uint32_t usart_is_tx_buf_empty (Usart *p_usart)
 Check if both transmit buffers are empty.
uint32_t usart_is_tx_buf_end (Usart *p_usart)
 Check if one transmit buffer is empty.
uint32_t usart_is_tx_empty (Usart *p_usart)
 Check if Transmit Holding Register is empty.
uint32_t usart_is_tx_ready (Usart *p_usart)
 Check if Transmit is Ready.
void usart_man_disable_drift_compensation (Usart *p_usart)
 Disable drift compensation.
void usart_man_enable_drift_compensation (Usart *p_usart)
 Enable drift compensation.
void usart_man_set_rx_polarity (Usart *p_usart, uint8_t uc_polarity)
 Configure the receiver Manchester polarity when the Manchester encode/decode is enabled.
void usart_man_set_rx_pre_len (Usart *p_usart, uint8_t uc_len)
 Configure the detected receiver preamble length when the Manchester encode/decode is enabled.
void usart_man_set_rx_pre_pattern (Usart *p_usart, uint8_t uc_pattern)
 Configure the detected receiver preamble pattern when the Manchester encode/decode is enabled, which should be 0 ~ 3.
void usart_man_set_tx_polarity (Usart *p_usart, uint8_t uc_polarity)
 Configure the transmitter Manchester polarity when the Manchester encode/decode is enabled.
void usart_man_set_tx_pre_len (Usart *p_usart, uint8_t uc_len)
 Configure the transmitter preamble length when the Manchester encode/decode is enabled.
void usart_man_set_tx_pre_pattern (Usart *p_usart, uint8_t uc_pattern)
 Configure the transmitter preamble pattern when the Manchester encode/decode is enabled, which should be 0 ~ 3.
uint32_t usart_putchar (Usart *p_usart, uint32_t c)
 Write to USART Transmit Holding Register.
uint32_t usart_read (Usart *p_usart, uint32_t *c)
 Read from USART Receive Holding Register.
void usart_reset (Usart *p_usart)
 Reset the USART and disable TX and RX.
void usart_reset_iterations (Usart *p_usart)
 Reset the ITERATION in US_CSR when the ISO7816 mode is enabled.
void usart_reset_nack (Usart *p_usart)
 Reset NACK in US_CSR.
void usart_reset_rx (Usart *p_usart)
 Immediately stop and disable USART receiver.
void usart_reset_status (Usart *p_usart)
 Reset status bits (PARE, OVER, MANERR, UNRE and PXBRK in US_CSR).
void usart_reset_tx (Usart *p_usart)
 Immediately stop and disable USART transmitter.
void usart_restart_rx_timeout (Usart *p_usart)
 Restart the receive timeout.
uint32_t usart_send_address (Usart *p_usart, uint32_t ul_addr)
 In Multidrop mode only, the next character written to the US_THR is sent with the address bit set.
uint32_t usart_set_async_baudrate (Usart *p_usart, uint32_t baudrate, uint32_t ul_mck)
 Calculate a clock divider(CD) and a fractional part (FP) for the USART asynchronous modes to generate a baudrate as close as possible to the baudrate set point.
static uint32_t usart_set_iso7816_clock (Usart *p_usart, uint32_t clock, uint32_t ul_mck)
 Calculate a clock divider (CD) for the USART ISO7816 mode to generate an ISO7816 clock as close as possible to the clock set point.
void usart_set_rx_timeout (Usart *p_usart, uint32_t timeout)
 Configure the receive timeout register.
static uint32_t usart_set_spi_master_baudrate (Usart *p_usart, uint32_t baudrate, uint32_t ul_mck)
 Calculate a clock divider (CD) for the USART SPI master mode to generate a baud rate as close as possible to the baud rate set point.
static void usart_set_spi_slave_baudrate (Usart *p_usart)
 Select the SCK pin as the source of baudrate for the USART SPI slave mode.
static uint32_t usart_set_sync_master_baudrate (Usart *p_usart, uint32_t baudrate, uint32_t ul_mck)
 Calculate a clock divider for the USART synchronous master modes to generate a baudrate as close as possible to the baudrate set point.
static void usart_set_sync_slave_baudrate (Usart *p_usart)
 Select the SCK pin as the source of baud rate for the USART synchronous slave modes.
void usart_set_tx_timeguard (Usart *p_usart, uint32_t timeguard)
 Configure the transmit timeguard register.
void usart_spi_force_chip_select (Usart *p_usart)
 Drive the slave select line NSS (RTS pin) to 0 in SPI master mode.
void usart_spi_release_chip_select (Usart *p_usart)
 Drive the slave select line NSS (RTS pin) to 1 in SPI master mode.
void usart_start_rx_timeout (Usart *p_usart)
 Start waiting for a character before clocking the timeout count.
void usart_start_tx_break (Usart *p_usart)
 Start transmission of a break.
void usart_stop_tx_break (Usart *p_usart)
 Stop transmission of a break.
uint32_t usart_write (Usart *p_usart, uint32_t c)
 Write to USART Transmit Holding Register.
void usart_write_line (Usart *p_usart, const char *string)
 Write one-line string through USART.

Detailed Description

Universal Synchronous Asynchronous Receiver Transmitter (USART) driver for SAM.

Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.

\cond ASF_LICENSE

Definition in file usart.c.