Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
SPI Interface
+ Collaboration diagram for SPI Interface:

Data Structures

struct  spi_transaction
 SPI transaction structure. More...
 
struct  spi_periph
 

Macros

#define SPI_TRANSACTION_QUEUE_LEN   8
 
#define SPI_SLAVE0   0
 
#define SPI_SLAVE1   1
 
#define SPI_SLAVE2   2
 
#define SPI_SLAVE3   3
 
#define SPI_SLAVE4   4
 
#define SPI_SLAVE5   5
 

Typedefs

typedef void(* SPICallback )(struct spi_transaction *trans)
 SPI Callback function. More...
 

Enumerations

enum  SPIMode { SPIMaster, SPISlave }
 
enum  SPISlaveSelect { SPISelectUnselect, SPISelect, SPIUnselect, SPINoSelect }
 SPI slave selection behavior options. More...
 
enum  SPIClockPhase { SPICphaEdge1, SPICphaEdge2 }
 SPI CPHA (clock phase) options. More...
 
enum  SPIClockPolarity { SPICpolIdleLow, SPICpolIdleHigh }
 SPI CPOL (clock polarity) options. More...
 
enum  SPIDataSizeSelect { SPIDss8bit, SPIDss16bit }
 SPI data word size of transfer. More...
 
enum  SPITransactionStatus {
  SPITransPending, SPITransRunning, SPITransSuccess, SPITransFailed,
  SPITransDone
}
 SPI transaction status. More...
 
enum  SPIStatus { SPIIdle, SPIRunning }
 SPI peripheral status. More...
 
enum  SPIBitOrder { SPIMSBFirst, SPILSBFirst }
 
enum  SPIClockDiv {
  SPIDiv2, SPIDiv4, SPIDiv8, SPIDiv16,
  SPIDiv32, SPIDiv64, SPIDiv128, SPIDiv256
}
 Peripheral clock divider. More...
 

Functions

void spi0_init (void)
 
void spi0_arch_init (void)
 Architecture dependant SPI0 initialization. More...
 
void spi1_init (void)
 
void spi1_arch_init (void)
 Architecture dependant SPI1 initialization. More...
 
void spi2_init (void)
 
void spi2_arch_init (void)
 Architecture dependant SPI2 initialization. More...
 
void spi_init (struct spi_periph *p)
 Initialize a spi peripheral. More...
 
void spi_init_slaves (void)
 Initialize all used slaves and uselect them. More...
 
bool_t spi_submit (struct spi_periph *p, struct spi_transaction *t)
 Submit a spi transaction. More...
 
void spi_slave_select (uint8_t slave)
 Select a slave. More...
 
void spi_slave_unselect (uint8_t slave)
 Unselect a slave. More...
 
bool_t spi_lock (struct spi_periph *p, uint8_t slave)
 Lock the SPI fifo. More...
 
bool_t spi_resume (struct spi_periph *p, uint8_t slave)
 Resume the SPI fifo. More...
 
void spi_slave_init (struct spi_periph *p)
 Initialize a spi peripheral in slave mode. More...
 
bool_t spi_slave_register (struct spi_periph *p, struct spi_transaction *t)
 Register a spi transaction in slave mode (only one transaction can be registered). More...
 
bool_t spi_slave_wait (struct spi_periph *p)
 Initialized and wait for the next transaction. More...
 

Variables

struct spi_periph spi0
 
struct spi_periph spi1
 
struct spi_periph spi2
 

Detailed Description

Macro Definition Documentation

#define SPI_SLAVE0   0

Definition at line 181 of file spi.h.

Referenced by mcp355x_init(), spi_init_slaves(), SpiSlaveSelect(), and SpiSlaveUnselect().

#define SPI_SLAVE1   1

Definition at line 182 of file spi.h.

Referenced by spi_init_slaves(), SpiSlaveSelect(), and SpiSlaveUnselect().

#define SPI_SLAVE2   2

Definition at line 183 of file spi.h.

#define SPI_SLAVE3   3

