SPI master common service for SAM.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
Macros | |
#define | DEFAULT_CHIP_ID 0 |
The default chip select id. More... | |
#define | MAX_NUM_WITH_DECODER 0x10 |
Max number when the chip selects are connected to a 4- to 16-bit decoder. More... | |
#define | MAX_NUM_WITHOUT_DECODER 0x04 |
Max number when the chip selects are directly connected to peripheral device. More... | |
#define | NONE_CHIP_SELECT_ID 0x0f |
Max number when the chip selects are directly connected to peripheral device. More... | |
Functions | |
void | spi_deselect_device (Spi *p_spi, struct spi_device *device) |
Deselect the given device on the SPI bus. More... | |
void | spi_master_init (Spi *p_spi) |
Initialize the SPI in master mode. More... | |
void | spi_master_setup_device (Spi *p_spi, struct spi_device *device, spi_flags_t flags, uint32_t baud_rate, board_spi_select_id_t sel_id) |
Set up an SPI device. More... | |
status_code_t | spi_read_packet (Spi *p_spi, uint8_t *data, size_t len) |
Receive a sequence of bytes from an SPI device. More... | |
void | spi_select_device (Spi *p_spi, struct spi_device *device) |
Select the given device on the SPI bus. More... | |
status_code_t | spi_transceive_packet (Spi *p_spi, uint8_t *tx_data, uint8_t *rx_data, size_t len) |
Send and receive a sequence of bytes from an SPI device. More... | |
status_code_t | spi_write_packet (Spi *p_spi, const uint8_t *data, size_t len) |
Send a sequence of bytes to an SPI device. More... | |
#define DEFAULT_CHIP_ID 0 |
The default chip select id.
Referenced by spi_master_init().
#define MAX_NUM_WITH_DECODER 0x10 |
Max number when the chip selects are connected to a 4- to 16-bit decoder.
Referenced by spi_select_device().
#define MAX_NUM_WITHOUT_DECODER 0x04 |
Max number when the chip selects are directly connected to peripheral device.
Referenced by spi_select_device().
#define NONE_CHIP_SELECT_ID 0x0f |
Max number when the chip selects are directly connected to peripheral device.
Referenced by spi_deselect_device().
void spi_deselect_device | ( | Spi * | p_spi, |
struct spi_device * | device | ||
) |
Deselect the given device on the SPI bus.
Call board chip deselect.
p_spi | Base address of the SPI instance. |
device | SPI device. |
References NONE_CHIP_SELECT_ID, spi_is_tx_empty(), spi_set_lastxfer(), spi_set_peripheral_chip_select_value(), and UNUSED.
Referenced by at25dfx_spi_deselect_device().
void spi_master_init | ( | Spi * | p_spi | ) |
Initialize the SPI in master mode.
p_spi | Base address of the SPI instance. |
References CONFIG_SPI_MASTER_DELAY_BCS, DEFAULT_CHIP_ID, spi_disable_loopback(), spi_disable_mode_fault_detect(), spi_disable_peripheral_select_decode(), spi_enable_clock(), spi_reset(), spi_set_delay_between_chip_select(), spi_set_fixed_peripheral_select(), spi_set_master_mode(), and spi_set_peripheral_chip_select_value().
Referenced by at25dfx_spi_init().
void spi_master_setup_device | ( | Spi * | p_spi, |
struct spi_device * | device, | ||
spi_flags_t | flags, | ||
uint32_t | baud_rate, | ||
board_spi_select_id_t | sel_id | ||
) |
Set up an SPI device.
The returned device descriptor structure must be passed to the driver whenever that device should be used as current slave device.
p_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 Assert, CONFIG_SPI_MASTER_BITS_PER_TRANSFER, CONFIG_SPI_MASTER_DELAY_BCT, CONFIG_SPI_MASTER_DELAY_BS, spi_device::id, spi_calc_baudrate_div(), spi_configure_cs_behavior(), SPI_CS_KEEP_LOW, spi_set_baudrate_div(), spi_set_bits_per_transfer(), spi_set_clock_phase(), spi_set_clock_polarity(), spi_set_transfer_delay(), sysclk_get_pba_hz(), and UNUSED.
Referenced by at25dfx_spi_init().
status_code_t spi_read_packet | ( | Spi * | p_spi, |
uint8_t * | data, | ||
size_t | len | ||
) |
Receive a sequence of bytes from an SPI device.
All bytes sent out on SPI bus are sent as value 0.
p_spi | Base address of the SPI instance. |
data | Data buffer to read. |
len | Length of data to be read. |
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.
Referenced by at25dfx_spi_read_byte(), and at25dfx_spi_read_packet().
void spi_select_device | ( | Spi * | p_spi, |
struct spi_device * | device | ||
) |
Select the given device on the SPI bus.
Set device specific setting and call board chip select.
p_spi | Base address of the SPI instance. |
device | SPI device. |
References spi_device::id, MAX_NUM_WITH_DECODER, MAX_NUM_WITHOUT_DECODER, spi_get_peripheral_select_decode_setting(), and spi_set_peripheral_chip_select_value().
Referenced by at25dfx_spi_select_device().
status_code_t spi_transceive_packet | ( | Spi * | p_spi, |
uint8_t * | tx_data, | ||
uint8_t * | rx_data, | ||
size_t | len | ||
) |
Send and receive a sequence of bytes from an SPI device.
p_spi | Base address of the SPI instance. |
tx_data | Data buffer to send. |
rx_data | Data buffer to read. |
len | Length of data to be read. |
References ERR_TIMEOUT, spi_is_rx_ready(), spi_is_tx_ready(), spi_read_single(), SPI_TIMEOUT, spi_write_single(), and STATUS_OK.
status_code_t spi_write_packet | ( | Spi * | p_spi, |
const uint8_t * | data, | ||
size_t | len | ||
) |
Send a sequence of bytes to an SPI device.
Received bytes on the SPI bus are discarded.
p_spi | Base address of the SPI instance. |
data | Data buffer to write. |
len | Length of data to be written. |
References ERR_TIMEOUT, spi_is_tx_ready(), SPI_TIMEOUT, spi_write_single(), and STATUS_OK.
Referenced by at25dfx_spi_write_byte(), and at25dfx_spi_write_packet().