Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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 
159 #ifndef SPI_TRANSACTION_QUEUE_LEN
160 #define SPI_TRANSACTION_QUEUE_LEN 8
161 #endif
162 
163 struct spi_periph {
169  volatile enum SPIStatus status;
170  volatile uint8_t tx_idx_buf;
171  volatile uint8_t rx_idx_buf;
172  void *reg_addr;
173  void *init_struct;
174  enum SPIMode mode;
176  volatile uint8_t suspend;
177 };
178 
179 #if SPI_MASTER
180 
181 #define SPI_SLAVE0 0
182 #define SPI_SLAVE1 1
183 #define SPI_SLAVE2 2
184 #define SPI_SLAVE3 3
185 #define SPI_SLAVE4 4
186 #define SPI_SLAVE5 5
187 
189 //extern uint8_t spi_nb_ovrn;
190 
191 #if USE_SPI0
192 
193 extern struct spi_periph spi0;
194 extern void spi0_init(void);
195 
199 extern void spi0_arch_init(void);
200 
201 #endif // USE_SPI0
202 
203 #if USE_SPI1
204 
205 extern struct spi_periph spi1;
206 extern void spi1_init(void);
207 
211 extern void spi1_arch_init(void);
212 
213 #endif // USE_SPI1
214 
215 #if USE_SPI2
216 
217 extern struct spi_periph spi2;
218 extern void spi2_init(void);
219 
223 extern void spi2_arch_init(void);
224 
225 #endif // USE_SPI2
226 
227 #if USE_SPI3
228 
229 extern struct spi_periph spi3;
230 extern void spi3_init(void);
231 
235 extern void spi3_arch_init(void);
236 
237 #endif // USE_SPI3
238 
242 extern void spi_init(struct spi_periph* p);
243 
246 extern void spi_init_slaves(void);
247 
254 extern bool_t spi_submit(struct spi_periph* p, struct spi_transaction* t);
255 
259 extern void spi_slave_select(uint8_t slave);
260 
264 extern void spi_slave_unselect(uint8_t slave);
265 
274 extern bool_t spi_lock(struct spi_periph* p, uint8_t slave);
275 
282 extern bool_t spi_resume(struct spi_periph* p, uint8_t slave);
283 
284 #endif /* SPI_MASTER */
285 
286 #if SPI_SLAVE
287 
288 #if USE_SPI0_SLAVE
289 
290 extern struct spi_periph spi0;
291 extern void spi0_slave_init(void);
292 
296 extern void spi0_slave_arch_init(void);
297 
298 #endif
299 
300 #if USE_SPI1_SLAVE
301 
302 extern struct spi_periph spi1;
303 extern void spi1_slave_init(void);
304 
308 extern void spi1_slave_arch_init(void);
309 
310 #endif
311 
312 #if USE_SPI2_SLAVE
313 
314 extern struct spi_periph spi2;
315 extern void spi2_slave_init(void);
316 
320 extern void spi2_slave_arch_init(void);
321 
322 #endif
323 
324 #if USE_SPI3_SLAVE
325 
326 extern struct spi_periph spi3;
327 extern void spi3_slave_init(void);
328 
332 extern void spi3_slave_arch_init(void);
333 
334 #endif
335 
339 extern void spi_slave_init(struct spi_periph* p);
340 
347 extern bool_t spi_slave_register(struct spi_periph* p, struct spi_transaction* t);
348 
355 extern bool_t spi_slave_wait(struct spi_periph* p);
356 
357 #endif /* SPI_SLAVE */
358 
362 #if SPI_SLAVE_HS
363 extern void spi_slave_hs_init(void);
364 #endif
365 
366 #endif /* SPI_H */
SPIClockPolarity
SPI CPOL (clock polarity) options.
Definition: spi.h:76
enum SPIBitOrder bitorder
MSB/LSB order.
Definition: spi.h:152
enum SPIClockPolarity cpol
clock polarity control
Definition: spi.h:149
Definition: spi.h:118
bool_t spi_lock(struct spi_periph *p, uint8_t slave)
Lock the SPI fifo.
Definition: spi_arch.c:535
uint8_t input_length
number of data words to read
Definition: spi.h:145
SPIMode
Definition: spi.h:46
SPIDataSizeSelect
SPI data word size of transfer.
Definition: spi.h:83
struct spi_periph spi2
Definition: spi.c:55
slave is selected before transaction but not unselected
Definition: spi.h:58
void spi1_arch_init(void)
Architecture dependant SPI1 initialization.
Definition: spi_arch.c:444
bool_t spi_slave_wait(struct spi_periph *p)
Initialized and wait for the next transaction.
Definition: spi_arch.c:670
slave is not selected but unselected after transaction
Definition: spi.h:59
enum SPIClockPhase cpha
clock phase control
Definition: spi.h:150
SPITransactionStatus
SPI transaction status.
Definition: spi.h:90
CPHA = 1.
Definition: spi.h:69
Definition: spi.h:115
slave is not selected nor unselected
Definition: spi.h:60
void * reg_addr
Definition: spi.h:172
void(* SPICallback)(struct spi_transaction *trans)
SPI Callback function.
Definition: spi.h:130
void spi_slave_hs_init(void)
volatile uint8_t * input_buf
pointer to receive buffer for DMA
Definition: spi.h:143
CPOL = 1.
Definition: spi.h:78
void * init_struct
Definition: spi.h:173
SPIClockPhase
SPI CPHA (clock phase) options.
Definition: spi.h:67
enum SPISlaveSelect select
slave selection behavior
Definition: spi.h:148
void spi_init(struct spi_periph *p)
Initialize a spi peripheral.
Definition: spi.c:74
SPIStatus
SPI peripheral status.
Definition: spi.h:100
enum SPITransactionStatus status
Definition: spi.h:156
volatile uint8_t rx_idx_buf
Definition: spi.h:171
Definition: spi.h:114
enum SPIStatus status
internal state of the peripheral
Definition: spi.h:169
Definition: spi.h:84
void spi_slave_init(struct spi_periph *p)
Initialize a spi peripheral in slave mode.
Definition: spi.c:127
void spi_slave_unselect(uint8_t slave)
Unselect a slave.
Definition: spi_arch.c:531
enum SPIClockDiv cdiv
prescaler of main clock to use as SPI clock
Definition: spi.h:153
bool_t spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit a spi transaction.
Definition: spi_arch.c:469
struct spi_periph spi0
Definition: spi.c:35
enum SPIDataSizeSelect dss
data transfer word size
Definition: spi.h:151
void spi2_arch_init(void)
Architecture dependant SPI2 initialization.
Definition: spi_arch.c:690
uint8_t output_length
number of data words to write
Definition: spi.h:146
struct spi_transaction * trans[SPI_TRANSACTION_QUEUE_LEN]
circular buffer holding transactions
Definition: spi.h:165
CPOL = 0.
Definition: spi.h:77
enum SPIMode mode
Definition: spi.h:174
void spi1_init(void)
Definition: spi.c:47
volatile uint8_t suspend
control for stop/resume of the fifo
Definition: spi.h:176
SPIBitOrder
Definition: spi.h:105
bool_t 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:647
unsigned char uint8_t
Definition: types.h:14
Definition: spi.h:101
void spi2_init(void)
Definition: spi.c:57
Definition: spi.h:48
SPIClockDiv
Peripheral clock divider.
Definition: spi.h:113
CPHA = 0.
Definition: spi.h:68
Definition: spi.h:117
Definition: spi.h:121
slave is selected before transaction and unselected after
Definition: spi.h:57
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
Definition: spi.h:147
Definition: spi.h:119
static float p[2][2]
bool_t spi_resume(struct spi_periph *p, uint8_t slave)
Resume the SPI fifo.
Definition: spi_arch.c:547
uint8_t trans_extract_idx
Definition: spi.h:167
Definition: spi.h:116
SPI transaction structure.
Definition: spi.h:142
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
Definition: spi.h:144
#define SPI_TRANSACTION_QUEUE_LEN
Definition: spi.h:160
SPICallback before_cb
NULL or function called before the transaction.
Definition: spi.h:154
Definition: spi.h:47
void spi_init_slaves(void)
Initialize all used slaves and uselect them.
Definition: spi_arch.c:503
void spi_slave_select(uint8_t slave)
Select a slave.
Definition: spi_arch.c:527
uint8_t trans_insert_idx
Definition: spi.h:166
void spi0_arch_init(void)
Architecture dependant SPI0 initialization.
Definition: spi_arch.c:396
struct spi_periph spi1
Definition: spi.c:45
SPISlaveSelect
SPI slave selection behavior options.
Definition: spi.h:56
Definition: spi.h:120
void spi0_init(void)
Definition: spi.c:37
volatile uint8_t tx_idx_buf
Definition: spi.h:170
SPICallback after_cb
NULL or function called after the transaction.
Definition: spi.h:155