Definition at line 184 of file spi.h.

#define SPI_SLAVE4   4

Definition at line 185 of file spi.h.

#define SPI_SLAVE5   5

Definition at line 186 of file spi.h.

#define SPI_TRANSACTION_QUEUE_LEN   8

Definition at line 160 of file spi.h.

Referenced by spi_next_transaction(), spi_submit(), and SpiEndOfTransaction().

Typedef Documentation

typedef void(* SPICallback)(struct spi_transaction *trans)

SPI Callback function.

If not NULL (or 0), call function (with transaction as parameter) before or after transaction, e.g to allow execution of hardware specific actions

Definition at line 130 of file spi.h.

Enumeration Type Documentation

Enumerator
SPIMSBFirst 
SPILSBFirst 

Definition at line 105 of file spi.h.

Peripheral clock divider.

Defines the SPI baudrate

Enumerator
SPIDiv2 
SPIDiv4 
SPIDiv8 
SPIDiv16 
SPIDiv32 
SPIDiv64 
SPIDiv128 
SPIDiv256 

Definition at line 113 of file spi.h.

SPI CPHA (clock phase) options.

Control whether data line is sampled at first or second edge of clock signal.

Enumerator
SPICphaEdge1 

CPHA = 0.

SPICphaEdge2 

CPHA = 1.

Definition at line 67 of file spi.h.

SPI CPOL (clock polarity) options.

Control whether clock line is held low or high in idle state.

Enumerator
SPICpolIdleLow 

CPOL = 0.

SPICpolIdleHigh 

CPOL = 1.

Definition at line 76 of file spi.h.

SPI data word size of transfer.

Enumerator
SPIDss8bit 
SPIDss16bit 

Definition at line 83 of file spi.h.

enum SPIMode
Enumerator
SPIMaster 
SPISlave 

Definition at line 46 of file spi.h.

SPI slave selection behavior options.

Default operation should be SelectUnselected, but some peripherals might need some special control. Use non-default control only if you know what you're doing.

Enumerator
SPISelectUnselect 

slave is selected before transaction and unselected after

SPISelect 

slave is selected before transaction but not unselected

SPIUnselect 

slave is not selected but unselected after transaction

SPINoSelect 

slave is not selected nor unselected

Definition at line 56 of file spi.h.

enum SPIStatus

SPI peripheral status.

Enumerator
SPIIdle 
SPIRunning 

Definition at line 100 of file spi.h.

SPI transaction status.

Enumerator
SPITransPending 
SPITransRunning 
SPITransSuccess 
SPITransFailed 
SPITransDone 

Definition at line 90 of file spi.h.

Function Documentation

void spi0_arch_init ( void  )

Architecture dependant SPI0 initialization.

Must be implemented by underlying architecture

Definition at line 396 of file spi_arch.c.

References spi_periph::init_struct, spi_periph::reg_addr, spi0, SPI0, and VIC_SPI0.

Referenced by spi0_init().

+ Here is the caller graph for this function:

void spi0_init ( void  )

Definition at line 37 of file spi.c.

References spi0, spi0_arch_init(), and spi_init().

Referenced by mcu_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void spi1_init ( void  )

Definition at line 47 of file spi.c.

References spi1, spi1_arch_init(), and spi_init().

Referenced by mcu_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void spi2_init ( void  )

Definition at line 57 of file spi.c.

References spi2, spi2_arch_init(), and spi_init().

Referenced by mcu_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void spi_init ( struct spi_periph p)

Initialize a spi peripheral.

Parameters
pspi peripheral to be configured

Definition at line 74 of file spi.c.

References FALSE, spi_periph::mode, SPIIdle, SPIMaster, spi_periph::status, spi_periph::suspend, spi_periph::trans_extract_idx, and spi_periph::trans_insert_idx.

Referenced by main_init(), spi0_init(), spi1_init(), and spi2_init().

+ Here is the caller graph for this function:

bool_t spi_lock ( struct spi_periph p,
uint8_t  slave 
)

Lock the SPI fifo.

