Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
spi_arch.c File Reference

Implementation of SPI interface for ChibiOS arch. More...

#include "mcu_periph/spi.h"
#include "mcu_periph/gpio.h"
#include <BOARD_CONFIG>
#include <string.h>
#include "mcu_periph/ram_arch.h"
Include dependency graph for spi_arch.c:

Go to the source code of this file.

Data Structures

struct  spi_init

Macros

#define SPI_THREAD_STACK_SIZE   512
#define SPI_DMA_BUF_LEN   512

Functions

static ioportid_t spi_resolve_slave_port (uint8_t slave)
 Resolve slave port.
static uint16_t spi_resolve_slave_pin (uint8_t slave)
 Resolve slave pin.
static uint32_t spi_resolve_CR1 (struct spi_transaction *t)
 Resolve CR1 (or CFG1).
static uint32_t spi_resolve_CR2 (struct spi_transaction *t)
 Resolve CR2 (or CFG2).
static void handle_spi_thd (struct spi_periph *p)
 main thread function
static void thd_spi (void *arg)
 Default spi thread.
static IN_DMA_SECTION (struct spi_init spi1_init_s)
 Configure SPI peripherals.
static THD_WORKING_AREA (wa_thd_spi1, SPI_THREAD_STACK_SIZE)
void spi1_arch_init (void)
 Architecture dependent SPI1 initialization.
static THD_WORKING_AREA (wa_thd_spi2, SPI_THREAD_STACK_SIZE)
void spi2_arch_init (void)
 Architecture dependent SPI2 initialization.
bool spi_submit (struct spi_periph *p, struct spi_transaction *t)
 Submit SPI transaction.
void spi_slave_select (uint8_t slave)
 spi_slave_select() function
void spi_slave_unselect (uint8_t slave)
 spi_slave_unselect() function
bool spi_lock (struct spi_periph *p, uint8_t slave)
 spi_lock() function
bool spi_resume (struct spi_periph *p, uint8_t slave)
 spi_resume() function
void spi_init_slaves (void)
 spi_init_slaves() function

Detailed Description

Implementation of SPI interface for ChibiOS arch.

Only Master mode is allowed in ChibiOS.

Definition in file spi_arch.c.


Data Structure Documentation

◆ spi_init

struct spi_init

Definition at line 58 of file spi_arch.c.

Data Fields
char * name
semaphore_t sem

Macro Definition Documentation

◆ SPI_DMA_BUF_LEN

#define SPI_DMA_BUF_LEN   512

Definition at line 54 of file spi_arch.c.

◆ SPI_THREAD_STACK_SIZE

#define SPI_THREAD_STACK_SIZE   512

Definition at line 49 of file spi_arch.c.

Referenced by THD_WORKING_AREA(), and THD_WORKING_AREA().

Function Documentation

◆ handle_spi_thd()

◆ IN_DMA_SECTION()

IN_DMA_SECTION ( struct spi_init spi1_init_s)
static
Initial value:
= {
.name = "spi2",
.sem = __SEMAPHORE_DATA(spi2_init_s.sem, 0),
}

Configure SPI peripherals.

◆ spi_resolve_CR1()

uint32_t spi_resolve_CR1 ( struct spi_transaction * t)
inlinestatic

Resolve CR1 (or CFG1).

Given the transaction settings, returns the right configuration of SPIx_CR1 register.

This function is currently architecture dependent (for STM32F1xx STM32F4xx, STM32F7xx and STM32H7xx only) TODO: extend for other architectures too

Parameters
[in]tpointer to a spi_transaction struct

Definition at line 213 of file spi_arch.c.

References SPICphaEdge2, SPICpolIdleHigh, SPIDiv128, SPIDiv16, SPIDiv2, SPIDiv256, SPIDiv32, SPIDiv4, SPIDiv64, SPIDiv8, SPIDss16bit, and SPILSBFirst.

Referenced by handle_spi_thd().

Here is the caller graph for this function:

◆ spi_resolve_CR2()

uint32_t spi_resolve_CR2 ( struct spi_transaction * t)
inlinestatic

Resolve CR2 (or CFG2).

Given the transaction settings, returns the right configuration of SPIx_CR2 register.

This function is currently architecture dependent (for STM32F1xx STM32F4xx, STM32F7xx and STM32H7xx only) TODO: extend for other architectures too

Parameters
[in]tpointer to a spi_transaction struct

Definition at line 283 of file spi_arch.c.

References SPICphaEdge2, SPICpolIdleHigh, SPIDss16bit, and SPILSBFirst.

Referenced by handle_spi_thd().

Here is the caller graph for this function:

◆ spi_resolve_slave_pin()

uint16_t spi_resolve_slave_pin ( uint8_t slave)
inlinestatic

Resolve slave pin.

Given the slave number and the board config file, returns the right pin (i.e. 12)

Parameters
[in]slaveindex number of a slave

Definition at line 142 of file spi_arch.c.

References SPI_SELECT_SLAVE0_PIN, SPI_SELECT_SLAVE1_PIN, SPI_SELECT_SLAVE2_PIN, SPI_SELECT_SLAVE3_PIN, SPI_SELECT_SLAVE4_PIN, and SPI_SELECT_SLAVE5_PIN.

Referenced by handle_spi_thd().

Here is the caller graph for this function:

◆ spi_resolve_slave_port()

ioportid_t spi_resolve_slave_port ( uint8_t slave)
inlinestatic

Resolve slave port.

Given the slave number and the board config file, returns the right port (i.e. GPIOC)

Parameters
[in]slaveindex number of a slave

Definition at line 75 of file spi_arch.c.

References SPI_SELECT_SLAVE0_PORT, SPI_SELECT_SLAVE1_PORT, SPI_SELECT_SLAVE2_PORT, SPI_SELECT_SLAVE3_PORT, SPI_SELECT_SLAVE4_PORT, and SPI_SELECT_SLAVE5_PORT.

Referenced by handle_spi_thd().

Here is the caller graph for this function:

◆ thd_spi()

void thd_spi ( void * arg)
static

Default spi thread.

Parameters
argThe SPI perpheral (struct spi_periph)

Definition at line 414 of file spi_arch.c.

References handle_spi_thd(), spi_periph::init_struct, spi_init::name, and TRUE.

Referenced by spi1_arch_init(), and spi2_arch_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ THD_WORKING_AREA() [1/2]

THD_WORKING_AREA ( wa_thd_spi1 ,
SPI_THREAD_STACK_SIZE  )
static

References SPI_THREAD_STACK_SIZE.

◆ THD_WORKING_AREA() [2/2]

THD_WORKING_AREA ( wa_thd_spi2 ,
SPI_THREAD_STACK_SIZE  )
static

References SPI_THREAD_STACK_SIZE.