Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
spi.c
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 
29 #include "std.h"
30 #include "mcu_periph/spi.h"
31 
32 #if SPI_MASTER
33 
34 #if USE_SPI0
36 
37 void spi0_init(void) {
38  spi_init(&spi0);
40 }
41 #endif // USE_SPI0
42 
43 
44 #if USE_SPI1
46 
47 void spi1_init(void) {
48  spi_init(&spi1);
50 }
51 #endif // USE_SPI1
52 
53 
54 #if USE_SPI2
56 
57 void spi2_init(void) {
58  spi_init(&spi2);
60 }
61 #endif // USE_SPI2
62 
63 
64 #if USE_SPI3
65 struct spi_periph spi3;
66 
67 void spi3_init(void) {
68  spi_init(&spi3);
69  spi3_arch_init();
70 }
71 #endif // USE_SPI3
72 
73 
74 void spi_init(struct spi_periph* p) {
75  p->trans_insert_idx = 0;
76  p->trans_extract_idx = 0;
77  p->status = SPIIdle;
78  p->mode = SPIMaster;
79  p->suspend = FALSE;
80 }
81 
82 #endif /* SPI_MASTER */
83 
84 
85 #if SPI_SLAVE
86 
87 #if USE_SPI0_SLAVE
88 struct spi_periph spi0;
89 
90 void spi0_slave_init(void) {
92  spi0_slave_arch_init();
93 }
94 #endif // USE_SPI0_SLAVE
95 
96 
97 #if USE_SPI1_SLAVE
98 struct spi_periph spi1;
99 
100 void spi1_slave_init(void) {
102  spi1_slave_arch_init();
103 }
104 #endif // USE_SPI1_SLAVE
105 
106 
107 #if USE_SPI2_SLAVE
108 struct spi_periph spi2;
109 
110 void spi2_slave_init(void) {
112  spi2_slave_arch_init();
113 }
114 #endif // USE_SPI2_SLAVE
115 
116 
117 #if USE_SPI3_SLAVE
118 struct spi_periph spi3;
119 
120 void spi3_slave_init(void) {
121  spi_slave_init(&spi3);
122  spi3_slave_arch_init();
123 }
124 #endif // USE_SPI3_SLAVE
125 
126 
127 extern void spi_slave_init(struct spi_periph* p) {
128  p->trans_insert_idx = 0;
129  p->trans_extract_idx = 0;
130  p->status = SPIIdle;
131  p->mode = SPISlave;
132  p->suspend = FALSE;
133 }
134 
135 #endif /* SPI_SLAVE */
136 
struct spi_periph spi2
receive transferred over DMA
Definition: spi.c:55
void spi1_arch_init(void)
Architecture dependant SPI1 initialization.
Definition: spi_arch.c:445
void spi_init(struct spi_periph *p)
Initialize a spi peripheral.
Definition: spi.c:74
#define FALSE
Definition: imu_chimu.h:141
Architecture independent SPI (Serial Peripheral Interface) API.
enum SPIStatus status
internal state of the peripheral
Definition: spi.h:174
void spi_slave_init(struct spi_periph *p)
Initialize a spi peripheral in slave mode.
Definition: spi.c:127
struct spi_periph spi0
Definition: spi.c:35
void spi2_arch_init(void)
Architecture dependant SPI2 initialization.
Definition: spi_arch.c:752
enum SPIMode mode
Definition: spi.h:179
void spi1_init(void)
Definition: spi.c:47
SPI peripheral structure.
Definition: spi.h:168
volatile uint8_t suspend
control for stop/resume of the fifo
Definition: spi.h:181
Definition: spi.h:101
void spi2_init(void)
Definition: spi.c:57
Definition: spi.h:48
static float p[2][2]
uint8_t trans_extract_idx
Definition: spi.h:172
Definition: spi.h:47
uint8_t trans_insert_idx
Definition: spi.h:171
void spi0_arch_init(void)
Architecture dependant SPI0 initialization.
Definition: spi_arch.c:397
struct spi_periph spi1
receive transferred over DMA
Definition: spi.c:45
void spi0_init(void)
Definition: spi.c:37