|
Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
|
Go to the documentation of this file.
39 #error "ChibiOS operates only in SPI_MASTER mode"
43 #error "ChibiOS architectures don't have SPI0"
47 #ifndef SPI_THREAD_STACK_SIZE
48 #define SPI_THREAD_STACK_SIZE 512
59 #define SPI_DMA_BUF_LEN 512 // it has to be big enough
76 #endif // USE_SPI_SLAVE0
81 #endif //USE_SPI_SLAVE1
86 #endif //USE_SPI_SLAVE2
91 #endif //USE_SPI_SLAVE3
96 #endif //USE_SPI_SLAVE4
101 #endif //USE_SPI_SLAVE5
123 #endif // USE_SPI_SLAVE0
128 #endif //USE_SPI_SLAVE1
133 #endif //USE_SPI_SLAVE2
138 #endif //USE_SPI_SLAVE3
143 #endif //USE_SPI_SLAVE4
148 #endif //USE_SPI_SLAVE5
170 #if defined(STM32F1) || defined(STM32F4)
175 #if defined(STM32F1) || defined(STM32F4) || defined(STM32F7)
177 CR1 |= SPI_CR1_LSBFIRST;
196 CR1 |= SPI_CR1_BR_1 | SPI_CR1_BR_0;
202 CR1 |= SPI_CR1_BR_2 | SPI_CR1_BR_0;
205 CR1 |= SPI_CR1_BR_2 | SPI_CR1_BR_1;
234 CR2 |= SPI_CR2_DS_0 | SPI_CR2_DS_1 | SPI_CR2_DS_2 | SPI_CR2_DS_3;
236 CR2 |= SPI_CR2_DS_0 | SPI_CR2_DS_1 | SPI_CR2_DS_2;
254 if ((
p->trans_insert_idx ==
p->trans_extract_idx) ||
p->suspend) {
265 SPIConfig spi_cfg = {
275 static size_t t_length;
283 spiStart((SPIDriver *)
p->reg_addr, &spi_cfg);
286 spiSelect((SPIDriver *)
p->reg_addr);
299 spiExchange((SPIDriver *)
p->reg_addr, t_length, i->dma_buf_out, i->dma_buf_in);
307 spiUnselect((SPIDriver *)
p->reg_addr);
312 p->trans_extract_idx++;
314 p->trans_extract_idx = 0;
345 .dma_buf_out = spi1_dma_buf_out,
346 .dma_buf_in = spi1_dma_buf_in
354 static __attribute__((noreturn))
void thd_spi1(
void *arg)
357 chRegSetThreadName(
"spi1");
368 spi1.reg_addr = &SPID1;
371 chThdCreateStatic(wa_thd_spi1,
sizeof(wa_thd_spi1),
384 .dma_buf_out = spi2_dma_buf_out,
385 .dma_buf_in = spi2_dma_buf_in
393 static __attribute__((noreturn))
void thd_spi2(
void *arg)
396 chRegSetThreadName(
"spi2");
407 spi2.reg_addr = &SPID2;
410 chThdCreateStatic(wa_thd_spi2,
sizeof(wa_thd_spi2),
421 static struct spi_init spi3_init_s = {
423 .dma_buf_out = spi3_dma_buf_out,
424 .dma_buf_in = spi3_dma_buf_in
427 static struct spi_init spi3_init_s = {
432 static __attribute__((noreturn))
void thd_spi3(
void *arg)
435 chRegSetThreadName(
"spi3");
444 void spi3_arch_init(
void)
446 spi3.reg_addr = &SPID3;
447 spi3.init_struct = &spi3_init_s;
449 chThdCreateStatic(wa_thd_spi3,
sizeof(wa_thd_spi3),
450 NORMALPRIO + 1, thd_spi3, NULL);
460 static struct spi_init spi4_init_s = {
462 .dma_buf_out = spi4_dma_buf_out,
463 .dma_buf_in = spi4_dma_buf_in
466 static struct spi_init spi4_init_s = {
471 static __attribute__((noreturn))
void thd_spi4(
void *arg)
474 chRegSetThreadName(
"spi4");
483 void spi4_arch_init(
void)
485 spi4.reg_addr = &SPID4;
486 spi4.init_struct = &spi4_init_s;
488 chThdCreateStatic(wa_thd_spi4,
sizeof(wa_thd_spi4),
489 NORMALPRIO + 1, thd_spi4, NULL);
517 idx =
p->trans_insert_idx + 1;
529 p->trans[
p->trans_insert_idx] = t;
530 p->trans_insert_idx =
idx;
533 chSemSignal(((
struct spi_init *)
p->init_struct)->sem);
551 #endif // USE_SPI_SLAVE0
556 #endif //USE_SPI_SLAVE1
561 #endif //USE_SPI_SLAVE2
566 #endif //USE_SPI_SLAVE3
571 #endif //USE_SPI_SLAVE4
576 #endif //USE_SPI_SLAVE5
593 #endif // USE_SPI_SLAVE0
598 #endif //USE_SPI_SLAVE1
603 #endif //USE_SPI_SLAVE2
608 #endif //USE_SPI_SLAVE3
613 #endif //USE_SPI_SLAVE4
618 #endif //USE_SPI_SLAVE5
631 if (slave < 254 && p->suspend == 0) {
632 p->suspend = slave + 1;
645 if (
p->suspend == slave + 1) {
#define SPI_SELECT_SLAVE3_PIN
static SEMAPHORE_DECL(spi1_sem, 0)
Configure SPI peripherals.
static void handle_spi_thd(struct spi_periph *p)
main thread function
uint16_t output_length
number of data words to write
static void thd_spi1(void *arg)
static uint16_t spi_resolve_CR1(struct spi_transaction *t)
Resolve CR1.
SPI transaction structure.
#define SPI_THREAD_STACK_SIZE
static uint16_t spi_resolve_slave_pin(uint8_t slave)
Resolve slave pin.
#define SPI_SELECT_SLAVE4_PORT
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
#define SPI_SELECT_SLAVE3_PORT
@ SPISelectUnselect
slave is selected before transaction and unselected after
process_rx_dma_interrupt & spi2
receive transferred over DMA
#define SPI_SELECT_SLAVE0_PIN
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
SPI peripheral structure.
enum SPISlaveSelect select
slave selection behavior
void spi2_arch_init(void)
Architecture dependent SPI2 initialization.
@ SPIUnselect
slave is not selected but unselected after transaction
static void gpio_clear(ioportid_t port, uint16_t pin)
Clear a gpio output to low level.
#define SPI_SELECT_SLAVE0_PORT
#define SPI_SELECT_SLAVE1_PIN
SPICallback after_cb
NULL or function called after the transaction.
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
bool spi_resume(struct spi_periph *p, uint8_t slave)
spi_resume() function
#define IN_DMA_SECTION(var)
#define SPI_SELECT_SLAVE1_PORT
void spi_slave_unselect(uint8_t slave)
spi_slave_unselect() function
@ SPICpolIdleHigh
CPOL = 1.
static THD_WORKING_AREA(wa_thd_spi1, SPI_THREAD_STACK_SIZE)
#define SPI_SELECT_SLAVE2_PORT
void spi_slave_select(uint8_t slave)
spi_slave_select() function
bool spi_lock(struct spi_periph *p, uint8_t slave)
spi_lock() function
uint16_t input_length
number of data words to read
#define SPI_SELECT_SLAVE2_PIN
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
static ioportid_t spi_resolve_slave_port(uint8_t slave)
Resolve slave port.
@ SPISelect
slave is selected before transaction but not unselected
volatile uint8_t * input_buf
pointer to receive buffer for DMA
#define SPI_SELECT_SLAVE5_PIN
#define SPI_SELECT_SLAVE5_PORT
process_rx_dma_interrupt & spi1
receive transferred over DMA
#define SPI_SELECT_SLAVE4_PIN
void spi1_arch_init(void)
Architecture dependent SPI1 initialization.
SPICallback before_cb
NULL or function called before the transaction.
static void thd_spi2(void *arg)
static struct spi_init spi2_init_s
static void gpio_set(ioportid_t port, uint16_t pin)
Set a gpio output to high level.
void spi_init_slaves(void)
spi_init_slaves() function
static uint16_t spi_resolve_CR2(struct spi_transaction *t)
Resolve CR2.
#define SPI_TRANSACTION_QUEUE_LEN
SPI transaction queue length.
enum SPITransactionStatus status
static struct spi_init spi1_init_s