Atmel Software Framework

usart.c File Reference
#include "compiler.h"
#include "usart.h"

Functions

Private Functions
static __always_inline int usart_mode_is_multidrop (volatile avr32_usart_t *usart)
 Checks if the USART is in multidrop mode. More...
 
static int usart_set_async_baudrate (volatile avr32_usart_t *usart, unsigned int baudrate, unsigned long pba_hz)
 Calculates a clock divider (CD) and a fractional part (FP) for the USART asynchronous modes to generate a baud rate as close as possible to the baud rate set point. More...
 
static int usart_set_sync_master_baudrate (volatile avr32_usart_t *usart, unsigned int baudrate, unsigned long pba_hz)
 Calculates a clock divider (CD) for the USART synchronous master modes to generate a baud rate as close as possible to the baud rate set point. More...
 
static int usart_set_sync_slave_baudrate (volatile avr32_usart_t *usart)
 Selects the SCK pin as the source of baud rate for the USART synchronous slave modes. More...
 
static int usart_set_iso7816_clock (volatile avr32_usart_t *usart, unsigned int clock, unsigned long pba_hz)
 Calculates a clock divider (CD) for the USART ISO7816 mode to generate an ISO7816 clock as close as possible to the clock set point. More...
 
Initialization Functions
void usart_reset (volatile avr32_usart_t *usart)
 Resets the USART and disables TX and RX. More...
 
int usart_init_rs232 (volatile avr32_usart_t *usart, const usart_options_t *opt, long pba_hz)
 Sets up the USART to use the standard RS232 protocol. More...
 
int usart_init_rs232_tx_only (volatile avr32_usart_t *usart, const usart_options_t *opt, long pba_hz)
 Sets up the USART to use the standard RS232 protocol in TX-only mode. More...
 
int usart_init_hw_handshaking (volatile avr32_usart_t *usart, const usart_options_t *opt, long pba_hz)
 Sets up the USART to use hardware handshaking. More...
 
int usart_init_modem (volatile avr32_usart_t *usart, const usart_options_t *opt, long pba_hz)
 Sets up the USART to use the modem protocol, activating dedicated inputs/outputs. More...
 
int usart_init_sync_master (volatile avr32_usart_t *usart, const usart_options_t *opt, long pba_hz)
 Sets up the USART to use a synchronous RS232-like protocol in master mode. More...
 
int usart_init_sync_slave (volatile avr32_usart_t *usart, const usart_options_t *opt, long pba_hz)
 Sets up the USART to use a synchronous RS232-like protocol in slave mode. More...
 
int usart_init_rs485 (volatile avr32_usart_t *usart, const usart_options_t *opt, long pba_hz)
 Sets up the USART to use the RS485 protocol. More...
 
int usart_init_IrDA (volatile avr32_usart_t *usart, const usart_options_t *opt, long pba_hz, unsigned char irda_filter)
 Sets up the USART to use the IrDA protocol. More...
 
int usart_init_iso7816 (volatile avr32_usart_t *usart, const usart_iso7816_options_t *opt, int t, long pba_hz)
 Sets up the USART to use the ISO7816 T=0 or T=1 smartcard protocols. More...
 
Transmit/Receive Functions
int usart_send_address (volatile avr32_usart_t *usart, int address)
 Addresses a receiver. More...
 
int usart_write_char (volatile avr32_usart_t *usart, int c)
 Writes the given character to the TX buffer if the transmitter is ready. More...
 
int usart_putchar (volatile avr32_usart_t *usart, int c)
 Sends a character with the USART. More...
 
int usart_read_char (volatile avr32_usart_t *usart, int *c)
 Checks the RX buffer for a received character, and stores it at the given memory location. More...
 
int usart_getchar (volatile avr32_usart_t *usart)
 Waits until a character is received, and returns it. More...
 
void usart_write_line (volatile avr32_usart_t *usart, const char *string)
 Writes one character string to the USART. More...
 
int usart_get_echo_line (volatile avr32_usart_t *usart)
 Gets and echoes characters until end of line (detected by a CR character). More...
 

static __always_inline int usart_mode_is_multidrop ( volatile avr32_usart_t *  usart)
static

Checks if the USART is in multidrop mode.

Parameters
usartBase address of the USART instance.
Returns
1 if the USART is in multidrop mode, otherwise 0.

Referenced by usart_send_address().

static int usart_set_async_baudrate ( volatile avr32_usart_t *  usart,
unsigned int  baudrate,
unsigned long  pba_hz 
)
static

Calculates a clock divider (CD) and a fractional part (FP) for the USART asynchronous modes to generate a baud rate as close as possible to the baud rate set point.

Baud rate calculation: \( Baudrate = \frac{SelectedClock}{Over \times (CD + \frac{FP}{8})} \), Over being 16 or 8. The maximal oversampling is selected if it allows to generate a baud rate close to the set point.

Parameters
usartBase address of the USART instance.
baudrateBaud rate set point.
pba_hzUSART module input clock frequency (PBA clock, Hz).
Return values
USART_SUCCESSBaud rate successfully initialized.
USART_INVALID_INPUTBaud rate set point is out of range for the given input clock frequency.

References USART_INVALID_INPUT, and USART_SUCCESS.

Referenced by usart_init_rs232().

static int usart_set_iso7816_clock ( volatile avr32_usart_t *  usart,
unsigned int  clock,
unsigned long  pba_hz 
)
static

Calculates a clock divider (CD) for the USART ISO7816 mode to generate an ISO7816 clock as close as possible to the clock set point.

ISO7816 clock calculation: \( Clock = \frac{SelectedClock}{CD} \).

Parameters
usartBase address of the USART instance.
clockISO7816 clock set point.
pba_hzUSART module input clock frequency (PBA clock, Hz).
Return values
USART_SUCCESSISO7816 clock successfully initialized.
USART_INVALID_INPUTISO7816 clock set point is out of range for the given input clock frequency.

References USART_INVALID_INPUT, and USART_SUCCESS.

Referenced by usart_init_iso7816().

static int usart_set_sync_master_baudrate ( volatile avr32_usart_t *  usart,
unsigned int  baudrate,
unsigned long  pba_hz 
)
static

Calculates a clock divider (CD) for the USART synchronous master modes to generate a baud rate as close as possible to the baud rate set point.

Baud rate calculation: \( Baudrate = \frac{SelectedClock}{CD} \).

Parameters
usartBase address of the USART instance.
baudrateBaud rate set point.
pba_hzUSART module input clock frequency (PBA clock, Hz).
Return values
USART_SUCCESSBaud rate successfully initialized.
USART_INVALID_INPUTBaud rate set point is out of range for the given input clock frequency.

References USART_INVALID_INPUT, and USART_SUCCESS.

Referenced by usart_init_rs232_tx_only(), and usart_init_sync_master().

static int usart_set_sync_slave_baudrate ( volatile avr32_usart_t *  usart)
static

Selects the SCK pin as the source of baud rate for the USART synchronous slave modes.

Parameters
usartBase address of the USART instance.
Return values
USART_SUCCESSBaud rate successfully initialized.

References USART_SUCCESS.

Referenced by usart_init_sync_slave().