Atmel Software Framework

uc3_spi/spi_master.h File Reference
#include "compiler.h"
#include "sysclk.h"
#include "status_codes.h"
#include "spi.h"
#include "conf_spi_master.h"

Data Structures

struct  spi_device
 Polled SPI device definition. More...
 

Macros

Spi Master Management Configuration
#define CONFIG_SPI_MASTER_DELAY_BCS   0
 Default Config Spi Master Delay BCS. More...
 
#define CONFIG_SPI_MASTER_BITS_PER_TRANSFER   8
 Default Config Spi Master Bits per Transfer Definition. More...
 
#define CONFIG_SPI_MASTER_DELAY_BCT   0
 Default Config Spi Master Delay BCT. More...
 
#define CONFIG_SPI_MASTER_DELAY_BS   0
 Default Config Spi Master Delay BS. More...
 
#define CONFIG_SPI_MASTER_DUMMY   0xFF
 Default Config Spi Master Dummy Field. More...
 

Typedefs

typedef uint8_t board_spi_select_id_t
 Board Spi Select Id Definition. More...
 
typedef uint8_t spi_flags_t
 Spi Flags definition. More...
 

Functions

static void spi_deselect_device (volatile avr32_spi_t *spi, struct spi_device *device)
 Deselect given device on the SPI bus. More...
 
void spi_disable (volatile avr32_spi_t *spi)
 Disables the SPI. More...
 
void spi_enable (volatile avr32_spi_t *spi)
 Enables the SPI. More...
 
bool spi_is_enabled (volatile avr32_spi_t *spi)
 Tests if the SPI is enabled. More...
 
bool spi_is_rx_full (volatile avr32_spi_t *spi)
 Check if the SPI contains a received character. More...
 
bool spi_is_rx_ready (volatile avr32_spi_t *spi)
 Checks if all reception is ready. More...
 
bool spi_is_tx_empty (volatile avr32_spi_t *spi)
 Checks if all transmissions are complete. More...
 
bool spi_is_tx_ready (volatile avr32_spi_t *spi)
 Checks if all transmissions is ready. More...
 
static void spi_master_init (volatile avr32_spi_t *spi)
 Initializes the SPI in master mode. More...
 
void spi_master_setup_device (volatile avr32_spi_t *spi, struct spi_device *device, spi_flags_t flags, uint32_t baud_rate, board_spi_select_id_t sel_id)
 Setup a SPI device. More...
 
status_code_t spi_read_packet (volatile avr32_spi_t *spi, uint8_t *data, size_t len)
 Receive a sequence of bytes from a SPI device. More...
 
static void spi_read_single (volatile avr32_spi_t *spi, uint8_t *data)
 Receive one byte from a SPI device. More...
 
static void spi_select_device (volatile avr32_spi_t *spi, struct spi_device *device)
 Select given device on the SPI bus. More...
 
status_code_t spi_write_packet (volatile avr32_spi_t *spi, const uint8_t *data, size_t len)
 Send a sequence of bytes to a SPI device. More...
 
static void spi_write_single (volatile avr32_spi_t *spi, uint8_t data)
 Write one byte to a SPI device. More...
 

#define CONFIG_SPI_MASTER_BITS_PER_TRANSFER   8

Default Config Spi Master Bits per Transfer Definition.

Referenced by spi_master_setup_device().

#define CONFIG_SPI_MASTER_DELAY_BCS   0

Default Config Spi Master Delay BCS.

Referenced by spi_master_init().

#define CONFIG_SPI_MASTER_DELAY_BCT   0

Default Config Spi Master Delay BCT.

Referenced by spi_master_setup_device().

#define CONFIG_SPI_MASTER_DELAY_BS   0

Default Config Spi Master Delay BS.

Referenced by spi_master_setup_device().

#define CONFIG_SPI_MASTER_DUMMY   0xFF

Default Config Spi Master Dummy Field.

Referenced by spi_read_packet().

typedef uint8_t board_spi_select_id_t

Board Spi Select Id Definition.

typedef uint8_t spi_flags_t

Spi Flags definition.

static void spi_deselect_device ( volatile avr32_spi_t *  spi,
struct spi_device device 
)
inlinestatic

Deselect given device on the SPI bus.

Calls board chip deselect.

Parameters
spiBase address of the SPI instance.
deviceSPI device
Precondition
SPI device must be selected with spi_select_device() first

References spi_device::id, and spi_unselectChip().

Referenced by at25dfx_spi_deselect_device(), and spi_at45dbx_mem_check().

bool spi_is_rx_full ( volatile avr32_spi_t *  spi)

Check if the SPI contains a received character.

