Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
spi.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2012 The Paparazzi Team
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
31 #ifndef SPI_H
32 #define SPI_H
33 
34 #include "std.h"
35 
36 #include "mcu_periph/spi_arch.h"
37 
45 // FIXME how to use this properly ?
46 enum SPIMode {
49 };
50 
61 };
62 
70 };
71 
79 };
80 
86 };
87 
96 };
97 
100 enum SPIStatus {
103 };
104 
108 };
109 
122 };
123 
124 struct spi_transaction;
125 
130 typedef void (*SPICallback)(struct spi_transaction *trans);
131 
143  volatile uint8_t *input_buf;
144  volatile uint8_t *output_buf;
157 };
158 
162 #ifndef SPI_TRANSACTION_QUEUE_LEN
163 #define SPI_TRANSACTION_QUEUE_LEN 8
164 #endif
165 
168 struct spi_periph {
174  volatile enum SPIStatus status;
175  volatile uint8_t tx_idx_buf;
176  volatile uint8_t rx_idx_buf;
177  void *reg_addr;
178  void *init_struct;
179  enum SPIMode mode;
181  volatile uint8_t suspend;
182 };
183 
184 #if SPI_MASTER
185 
186 #define SPI_SLAVE0 0
187 #define SPI_SLAVE1 1
188 #define SPI_SLAVE2 2
189 #define SPI_SLAVE3 3
190 #define SPI_SLAVE4 4
191 #define SPI_SLAVE5 5
192 
194 //extern uint8_t spi_nb_ovrn;
195 
196 #if USE_SPI0
197 
198 extern struct spi_periph spi0;
199 extern void spi0_init(void);
200 
204 extern void spi0_arch_init(void);
205 
206 #endif // USE_SPI0
207 
208 #if USE_SPI1
209 
210 extern struct spi_periph spi1;
211 extern void spi1_init(void);
212 
216 extern void spi1_arch_init(void);
217 
218 #endif // USE_SPI1
219 
220 #if USE_SPI2
221 
222 extern struct spi_periph spi2;
223 extern void spi2_init(void);
224 
228 extern void spi2_arch_init(void);
229 
230 #endif // USE_SPI2
231 
232 #if USE_SPI3
233 
234 extern struct spi_periph spi3;
235 extern void spi3_init(void);
236 
240 extern void spi3_arch_init(void);
241 
242 #endif // USE_SPI3
243 
247 extern void spi_init(struct spi_periph *p);
248 
251 extern void spi_init_slaves(void);
252 
259 extern bool spi_submit(struct spi_periph *p, struct spi_transaction *t);
260 
264 extern void spi_slave_select(uint8_t slave);
265 
269 extern void spi_slave_unselect(uint8_t slave);
270 
279 extern bool spi_lock(struct spi_periph *p, uint8_t slave);
280 
287 extern bool spi_resume(struct spi_periph *p, uint8_t slave);
288 
289 #endif /* SPI_MASTER */
290 
291 #if SPI_SLAVE
292 
293 #if USE_SPI0_SLAVE
294 
295 extern struct spi_periph spi0;
296 extern void spi0_slave_init(void);
297 
301 extern void spi0_slave_arch_init(void);
302 
303 #endif
304 
305 #if USE_SPI1_SLAVE
306 
307 extern struct spi_periph spi1;
308 extern void spi1_slave_init(void);
309 
313 extern void spi1_slave_arch_init(void);
314 
315 #endif
316 
317 #if USE_SPI2_SLAVE
318 
319 extern struct spi_periph spi2;
320 extern void spi2_slave_init(void);
321 
325 extern void spi2_slave_arch_init(void);
326 
327 #endif
328 
329 #if USE_SPI3_SLAVE
330 
331 extern struct spi_periph spi3;
332 extern void spi3_slave_init(void);
333 
337 extern void spi3_slave_arch_init(void);
338 
339 #endif
340 
344 extern void spi_slave_init(struct spi_periph *p);
345 
352 extern bool spi_slave_register(struct spi_periph *p, struct spi_transaction *t);
353 
360 extern bool spi_slave_wait(struct spi_periph *p);
361 
362 #endif /* SPI_SLAVE */
363 
367 #if SPI_SLAVE_HS
369 extern void spi_slave_hs_init(void);
370 #endif
371 
372 #endif /* SPI_H */
SPIClockPolarity
SPI CPOL (clock polarity) options.
Definition: spi.h:76
unsigned short uint16_t
Definition: types.h:16
enum SPIClockPolarity cpol
clock polarity control
Definition: spi.h:149
bool spi_slave_register(struct spi_periph *p, struct spi_transaction *t)
Register a spi transaction in slave mode (only one transaction can be registered).
Definition: spi_arch.c:679
Definition: spi.h:118
enum SPIClockDiv cdiv
prescaler of main clock to use as SPI clock
Definition: spi.h:153
uint16_t output_length
number of data words to write
Definition: spi.h:146
SPIMode
Definition: spi.h:46
SPIDataSizeSelect
SPI data word size of transfer.
Definition: spi.h:83
struct spi_periph spi2
receive transferred over DMA
Definition: spi_arch.c:1004
slave is selected before transaction but not unselected
Definition: spi.h:58
void * reg_addr
Definition: spi.h:177
void spi1_arch_init(void)
Architecture dependent SPI1 initialization.
Definition: spi_arch.c:352
slave is not selected but unselected after transaction
Definition: spi.h:59
SPITransactionStatus
SPI transaction status.
Definition: spi.h:90
CPHA = 1.
Definition: spi.h:69
Definition: spi.h:115
SPI transaction structure.
Definition: spi.h:142
slave is not selected nor unselected
Definition: spi.h:60
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit a spi transaction.
Definition: spi_arch.c:458
void(* SPICallback)(struct spi_transaction *trans)
SPI Callback function.
Definition: spi.h:130
void spi_slave_hs_init(void)
CPOL = 1.
Definition: spi.h:78
enum SPIBitOrder bitorder
MSB/LSB order.
Definition: spi.h:152
SPIClockPhase
SPI CPHA (clock phase) options.
Definition: spi.h:67
void * init_struct
Definition: spi.h:178
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
Definition: spi.h:144
volatile uint8_t suspend
control for stop/resume of the fifo
Definition: spi.h:181
enum SPISlaveSelect select
slave selection behavior
Definition: spi.h:148
void spi_init(struct spi_periph *p)
Initialize a spi peripheral.
Definition: spi.c:78
SPIStatus
SPI peripheral status.
Definition: spi.h:100
Definition: spi.h:114
enum SPIClockPhase cpha
clock phase control
Definition: spi.h:150
bool spi_lock(struct spi_periph *p, uint8_t slave)
Lock the SPI fifo.
Definition: spi_arch.c:576
SPI peripheral structure.
Definition: spi.h:168
Definition: spi.h:84
void spi_slave_init(struct spi_periph *p)
Initialize a spi peripheral in slave mode.
Definition: spi.c:136
void spi_slave_unselect(uint8_t slave)
Unselect a slave.
Definition: spi_arch.c:533
struct spi_periph spi0
Definition: spi.c:35
SPICallback after_cb
NULL or function called after the transaction.
Definition: spi.h:155
void spi2_arch_init(void)
Architecture dependent SPI2 initialization.
Definition: spi_arch.c:391
volatile uint8_t tx_idx_buf
Definition: spi.h:175
bool spi_slave_wait(struct spi_periph *p)
Initialized and wait for the next transaction.
Definition: spi_arch.c:703
CPOL = 0.
Definition: spi.h:77
uint16_t input_length
number of data words to read
Definition: spi.h:145
enum SPIStatus status
internal state of the peripheral
Definition: spi.h:174
void spi1_init(void)
Definition: spi.c:48
SPIBitOrder
Definition: spi.h:105
unsigned char uint8_t
Definition: types.h:14
Definition: spi.h:101
void spi2_init(void)
Definition: spi.c:59
Definition: spi.h:48
SPIClockDiv
Peripheral clock divider.
Definition: spi.h:113
CPHA = 0.
Definition: spi.h:68
bool spi_resume(struct spi_periph *p, uint8_t slave)
Resume the SPI fifo.
Definition: spi_arch.c:590
Definition: spi.h:117
Definition: spi.h:121
slave is selected before transaction and unselected after
Definition: spi.h:57
enum SPIMode mode
Definition: spi.h:179
uint8_t trans_extract_idx
Definition: spi.h:172
enum SPIDataSizeSelect dss
data transfer word size
Definition: spi.h:151
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
Definition: spi.h:147
Definition: spi.h:119
volatile uint8_t * input_buf
pointer to receive buffer for DMA
Definition: spi.h:143
static float p[2][2]
Definition: spi.h:116
Highspeed SPI Slave Interface.
SPICallback before_cb
NULL or function called before the transaction.
Definition: spi.h:154
volatile uint8_t rx_idx_buf
Definition: spi.h:176
#define SPI_TRANSACTION_QUEUE_LEN
SPI transaction queue length.
Definition: spi.h:163
Definition: spi.h:47
void spi_init_slaves(void)
Initialize all used slaves and unselect them.
Definition: spi_arch.c:604
void spi_slave_select(uint8_t slave)
Select a slave.
Definition: spi_arch.c:491
void spi0_arch_init(void)
Architecture dependent SPI0 initialization.
Definition: spi_arch.c:136
struct spi_transaction * trans[SPI_TRANSACTION_QUEUE_LEN]
circular buffer holding transactions
Definition: spi.h:170
struct spi_periph spi1
receive transferred over DMA
Definition: spi_arch.c:967
SPISlaveSelect
SPI slave selection behavior options.
Definition: spi.h:56
Definition: spi.h:120
void spi0_init(void)
Definition: spi.c:37
enum SPITransactionStatus status
Definition: spi.h:156
uint8_t trans_insert_idx
Definition: spi.h:171