#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... | |
Typedefs | |
typedef uint8_t | board_spi_select_id_t |
Board Spi Select Id Definition. More... | |
typedef uint8_t | spi_flags_t |
Default Config Spi Master Delay BCS. 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... | |
typedef uint8_t board_spi_select_id_t |
Board Spi Select Id Definition.
typedef uint8_t spi_flags_t |
Default Config Spi Master Delay BCS.
Default Config Spi Master Bits per Transfer Definition Default Config Spi Master Delay BCT Default Config Spi Master Delay BS Default Config Spi Master Dummy Field Spi Flags definition
|
inlinestatic |
Deselect given device on the SPI bus.
Calls board chip deselect.
spi | Base address of the SPI instance. |
device | SPI device |
References spi_device::id, and spi_unselectChip().
void spi_disable | ( | volatile avr32_spi_t * | spi | ) |
Disables the SPI.
Ensures that nothing is transferred while setting up buffers.
spi | Base address of the SPI instance. |
void spi_enable | ( | volatile avr32_spi_t * | spi | ) |
Enables the SPI.
spi | Base address of the SPI instance. |
bool spi_is_enabled | ( | volatile avr32_spi_t * | spi | ) |
Tests if the SPI is enabled.
spi | Base address of the SPI instance. |
true
if the SPI is enabled, otherwise false
. bool spi_is_rx_full | ( | volatile avr32_spi_t * | spi | ) |
Check if the SPI contains a received character.
spi | Base address of the SPI instance. |
1
if the SPI Receive Holding Register is full, otherwise 0
. bool spi_is_rx_ready | ( | volatile avr32_spi_t * | spi | ) |
Checks if all reception is ready.
spi | Base address of the SPI instance. |
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.
spi | Base address of the SPI instance. |
1 | All transmissions complete. |
0 | Transmissions not complete. |
bool spi_is_tx_ready | ( | volatile avr32_spi_t * | spi | ) |
Checks if all transmissions is ready.
spi | Base address of the SPI instance. |
1 | All transmissions complete. |
0 | Transmissions not complete. |
Referenced by spi_read_packet(), and spi_write_packet().
|
inlinestatic |
Initializes the SPI in master mode.
spi | Base address of the SPI instance. |
References CONFIG_SPI_MASTER_DELAY_BCS, spi_disable_chipselect_decoding(), spi_disable_loopback(), spi_disable_modfault(), spi_disable_variable_chipselect(), spi_reset(), spi_set_chipselect(), spi_set_delay(), spi_set_master_mode(), sysclk_enable_pba_module(), SYSCLK_SPI0, and SYSCLK_SPI1.
Referenced by sd_mmc_spi_init().
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.
spi | Base address of the SPI instance. |
device | Pointer to SPI device struct that should be initialized. |
flags | SPI configuration flags. Common flags for all implementations are the SPI modes SPI_MODE_0 ... SPI_MODE_3. |
baud_rate | Baud rate for communication with slave device in Hz. |
sel_id | Board 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(), and sysclk_get_peripheral_bus_hz().
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.
spi | Base address of the SPI instance. |
data | Data buffer to read |
len | Length of data |
References CONFIG_SPI_MASTER_DUMMY, ERR_TIMEOUT, spi_is_rx_ready(), spi_is_tx_ready(), spi_read_single(), SPI_TIMEOUT, spi_write_single(), and STATUS_OK.
|
inlinestatic |
Receive one byte from a SPI device.
spi | Base address of the SPI instance. |
data | Data to read |
References spi_get().
Referenced by spi_read_packet().
|
inlinestatic |
Select given device on the SPI bus.
Set device specific setting and calls board chip select.
spi | Base address of the SPI instance. |
device | SPI device |
References spi_device::id, and spi_selectChip().
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.
spi | Base address of the SPI instance. |
data | Data buffer to write |
len | Length of data |
References ERR_TIMEOUT, spi_is_tx_ready(), SPI_TIMEOUT, spi_write_single(), and STATUS_OK.
|
inlinestatic |
Write one byte to a SPI device.
spi | Base address of the SPI instance. |
data | Data to write |
References spi_put().
Referenced by spi_read_packet(), and spi_write_packet().