Parameters
spiBase address of the SPI instance.
Returns
1 if the SPI Receive Holding Register is full, otherwise 0.

Referenced by ili9341_read_byte().

bool spi_is_rx_ready ( volatile avr32_spi_t *  spi)

Checks if all reception is ready.

Parameters
spiBase address of the SPI instance.
Returns
1 if the SPI Receiver is ready, otherwise 0.

Referenced by spi_read_packet().

bool spi_is_tx_empty ( volatile avr32_spi_t *  spi)

Checks if all transmissions are complete.

Parameters
spiBase address of the SPI instance.
Returns
Status.
Return values
1All transmissions complete.
0Transmissions not complete.

Referenced by ili9341_wait_for_send_done().

bool spi_is_tx_ready ( volatile avr32_spi_t *  spi)

Checks if all transmissions is ready.

Parameters
spiBase address of the SPI instance.
Returns
Status.
Return values
1All transmissions complete.
0Transmissions not complete.

Referenced by spi_read_packet(), and spi_write_packet().

static void spi_master_init ( volatile avr32_spi_t *  spi)
inlinestatic
void spi_master_setup_device ( volatile avr32_spi_t *  spi,
struct spi_device device,
spi_flags_t  flags,
uint32_t  baud_rate,
board_spi_select_id_t  sel_id 
)

Setup a SPI device.

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

Parameters
spiBase address of the SPI instance.
devicePointer to SPI device struct that should be initialized.
flagsSPI configuration flags. Common flags for all implementations are the SPI modes SPI_MODE_0 ... SPI_MODE_3.
baud_rateBaud rate for communication with slave device in Hz.
sel_idBoard specific select id

References CONFIG_SPI_MASTER_BITS_PER_TRANSFER, CONFIG_SPI_MASTER_DELAY_BCT, CONFIG_SPI_MASTER_DELAY_BS, getBaudDiv(), spi_device::id, spi_enable_active_mode(), spi_set_baudrate_register(), spi_set_bits_per_transfer(), spi_set_chipselect_delay_bct(), spi_set_chipselect_delay_bs(), spi_set_mode(), sysclk_get_peripheral_bus_hz(), and vSemaphoreCreateBinary.

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

status_code_t spi_read_packet ( volatile avr32_spi_t *  spi,
uint8_t *  data,
size_t  len 
)

Receive a sequence of bytes from a SPI device.

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

Parameters
spiBase address of the SPI instance.
dataData buffer to read
lenLength of data
Precondition
SPI device must be selected with spi_select_device() first

References CONFIG_SPI_MASTER_DUMMY, ERR_TIMEOUT, i, spi_is_rx_ready(), spi_is_tx_ready(), spi_read_single(), SPI_TIMEOUT, spi_write_single(), STATUS_OK, and val.

Referenced by at25dfx_spi_read_byte(), at25dfx_spi_read_packet(), and spi_at45dbx_mem_check().

static void spi_read_single ( volatile avr32_spi_t *  spi,
uint8_t *  data 
)
inlinestatic

Receive one byte from a SPI device.

Parameters
spiBase address of the SPI instance.
dataData to read

References spi_get().

Referenced by ili9341_read_byte(), and spi_read_packet().

static void spi_select_device ( volatile avr32_spi_t *  spi,
struct spi_device device 
)
inlinestatic

Select given device on the SPI bus.

Set device specific setting and calls board chip select.

Parameters
spiBase address of the SPI instance.
deviceSPI device

References spi_device::id, and spi_selectChip().

Referenced by at25dfx_spi_select_device(), and spi_at45dbx_mem_check().

status_code_t spi_write_packet ( volatile avr32_spi_t *  spi,
const uint8_t *  data,
size_t  len 
)

Send a sequence of bytes to a SPI device.

Received bytes on the SPI bus are discarded.

Parameters
spiBase address of the SPI instance.
dataData buffer to write
lenLength of data
Precondition
SPI device must be selected with spi_select_device() first

References ERR_TIMEOUT, i, spi_is_tx_ready(), SPI_TIMEOUT, spi_write_single(), STATUS_OK, and val.

Referenced by at25dfx_spi_write_byte(), at25dfx_spi_write_packet(), and spi_at45dbx_mem_check().

static void spi_write_single ( volatile avr32_spi_t *  spi,
uint8_t  data 
)
inlinestatic

Write one byte to a SPI device.

Parameters
spiBase address of the SPI instance.
dataData to write

References spi_put().

Referenced by ili9341_interface_init(), ili9341_read_byte(), ili9341_send_byte(), spi_read_packet(), and spi_write_packet().