Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
spi_arch.c File Reference

Handling of SPI hardware for lpc21xx. More...

#include "mcu_periph/spi.h"
#include "std.h"
#include "LPC21xx.h"
#include "armVIC.h"
#include <BOARD_CONFIG>
+ Include dependency graph for spi_arch.c:

Go to the source code of this file.

Macros

#define SSP_PINSEL1_SCK   (2 << 2)
 
#define SSP_PINSEL1_MISO   (2 << 4)
 
#define SSP_PINSEL1_MOSI   (2 << 6)
 
#define SSP_PINSEL1_SSEL   (2 << 8)
 
#define SPI1_VIC_SLOT   7
 default initial settings More...
 
#define MASTER_SSP_DSS   0x07 << 0
 data size : 8 bits More...
 
#define MASTER_SSP_FRF   0x00 << 4
 frame format : SPI More...
 
#define MASTER_SSP_CPOL   0x00 << 6
 clock polarity : SCK idles low More...
 
#define MASTER_SSP_CPHA   0x00 << 7
 clock phase : data captured on first clock transition More...
 
#define MASTER_SSP_SCR   0x0F << 8
 serial clock rate : divide by 16 More...
 
#define MASTER_SSP_LBM   0x00 << 0
 loopback mode : disabled More...
 
#define MASTER_SSP_SSE   0x00 << 1
 SSP enable : disabled. More...
 
#define MASTER_SSP_MS   0x00 << 2
 master slave mode : master More...
 
#define MASTER_SSP_SOD   0x00 << 3
 slave output disable : don't care when master More...
 
#define SSPCPSR_VAL   0x02 /* clock prescale */
 Clock prescaler. More...
 

Functions

static void SpiSetDataSize (struct spi_periph *p, enum SPIDataSizeSelect dss)
 Set the SPI data size to 8 or 16bit. More...
 
void spi0_arch_init (void)
 Architecture dependent SPI0 initialization. More...
 
void spi1_ISR (void)
 
void spi1_arch_init (void)
 Architecture dependent SPI1 initialization. More...
 
bool spi_submit (struct spi_periph *p, struct spi_transaction *t)
 Submit a spi transaction. More...
 
void spi_init_slaves (void)
 Initialize all used slaves and unselect them. More...
 
void spi_slave_select (uint8_t slave)
 Select a slave. More...
 
void spi_slave_unselect (uint8_t slave)
 Unselect a slave. More...
 
bool spi_lock (struct spi_periph *p, uint8_t slave)
 Lock the SPI fifo. More...
 
bool spi_resume (struct spi_periph *p, uint8_t slave)
 Resume the SPI fifo. More...
 
bool spi_slave_register (struct spi_periph *p, struct spi_transaction *t)
 Register one (and only one) transaction to use spi as slave. More...
 
bool spi_slave_wait (struct spi_periph *p)
 Initialized and wait for the next transaction. More...
 
SPI clock

Spi clock polarity and phase functions.

static void SpiSetCPOL (struct spi_periph *p)
 
static void SpiClearCPOL (struct spi_periph *p)
 
static void SpiSetCPHA (struct spi_periph *p)
 
static void SpiClearCPHA (struct spi_periph *p)
 
SPI control

Spi control functions.

static void SpiEnable (struct spi_periph *p)
 
static void SpiDisable (struct spi_periph *p)
 
static void SpiEnableRti (struct spi_periph *p)
 
static void SpiDisableRti (struct spi_periph *p)
 
static void SpiClearRti (struct spi_periph *p)
 
static void SpiEnableTxi (struct spi_periph *p)
 
static void SpiDisableTxi (struct spi_periph *p)
 
static void SpiEnableRxi (struct spi_periph *p)
 
static void SpiDisableRxi (struct spi_periph *p)
 
static void SpiSend (struct spi_periph *p, uint16_t c)
 
static void SpiRead (struct spi_periph *p, uint16_t *c)
 
static void SpiTransmit (struct spi_periph *p, struct spi_transaction *t)
 
static void SpiReceive (struct spi_periph *p, struct spi_transaction *t)
 
static void SpiInitBuf (struct spi_periph *p, struct spi_transaction *t)
 
static void SpiStart (struct spi_periph *p, struct spi_transaction *t)
 
static void SpiEndOfTransaction (struct spi_periph *p, struct spi_transaction *t)
 
static void SpiAutomaton (struct spi_periph *p)
 
static void SpiSlaveStart (struct spi_periph *p, struct spi_transaction *t)
 
static void SpiSlaveAutomaton (struct spi_periph *p)
 

Variables

uint8_t spi0_vic_slot
 
uint8_t spi1_vic_slot
 

Slave selection

