Microchip® Advanced Software Framework

usart_spi.c File Reference

UC3 USART in SPI mode driver functions.

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

#include "usart_spi.h"
#include "sysclk.h"

Functions

void usart_spi_deselect_device (volatile avr32_usart_t *p_usart, struct usart_spi_device *device)
 De-select the given device on the SPI bus. More...
 
void usart_spi_init (volatile avr32_usart_t *p_usart)
 Enable the USART system clock in SPI master mode. More...
 
uint32_t usart_spi_is_rx_full (volatile avr32_usart_t *p_usart)
 Check if both receive buffers are full. More...
 
uint32_t usart_spi_is_rx_ready (volatile avr32_usart_t *p_usart)
 Check whether the USART in SPI master mode contains a received character. More...
 
uint32_t usart_spi_is_tx_empty (volatile avr32_usart_t *p_usart)
 Check whether there are data in Transmit Holding Register or Transmit Shift Register in SPI master mode. More...
 
uint32_t usart_spi_is_tx_ready (volatile avr32_usart_t *p_usart)
 Check if the USART Transmit Holding Register is empty or not in SPI mode. More...
 
uint32_t usart_spi_read_packet (volatile avr32_usart_t *p_usart, uint8_t *data, size_t len)
 Receive a sequence of bytes from a USART in SPI mode device. More...
 
void usart_spi_read_single (volatile avr32_usart_t *p_usart, uint8_t *data)
 Receive one byte from an SPI device using USART in SPI mode. More...
 
void usart_spi_select_device (volatile avr32_usart_t *p_usart, struct usart_spi_device *device)
 Select the given device on the SPI bus. More...
 
void usart_spi_setup_device (volatile avr32_usart_t *p_usart, struct usart_spi_device *device, spi_flags_t flags, unsigned long baud_rate, board_spi_select_id_t sel_id)
 Set up a USART in SPI master mode device. More...
 
uint32_t usart_spi_write_packet (volatile avr32_usart_t *p_usart, const uint8_t *data, size_t len)
 Send a sequence of bytes to an SPI device using USART in SPI mode. More...
 
void usart_spi_write_single (volatile avr32_usart_t *p_usart, uint8_t data)
 Write one byte to an SPI device using USART in SPI mode. More...
 

void usart_spi_deselect_device ( volatile avr32_usart_t *  p_usart,
struct usart_spi_device device 
)

De-select the given device on the SPI bus.

Parameters
p_usartBase address of the USART instance.
deviceSPI device.

References UNUSED().

Referenced by at25dfx_spi_deselect_device().

void usart_spi_init ( volatile avr32_usart_t *  p_usart)

Enable the USART system clock in SPI master mode.

Parameters
p_usartPointer to Base address of the USART instance.

References sysclk_enable_pba_module(), SYSCLK_USART0, SYSCLK_USART1, SYSCLK_USART2, and SYSCLK_USART3.

Referenced by at25dfx_spi_init(), at45dbx_spi_init(), and ili9341_interface_init().

uint32_t usart_spi_is_rx_full ( volatile avr32_usart_t *  p_usart)

Check if both receive buffers are full.

Parameters
p_usartBase address of the USART instance.
Return values
1Receive buffers are full.
0Receive buffers are not full.
uint32_t usart_spi_is_rx_ready ( volatile avr32_usart_t *  p_usart)

Check whether the USART in SPI master mode contains a received character.

Parameters
p_usartBase address of the USART instance.
Return values
1Some data have been received.
0No data has been received.
uint32_t usart_spi_is_tx_empty ( volatile avr32_usart_t *  p_usart)

Check whether there are data in Transmit Holding Register or Transmit Shift Register in SPI master mode.

Parameters
p_usartBase address of the USART instance.
Return values
1The two registers are empty.
0One of the two registers contains data.

References usart_tx_empty().

Referenced by ili9341_wait_for_send_done().

uint32_t usart_spi_is_tx_ready ( volatile avr32_usart_t *  p_usart)

Check if the USART Transmit Holding Register is empty or not in SPI mode.

Parameters
p_usartBase address of the USART instance.
Return values
1There is no data in the Transmit Holding Register.
0There are data in the Transmit Holding Register.

References usart_tx_ready().

uint32_t usart_spi_read_packet ( volatile avr32_usart_t *  p_usart,
uint8_t *  data,
size_t  len 
)

Receive a sequence of bytes from a USART in SPI mode device.

All bytes sent out on usart bus are sent as value 0.

Parameters
p_usartBase address of the usart instance.
dataData buffer to put read data.
lenLength of data.
Returns
0 if the USART in SPI master mode reads packet successfully.
Precondition
USART device must be selected with usart_spi_select_device() first.

References CONFIG_USART_SPI_DUMMY, i, usart_getchar(), usart_putchar(), and val.

Referenced by at25dfx_spi_read_byte(), and at25dfx_spi_read_packet().

void usart_spi_read_single ( volatile avr32_usart_t *  p_usart,
uint8_t *  data 
)

Receive one byte from an SPI device using USART in SPI mode.

Parameters
p_usartBase address of the USART instance.
dataPointer to the data byte where to store the received data.
Precondition
USART device must be selected with usart_spi_select_device() first.

References CONFIG_USART_SPI_DUMMY, usart_getchar(), and usart_putchar().

Referenced by ili9341_read_byte().

void usart_spi_select_device ( volatile avr32_usart_t *  p_usart,
struct usart_spi_device device 
)

Select the given device on the SPI bus.

Parameters
p_usartBase address of the USART instance.
deviceSPI device.

References UNUSED().

Referenced by at25dfx_spi_select_device().

void usart_spi_setup_device ( volatile avr32_usart_t *  p_usart,
struct usart_spi_device device,
spi_flags_t  flags,
unsigned long  baud_rate,
board_spi_select_id_t  sel_id 
)

Set up a USART in SPI master mode device.

The returned device descriptor structure must be passed to the driver whenever that device should be used as current slave device.

Parameters
p_usartBase address of the USART instance.
devicePointer to usart device struct that should be initialized.
flagsUSART configuration flags. Common flags for all implementations are the usart modes, which should be SPI_MODE_0, SPI_MODE_1, SPI_MODE_2, SPI_MODE_3.
baud_rateBaud rate for communication with slave device in Hz.
sel_idBoard specific select id.

References opt, sysclk_get_cpu_hz(), UNUSED(), and USART_NORMAL_CHMODE.

Referenced by at25dfx_spi_init(), and ili9341_interface_init().

uint32_t usart_spi_write_packet ( volatile avr32_usart_t *  p_usart,
const uint8_t *  data,
size_t  len 
)

Send a sequence of bytes to an SPI device using USART in SPI mode.

Received bytes on the USART in SPI mode are discarded.

Parameters
p_usartBase address of the USART instance.
dataData buffer to write.
lenLength of data.
Returns
0 if the USART in SPI master mode sends packet successfully.
Precondition
USART device must be selected with usart_spi_select_device() first.

References dummy_data, i, usart_getchar(), and usart_putchar().

Referenced by at25dfx_spi_write_byte(), and at25dfx_spi_write_packet().

void usart_spi_write_single ( volatile avr32_usart_t *  p_usart,
uint8_t  data 
)

Write one byte to an SPI device using USART in SPI mode.

Parameters
p_usartBase address of the USART instance.
dataThe data to be sent out.

References usart_putchar().

Referenced by ili9341_send_byte().