|
Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
|
Go to the documentation of this file.
32 #include <sys/ioctl.h>
33 #include <linux/spi/spidev.h>
46 #pragma GCC diagnostic push
47 #pragma GCC diagnostic ignored "-Wcast-qual"
50 int fd = (int)
p->reg_addr;
52 struct spi_ioc_transfer xfer;
53 memset(&xfer, 0,
sizeof xfer);
59 uint8_t tx_buf[buf_len], rx_buf[buf_len];
60 memset(tx_buf, 0, buf_len);
61 memset(rx_buf, 0, buf_len);
67 xfer.tx_buf = (
unsigned long)tx_buf;
73 xfer.rx_buf = (
unsigned long)rx_buf;
75 xfer.rx_buf = (
unsigned long)t->
input_buf;
83 xfer.bits_per_word = 16;
85 xfer.bits_per_word = 8;
91 if (ioctl(
fd, SPI_IOC_MESSAGE(1), &xfer) < 0) {
104 #pragma GCC diagnostic pop
122 #define SPI0_MODE (SPI_CPOL | SPI_CPHA)
125 #ifndef SPI0_LSB_FIRST
126 #define SPI0_LSB_FIRST 0
129 #ifndef SPI0_BITS_PER_WORD
130 #define SPI0_BITS_PER_WORD 8
133 #ifndef SPI0_MAX_SPEED_HZ
134 #define SPI0_MAX_SPEED_HZ 1000000
139 int fd = open(
"/dev/spidev1.0", O_RDWR);
142 perror(
"Could not open SPI device /dev/spidev1.0");
150 if (ioctl(
fd, SPI_IOC_WR_MODE, &spi_mode) < 0) {
151 perror(
"SPI0: can't set spi mode");
156 if (ioctl(
fd, SPI_IOC_WR_LSB_FIRST, &spi_order) < 0) {
157 perror(
"SPI0: can't set spi bit justification");
162 if (ioctl(
fd, SPI_IOC_WR_BITS_PER_WORD, &spi_bits_per_word) < 0) {
163 perror(
"SPI0: can't set bits per word");
168 if (ioctl(
fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi_speed) < 0) {
169 perror(
"SPI0: can't set max speed hz");
178 #define SPI1_MODE (SPI_CPOL | SPI_CPHA)
181 #ifndef SPI1_LSB_FIRST
182 #define SPI1_LSB_FIRST 0
185 #ifndef SPI1_BITS_PER_WORD
186 #define SPI1_BITS_PER_WORD 8
189 #ifndef SPI1_MAX_SPEED_HZ
190 #define SPI1_MAX_SPEED_HZ 1000000
195 int fd = open(
"/dev/spidev1.1", O_RDWR);
198 perror(
"Could not open SPI device /dev/spidev1.1");
199 spi1.reg_addr = NULL;
202 spi1.reg_addr = (
void *)
fd;
206 if (ioctl(
fd, SPI_IOC_WR_MODE, &spi_mode) < 0) {
207 perror(
"SPI1: can't set spi mode");
212 if (ioctl(
fd, SPI_IOC_WR_LSB_FIRST, &spi_order) < 0) {
213 perror(
"SPI1: can't set spi bit justification");
218 if (ioctl(
fd, SPI_IOC_WR_BITS_PER_WORD, &spi_bits_per_word) < 0) {r
219 perror(
"SPI1: can't set bits per word");
224 if (ioctl(
fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi_speed) < 0) {
225 perror(
"SPI1: can't set max speed hz");
uint16_t output_length
number of data words to write
SPI transaction structure.
@ SPISelectUnselect
slave is selected before transaction and unselected after
#define SPI0_MAX_SPEED_HZ
#define SPI1_BITS_PER_WORD
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
SPI peripheral structure.
enum SPISlaveSelect select
slave selection behavior
@ SPIUnselect
slave is not selected but unselected after 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
if(GpsFixValid() &&e_identification_started)
#define SPI1_MAX_SPEED_HZ
bool spi_lock(struct spi_periph *p, uint8_t slave)
spi_lock() function
uint16_t input_length
number of data words to read
enum SPIDataSizeSelect dss
data transfer word size
volatile uint8_t * input_buf
pointer to receive buffer for DMA
#define SPI0_BITS_PER_WORD
void spi0_arch_init(void)
Architecture dependent SPI0 initialization.
process_rx_dma_interrupt & spi1
receive transferred over DMA
void spi1_arch_init(void)
Architecture dependent SPI1 initialization.
void spi_init_slaves(void)
spi_init_slaves() function
enum SPITransactionStatus status