Slave selection functions and macros.

#define SPI_SELECT_SLAVE_IO__(port, reg)   IO ## port ## reg
 
#define SPI_SELECT_SLAVE_IO_(port, reg)   SPI_SELECT_SLAVE_IO__(port, reg)
 
#define SPI_SELECT_SLAVE0_IODIR   SPI_SELECT_SLAVE_IO_(SPI_SELECT_SLAVE0_PORT, DIR)
 
#define SPI_SELECT_SLAVE0_IOCLR   SPI_SELECT_SLAVE_IO_(SPI_SELECT_SLAVE0_PORT, CLR)
 
#define SPI_SELECT_SLAVE0_IOSET   SPI_SELECT_SLAVE_IO_(SPI_SELECT_SLAVE0_PORT, SET)
 
#define SPI_SELECT_SLAVE1_IODIR   SPI_SELECT_SLAVE_IO_(SPI_SELECT_SLAVE1_PORT, DIR)
 
#define SPI_SELECT_SLAVE1_IOCLR   SPI_SELECT_SLAVE_IO_(SPI_SELECT_SLAVE1_PORT, CLR)
 
#define SPI_SELECT_SLAVE1_IOSET   SPI_SELECT_SLAVE_IO_(SPI_SELECT_SLAVE1_PORT, SET)
 
static void SpiSlaveSelect (uint8_t slave)
 
static void SpiSlaveUnselect (uint8_t slave)
 

Detailed Description

Handling of SPI hardware for lpc21xx.

for now only SPI1 ( aka SSP )

TODO current implementation only works for SPI1 (SSP)

Definition in file spi_arch.c.

Macro Definition Documentation

#define MASTER_SSP_CPHA   0x00 << 7

clock phase : data captured on first clock transition

Definition at line 436 of file spi_arch.c.

Referenced by spi1_arch_init().

#define MASTER_SSP_CPOL   0x00 << 6

clock polarity : SCK idles low

Definition at line 435 of file spi_arch.c.

Referenced by spi1_arch_init().

#define MASTER_SSP_DSS   0x07 << 0

data size : 8 bits

Definition at line 433 of file spi_arch.c.

Referenced by spi1_arch_init().

#define MASTER_SSP_FRF   0x00 << 4

frame format : SPI

Definition at line 434 of file spi_arch.c.

Referenced by spi1_arch_init().

#define MASTER_SSP_LBM   0x00 << 0

loopback mode : disabled

Definition at line 440 of file spi_arch.c.

Referenced by spi1_arch_init().

#define MASTER_SSP_MS   0x00 << 2

master slave mode : master

Definition at line 442 of file spi_arch.c.

Referenced by spi1_arch_init().

#define MASTER_SSP_SCR   0x0F << 8

serial clock rate : divide by 16

Definition at line 437 of file spi_arch.c.

Referenced by spi1_arch_init().

#define MASTER_SSP_SOD   0x00 << 3

slave output disable : don't care when master

Definition at line 443 of file spi_arch.c.

Referenced by spi1_arch_init().

#define MASTER_SSP_SSE   0x00 << 1

SSP enable : disabled.

Definition at line 441 of file spi_arch.c.

#define SPI1_VIC_SLOT   7

default initial settings

Definition at line 392 of file spi_arch.c.

Referenced by spi1_arch_init().

#define SPI_SELECT_SLAVE0_IOCLR   SPI_SELECT_SLAVE_IO_(SPI_SELECT_SLAVE0_PORT, CLR)

Definition at line 48 of file spi_arch.c.

Referenced by SpiSlaveSelect().

#define SPI_SELECT_SLAVE0_IODIR   SPI_SELECT_SLAVE_IO_(SPI_SELECT_SLAVE0_PORT, DIR)

Definition at line 47 of file spi_arch.c.

Referenced by spi_init_slaves().

#define SPI_SELECT_SLAVE0_IOSET   SPI_SELECT_SLAVE_IO_(SPI_SELECT_SLAVE0_PORT, SET)

Definition at line 49 of file spi_arch.c.

Referenced by SpiSlaveUnselect().

#define SPI_SELECT_SLAVE1_IOCLR   SPI_SELECT_SLAVE_IO_(SPI_SELECT_SLAVE1_PORT, CLR)

Definition at line 52 of file spi_arch.c.

Referenced by SpiSlaveSelect().

#define SPI_SELECT_SLAVE1_IODIR   SPI_SELECT_SLAVE_IO_(SPI_SELECT_SLAVE1_PORT, DIR)

Definition at line 51 of file spi_arch.c.

Referenced by spi_init_slaves().

