Classes | Macros | Typedefs | Functions
sam_spi/spi_master.h File Reference

SPI master common service for SAM. More...

#include "compiler.h"
#include "sysclk.h"
#include "status_codes.h"
#include "spi.h"
#include "conf_spi_master.h"
Include dependency graph for sam_spi/spi_master.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  spi_device
 Polled SPI device definition. More...
 

Macros

#define SPI_CPHA   (1 << 0)
 Clock phase. More...
 
#define SPI_CPOL   (1 << 1)
 Clock polarity. More...
 
#define SPI_MODE_0   0
 SPI mode 0. More...
 
#define SPI_MODE_1   (SPI_CPHA)
 SPI mode 1. More...
 
#define SPI_MODE_2   (SPI_CPOL)
 SPI mode 2. More...
 
#define SPI_MODE_3   (SPI_CPOL | SPI_CPHA)
 SPI mode 3. More...
 
#define SPI_TYPE_DEFS
 
SPI Master Management Configuration
#define CONFIG_SPI_MASTER_DELAY_BCS   0
 Default Configuration of SPI Master Delay BCS. More...
 
#define CONFIG_SPI_MASTER_BITS_PER_TRANSFER   SPI_CSR_BITS_8_BIT
 Default Configuration of SPI Master Bits per Transfer Definition. More...
 
#define CONFIG_SPI_MASTER_DELAY_BCT   0
 Default Configuration of SPI Master Delay BCT. More...
 
#define CONFIG_SPI_MASTER_DELAY_BS   0
 Default Configuration of SPI Master Delay BS. More...
 
#define CONFIG_SPI_MASTER_DUMMY   0xFF
 Default Configuration of SPI Master Dummy Field. More...
 

Typedefs

typedef uint32_t board_spi_select_id_t
 Board SPI Select Id Definition. More...
 
typedef uint8_t spi_flags_t
 SPI Flags Definition. 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...
 
static void spi_read_single (Spi *p_spi, uint8_t *data)
 Receive one byte 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...
 
static void spi_write_single (Spi *p_spi, uint8_t data)
 Write one byte to an SPI device. More...
 

Detailed Description

SPI master common service for SAM.

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

Definition in file sam_spi/spi_master.h.

Macro Definition Documentation

◆ CONFIG_SPI_MASTER_BITS_PER_TRANSFER

#define CONFIG_SPI_MASTER_BITS_PER_TRANSFER   SPI_CSR_BITS_8_BIT

Default Configuration of SPI Master Bits per Transfer Definition.

Definition at line 64 of file sam_spi/spi_master.h.

◆ CONFIG_SPI_MASTER_DELAY_BCS

#define CONFIG_SPI_MASTER_DELAY_BCS   0

Default Configuration of SPI Master Delay BCS.

Definition at line 59 of file sam_spi/spi_master.h.

◆ CONFIG_SPI_MASTER_DELAY_BCT

#define CONFIG_SPI_MASTER_DELAY_BCT   0

Default Configuration of SPI Master Delay BCT.

Definition at line 69 of file sam_spi/spi_master.h.

◆ CONFIG_SPI_MASTER_DELAY_BS

#define CONFIG_SPI_MASTER_DELAY_BS   0

Default Configuration of SPI Master Delay BS.

Definition at line 74 of file sam_spi/spi_master.h.

◆ CONFIG_SPI_MASTER_DUMMY

#define CONFIG_SPI_MASTER_DUMMY   0xFF

Default Configuration of SPI Master Dummy Field.

Definition at line 79 of file sam_spi/spi_master.h.

◆ SPI_CPHA

#define SPI_CPHA   (1 << 0)

Clock phase.

Definition at line 86 of file sam_spi/spi_master.h.

◆ SPI_CPOL

#define SPI_CPOL   (1 << 1)

Clock polarity.

Definition at line 91 of file sam_spi/spi_master.h.

◆ SPI_MODE_0

#define SPI_MODE_0   0

SPI mode 0.

Definition at line 96 of file sam_spi/spi_master.h.

◆ SPI_MODE_1

#define SPI_MODE_1   (SPI_CPHA)

SPI mode 1.

Definition at line 100 of file sam_spi/spi_master.h.

◆ SPI_MODE_2

#define SPI_MODE_2   (SPI_CPOL)

SPI mode 2.

Definition at line 104 of file sam_spi/spi_master.h.

◆ SPI_MODE_3

#define SPI_MODE_3   (SPI_CPOL | SPI_CPHA)

SPI mode 3.

Definition at line 108 of file sam_spi/spi_master.h.

◆ SPI_TYPE_DEFS

#define SPI_TYPE_DEFS

Definition at line 111 of file sam_spi/spi_master.h.

Typedef Documentation

◆ board_spi_select_id_t

typedef uint32_t board_spi_select_id_t

Board SPI Select Id Definition.

Definition at line 116 of file sam_spi/spi_master.h.

◆ spi_flags_t

typedef uint8_t spi_flags_t

SPI Flags Definition.

Definition at line 113 of file sam_spi/spi_master.h.

Function Documentation

◆ 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.

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

Definition at line 155 of file spi_master.c.

◆ spi_master_init()

void spi_master_init ( Spi p_spi)

Initialize the SPI in master mode.

Parameters
p_spiBase address of the SPI instance.

Definition at line 68 of file spi_master.c.

◆ spi_master_setup_device()

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.

Parameters
p_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.

Definition at line 100 of file spi_master.c.

◆ spi_read_packet()

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 0xff.

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

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

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

Definition at line 215 of file spi_master.c.

◆ spi_read_single()

static void spi_read_single ( Spi p_spi,
uint8_t *  data 
)
inlinestatic

Receive one byte from an SPI device.

Parameters
p_spiBase address of the SPI instance.
dataData to read.

Definition at line 204 of file sam_spi/spi_master.h.

◆ spi_select_device()

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.

Parameters
p_spiBase address of the SPI instance.
deviceSPI device.

Definition at line 132 of file spi_master.c.

◆ spi_transceive_packet()

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.

Parameters
p_spiBase address of the SPI instance.
tx_dataData buffer to send.
rx_dataData buffer to read.
lenLength of data to be read.
Precondition
SPI device must be selected with spi_select_device() first.

Definition at line 256 of file spi_master.c.

◆ spi_write_packet()

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.

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

Definition at line 181 of file spi_master.c.

◆ spi_write_single()

static void spi_write_single ( Spi p_spi,
uint8_t  data 
)
inlinestatic

Write one byte to an SPI device.

Parameters
p_spiBase address of the SPI instance.
dataData to write.

Definition at line 179 of file sam_spi/spi_master.h.



inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:18:00