This will stop the SPI fifo after the current transaction if any, or before the next one if none are pending. Only the slave that locks the fifo can unlock it.

Parameters
pspi peripheral to be used
slaveslave id
Returns
true if correctly locked

Definition at line 535 of file spi_arch.c.

References FALSE, spi_periph::init_struct, spi_arch_int_disable(), spi_arch_int_enable(), spi_periph::suspend, TRUE, VIC_BIT, VICIntEnable, and VICIntEnClear.

Referenced by max1168_lock_cb().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool_t spi_resume ( struct spi_periph p,
uint8_t  slave 
)

Resume the SPI fifo.

Only the slave that locks the fifo can unlock it.

Parameters
pspi peripheral to be used
slaveslave id
Returns
true if correctly unlocked

Definition at line 547 of file spi_arch.c.

References FALSE, spi_periph::init_struct, spi_arch_int_disable(), spi_arch_int_enable(), spi_start_dma_transaction(), SPIIdle, SpiStart(), spi_periph::status, spi_periph::suspend, spi_periph::trans, spi_periph::trans_extract_idx, spi_periph::trans_insert_idx, TRUE, VIC_BIT, VICIntEnable, and VICIntEnClear.

Referenced by max1168_event().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void spi_slave_init ( struct spi_periph p)

Initialize a spi peripheral in slave mode.

Parameters
pspi peripheral to be configured

Definition at line 127 of file spi.c.

References FALSE, spi_periph::mode, SPIIdle, SPISlave, spi_periph::status, spi_periph::suspend, spi_periph::trans_extract_idx, and spi_periph::trans_insert_idx.

bool_t spi_slave_register ( struct spi_periph p,
struct spi_transaction t 
)

Register a spi transaction in slave mode (only one transaction can be registered).

Must be implemented by the underlying architecture

Parameters
pspi peripheral to be used
tspi transaction
Returns
return true if registered with success

Register a spi transaction in slave mode (only one transaction can be registered).

Definition at line 647 of file spi_arch.c.

References spi_transaction::cpha, spi_transaction::cpol, spi_transaction::dss, FALSE, SpiClearCPHA(), SpiClearCPOL(), SPICphaEdge2, SPICpolIdleHigh, SPIIdle, SpiSetCPHA(), SpiSetCPOL(), SpiSetDataSize(), SPITransFailed, SPITransPending, spi_transaction::status, spi_periph::status, spi_periph::trans, spi_periph::trans_insert_idx, and TRUE.

+ Here is the call graph for this function:

void spi_slave_select ( uint8_t  slave)

Select a slave.

Parameters
slaveslave id

Definition at line 527 of file spi_arch.c.

References SpiSlaveSelect().

+ Here is the call graph for this function:

void spi_slave_unselect ( uint8_t  slave)

Unselect a slave.

Parameters
slaveslave id

Definition at line 531 of file spi_arch.c.

References SpiSlaveUnselect().

Referenced by max1168_event().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool_t spi_slave_wait ( struct spi_periph p)

Initialized and wait for the next transaction.

If a transaction is registered for this peripheral, the spi will be waiting for a communication from the master

Parameters
pspi peripheral to be used
Returns
return true if a transaction was register for this peripheral

Definition at line 670 of file spi_arch.c.

References FALSE, SpiSlaveStart(), spi_periph::trans, spi_periph::trans_extract_idx, spi_periph::trans_insert_idx, and TRUE.

+ Here is the call graph for this function:

Variable Documentation

struct spi_periph spi0
Todo:
SPI error struct

Definition at line 35 of file spi.c.

Referenced by spi0_arch_init(), and spi0_init().

struct spi_periph spi1

Definition at line 45 of file spi.c.

Referenced by dma1_channel3_isr(), mcp355x_read(), spi1_arch_init(), spi1_init(), and spi1_ISR().

struct spi_periph spi2

Definition at line 55 of file spi.c.

Referenced by dma1_channel5_isr(), spi2_arch_init(), and spi2_init().