#define SPI_SELECT_SLAVE1_IOSET   SPI_SELECT_SLAVE_IO_(SPI_SELECT_SLAVE1_PORT, SET)

Definition at line 53 of file spi_arch.c.

Referenced by SpiSlaveUnselect().

#define SPI_SELECT_SLAVE_IO_ (   port,
  reg 
)    SPI_SELECT_SLAVE_IO__(port, reg)

Definition at line 45 of file spi_arch.c.

#define SPI_SELECT_SLAVE_IO__ (   port,
  reg 
)    IO ## port ## reg

Definition at line 44 of file spi_arch.c.

#define SSP_PINSEL1_MISO   (2 << 4)

Definition at line 386 of file spi_arch.c.

Referenced by max11040_hw_init(), micromag_hw_init(), and spi1_arch_init().

#define SSP_PINSEL1_MOSI   (2 << 6)

Definition at line 387 of file spi_arch.c.

Referenced by max11040_hw_init(), micromag_hw_init(), and spi1_arch_init().

#define SSP_PINSEL1_SCK   (2 << 2)

Definition at line 385 of file spi_arch.c.

Referenced by max11040_hw_init(), micromag_hw_init(), and spi1_arch_init().

#define SSP_PINSEL1_SSEL   (2 << 8)

Definition at line 388 of file spi_arch.c.

Referenced by max11040_hw_init().

#define SSPCPSR_VAL   0x02 /* clock prescale */

Clock prescaler.

SPI clock rate = PCLK / (CPSR*(SCR+1)) with PCLK = 30 MHz, CPSR = 2 and SCR = 15 -> clock ~ 1 MHz

Definition at line 450 of file spi_arch.c.

Referenced by spi1_arch_init().

Function Documentation

void spi1_ISR ( void  )

Definition at line 455 of file spi_arch.c.

References ISR_ENTRY, ISR_EXIT, spi1, SpiAutomaton(), and VICVectAddr.

Referenced by spi1_arch_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void SpiAutomaton ( struct spi_periph p)
inlinestatic

Definition at line 306 of file spi_arch.c.

References BSY, spi_transaction::input_length, spi_transaction::output_length, RTMIS, SpiClearRti(), SpiDisableRti(), SpiEnableTxi(), SpiEndOfTransaction(), SpiReceive(), SpiTransmit(), and TXMIS.

Referenced by spi1_ISR().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void SpiClearCPHA ( struct spi_periph p)
inlinestatic

Definition at line 111 of file spi_arch.c.

References CPHA.

Referenced by spi_slave_register(), and SpiStart().

+ Here is the caller graph for this function:

static void SpiClearCPOL ( struct spi_periph p)
inlinestatic

Definition at line 101 of file spi_arch.c.

References CPOL.

Referenced by spi_slave_register(), and SpiStart().

+ Here is the caller graph for this function:

static void SpiClearRti ( struct spi_periph p)
inlinestatic

Definition at line 161 of file spi_arch.c.

References RTIC.

Referenced by ADS8344_start(), lcd_spi_tx(), SPI1_ISR(), SpiAutomaton(), and SpiSlaveAutomaton().

+ Here is the caller graph for this function:

static void SpiDisable ( struct spi_periph p)
inlinestatic

Definition at line 146 of file spi_arch.c.

References SSE.

Referenced by SpiEndOfTransaction(), and SpiSlaveAutomaton().

+ Here is the caller graph for this function:

static void SpiDisableRti ( struct spi_periph p)
inlinestatic

Definition at line 156 of file spi_arch.c.

References RTIM.

Referenced by SPI1_ISR(), SpiAutomaton(), and SpiSlaveAutomaton().

+ Here is the caller graph for this function:

static void SpiDisableRxi ( struct spi_periph p)
inlinestatic

Definition at line 181 of file spi_arch.c.

References RXIM.

static void SpiDisableTxi ( struct spi_periph p)
inlinestatic

Definition at line 171 of file spi_arch.c.

References TXIM.

Referenced by SpiTransmit().

+ Here is the caller graph for this function:

static void SpiEnable ( struct spi_periph p)
inlinestatic

Definition at line 141 of file spi_arch.c.

Referenced by SpiSlaveStart(), and SpiStart().

+ Here is the caller graph for this function:

static void SpiEnableRti ( struct spi_periph p)
inlinestatic

Definition at line 151 of file spi_arch.c.

References RTIM.

Referenced by ADS8344_start(), baro_scp_start_high_res_measurement(), lcd_spi_tx(), SpiSlaveAutomaton(), and SpiStart().

+ Here is the caller graph for this function:

static void SpiEnableRxi ( struct spi_periph p)
inlinestatic

Definition at line 176 of file spi_arch.c.

References RXIM.

