Microchip® Advanced Software Framework

usart_serial.h File Reference

This file defines a useful set of functions for the Serial interface on AVR XMEGA devices.

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

#include "compiler.h"
#include "sysclk.h"
#include "status_codes.h"
#include "usart.h"
#include "conf_usart_serial.h"

Typedefs

typedef USART_t * usart_if
 This type can be used independently to refer to USART module for the architecture used. More...
 
typedef usart_rs232_options_t usart_serial_options_t
 

Functions

static void usart_serial_getchar (usart_if usart, uint8_t *data)
 Waits until a character is received, and returns it. More...
 
static bool usart_serial_init (usart_if usart, const usart_serial_options_t *options)
 Initializes the Usart in master mode. More...
 
static enum status_code usart_serial_putchar (usart_if usart, uint8_t c)
 Sends a character with the USART. More...
 
status_code_t usart_serial_read_packet (usart_if usart, uint8_t *data, size_t len)
 Receive a sequence of bytes from USART device. More...
 
status_code_t usart_serial_write_packet (usart_if usart, const uint8_t *data, size_t len)
 Send a sequence of bytes to USART device. More...
 

This type can be used independently to refer to USART module for the architecture used.

It refers to the correct type definition for the architecture, ie. USART_t* for XMEGA or avr32_usart_t* for UC3.

static void usart_serial_getchar ( usart_if  usart,
uint8_t *  data 
)
inlinestatic

Waits until a character is received, and returns it.

Parameters
usartBase address of the USART instance.
dataData to read

References usart_getchar().

Referenced by gfx_mono_screen_dump(), stdio_serial_init(), and usart_serial_read_packet().

static bool usart_serial_init ( usart_if  usart,
const usart_serial_options_t options 
)
inlinestatic

Initializes the Usart in master mode.

Parameters
usartBase address of the USART instance.
optionsOptions needed to set up RS232 communication (see usart_serial_options_t).
Return values
trueif the initialization was successful
falseif initialization failed (error in baud rate calculation)

References usart_rs232_options::baudrate, usart_rs232_options::charlength, usart_rs232_options::paritytype, usart_rs232_options::stopbits, sysclk_enable_module(), SYSCLK_PORT_C, SYSCLK_PORT_D, SYSCLK_PORT_E, SYSCLK_PORT_F, and usart_init_rs232().

Referenced by gfx_mono_screen_dump_init(), log_init(), main(), sio2ncp_init(), and stdio_serial_init().

static enum status_code usart_serial_putchar ( usart_if  usart,
uint8_t  c 
)
inlinestatic

Sends a character with the USART.

Parameters
usartBase address of the USART instance.
cCharacter to write.
Returns
Status code

References usart_putchar().

Referenced by stdio_serial_init(), and usart_serial_write_packet().

status_code_t usart_serial_read_packet ( usart_if  usart,
uint8_t *  data,
size_t  len 
)

Receive a sequence of bytes from USART device.

Parameters
usartBase address of the USART instance.
dataData buffer to write
lenLength of data

References STATUS_OK, and usart_serial_getchar().

status_code_t usart_serial_write_packet ( usart_if  usart,
const uint8_t *  data,
size_t  len 
)

Send a sequence of bytes to USART device.

Parameters
usartBase address of the USART instance.
dataData buffer to read
lenLength of data

References STATUS_OK, and usart_serial_putchar().

Referenced by gfx_mono_screen_dump(), log_sha204(), log_sha204_title(), main(), mxt_handler(), sio2host_tx(), sio2ncp_tx(), and usart_write_crlf().