static void SpiEnableTxi ( struct spi_periph p)
inlinestatic

Definition at line 166 of file spi_arch.c.

References TXIM.

Referenced by SpiAutomaton(), SpiSlaveStart(), and SpiStart().

+ Here is the caller graph for this function:

static void SpiEndOfTransaction ( struct spi_periph p,
struct spi_transaction t 
)
inlinestatic

Definition at line 278 of file spi_arch.c.

References SPI_TRANSACTION_QUEUE_LEN, SpiDisable(), SPIIdle, SPISelectUnselect, SpiSlaveUnselect(), SpiStart(), SPITransSuccess, and SPIUnselect.

Referenced by SpiAutomaton().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void SpiInitBuf ( struct spi_periph p,
struct spi_transaction t 
)
inlinestatic

Definition at line 241 of file spi_arch.c.

References SpiTransmit().

Referenced by SpiSlaveStart(), and SpiStart().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void SpiRead ( struct spi_periph p,
uint16_t c 
)
inlinestatic

Definition at line 191 of file spi_arch.c.

Referenced by SpiReceive().

+ Here is the caller graph for this function:

static void SpiReceive ( struct spi_periph p,
struct spi_transaction t 
)
inlinestatic

Definition at line 221 of file spi_arch.c.

References foo, RNE, SPIDss16bit, SPIDss8bit, and SpiRead().

Referenced by SpiAutomaton(), and SpiSlaveAutomaton().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void SpiSend ( struct spi_periph p,
uint16_t  c 
)
inlinestatic

Definition at line 186 of file spi_arch.c.

Referenced by SpiTransmit().

+ Here is the caller graph for this function:

static void SpiSetCPHA ( struct spi_periph p)
inlinestatic

Definition at line 106 of file spi_arch.c.

References CPHA.

Referenced by baro_MS5534A_send(), spi_slave_register(), and SpiStart().

+ Here is the caller graph for this function:

static void SpiSetCPOL ( struct spi_periph p)
inlinestatic

Definition at line 96 of file spi_arch.c.

Referenced by spi_slave_register(), and SpiStart().

+ Here is the caller graph for this function:

static void SpiSetDataSize ( struct spi_periph p,
enum SPIDataSizeSelect  dss 
)
inlinestatic

Set the SPI data size to 8 or 16bit.

Parameters
pSPI peripheral to set
dssdata size

Definition at line 123 of file spi_arch.c.

References DSS, DSS_VAL16, DSS_VAL8, SPIDss16bit, and SPIDss8bit.

Referenced by spi_slave_register(), and SpiStart().

+ Here is the caller graph for this function:

static void SpiSlaveAutomaton ( struct spi_periph p)
inlinestatic
static void SpiSlaveSelect ( uint8_t  slave)
inlinestatic

Definition at line 55 of file spi_arch.c.

References SPI_SELECT_SLAVE0_IOCLR, SPI_SELECT_SLAVE0_PIN, SPI_SELECT_SLAVE1_IOCLR, SPI_SELECT_SLAVE1_PIN, SPI_SLAVE0, and SPI_SLAVE1.

Referenced by spi_slave_select(), and SpiStart().

+ Here is the caller graph for this function:

static void SpiSlaveStart ( struct spi_periph p,
struct spi_transaction t 
)
inlinestatic

Definition at line 335 of file spi_arch.c.

References SpiEnable(), SpiEnableTxi(), SpiInitBuf(), SPIRunning, and SPITransRunning.

Referenced by spi_slave_wait().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void SpiSlaveUnselect ( uint8_t  slave)
inlinestatic

Definition at line 73 of file spi_arch.c.

References SPI_SELECT_SLAVE0_IOSET, SPI_SELECT_SLAVE0_PIN, SPI_SELECT_SLAVE1_IOSET, SPI_SELECT_SLAVE1_PIN, SPI_SLAVE0, and SPI_SLAVE1.

Referenced by spi_init_slaves(), spi_slave_unselect(), and SpiEndOfTransaction().

+ Here is the caller graph for this function:

static void SpiStart ( struct spi_periph p,
struct spi_transaction t 
)
inlinestatic
static void SpiTransmit ( struct spi_periph p,
struct spi_transaction t 
)
inlinestatic

Definition at line 197 of file spi_arch.c.

References Max, SpiDisableTxi(), SPIDss16bit, SPIDss8bit, SpiSend(), and TNF.

Referenced by SpiAutomaton(), SpiInitBuf(), and SpiSlaveAutomaton().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

uint8_t spi0_vic_slot

Definition at line 415 of file spi_arch.c.

uint8_t spi1_vic_slot

Definition at line 465 of file spi_arch.c.