Paparazzi UAS  v5.15_devel-229-g3fb4ee4
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
mcu.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010-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 
28 #include "mcu.h"
29 #include "std.h"
30 
31 #ifdef PERIPHERALS_AUTO_INIT
32 #include "mcu_periph/gpio.h"
33 #include "mcu_periph/sys_time.h"
34 #ifdef USE_LED
35 #include "led.h"
36 #endif
37 #if defined RADIO_CONTROL
38 #if defined RADIO_CONTROL_BIND_IMPL_FUNC & defined SPEKTRUM_BIND_PIN_PORT
40 #endif
41 #endif
42 #if USE_UART0 || USE_UART1 || USE_UART2 || USE_UART3 || USE_UART4 || USE_UART5 || USE_UART6 || USE_UART7 || USE_UART8
43 #define USING_UART 1
44 #include "mcu_periph/uart.h"
45 #endif
46 #if USE_I2C0 || USE_I2C1 || USE_I2C2 || USE_I2C3 || USE_I2C4 || USE_SOFTI2C0 || USE_SOFTI2C1
47 #define USING_I2C 1
48 #include "mcu_periph/i2c.h"
49 #endif
50 #if USE_SOFTI2C0 || USE_SOFTI2C1
51 #define USING_SOFTI2C 1
52 #include "mcu_periph/softi2c.h"
53 #endif
54 #if USE_ADC
55 #include "mcu_periph/adc.h"
56 #endif
57 #if USE_USB_SERIAL
58 #include "mcu_periph/usb_serial.h"
59 #endif
60 #ifdef USE_UDP
61 #include "mcu_periph/udp.h"
62 #endif
63 #if USE_SPI
64 #include "mcu_periph/spi.h"
65 #endif
66 #ifdef USE_DAC
67 #include "mcu_periph/dac.h"
68 #endif
69 #ifdef USE_RNG
70 #include "mcu_periph/rng.h"
71 #endif
72 #ifdef USE_PIPE
73 #include "mcu_periph/pipe.h"
74 #endif
75 #endif /* PERIPHERALS_AUTO_INIT */
76 
77 void WEAK board_init(void)
78 {
79  /* default board init function does nothing... */
80 }
81 
82 void WEAK board_init2(void)
83 {
84  /* default board init function does nothing... */
85 }
86 
87 void mcu_init(void)
88 {
89  /* If we have a board specific init function, call it.
90  * Otherwise it will simply call the empty weak function.
91  *
92  * For example the ARDrone2 has this implemented to prevent stray data of IMU
93  * from OEM program still running and also accessing AC sensors
94  */
95  board_init();
96 
97  mcu_arch_init();
98 
99  /* First enable the power of the MCU if needed */
100 #if defined MCU_PWR
103 
104 #if defined BTN_ON
107  {
109  }
110  else {
111  // Turn off and stop: wait until all power is off
112  while(true) {
114  }
115  }
116 #endif //BTN_ON
117 
118 #endif //MCU_PWR
119 
120 #ifdef PERIPHERALS_AUTO_INIT
121  sys_time_init();
122 #ifdef USE_LED
123  led_init();
124 #endif
125  /* First enable power of RC */
126 #if defined RADIO_CONTROL_POWER_PORT
129 #endif
130 #ifdef PERIPHERAL3V3_ENABLE_PORT
133 #endif
134  /* for now this means using spektrum */
135 #if defined RADIO_CONTROL & defined RADIO_CONTROL_BIND_IMPL_FUNC & defined SPEKTRUM_BIND_PIN_PORT
136  RADIO_CONTROL_BIND_IMPL_FUNC();
137 #endif
138 #if USE_UART0
139  uart0_init();
140 #endif
141 #if USE_UART1
142  uart1_init();
143 #endif
144 #if USE_UART2
145  uart2_init();
146 #endif
147 #if USE_UART3
148  uart3_init();
149 #endif
150 #if USE_UART4
151  uart4_init();
152 #endif
153 #if USE_UART5
154  uart5_init();
155 #endif
156 #if USE_UART6
157  uart6_init();
158 #endif
159 #if USE_UART7
160  uart7_init();
161 #endif
162 #if USE_UART8
163  uart8_init();
164 #endif
165 #if USING_UART
166  uart_arch_init();
167 #endif
168 #ifdef USE_I2C0
169  i2c0_init();
170 #endif
171 #ifdef USE_I2C1
172  i2c1_init();
173 #endif
174 #ifdef USE_I2C2
175  i2c2_init();
176 #endif
177 #ifdef USE_I2C3
178  i2c3_init();
179 #endif
180 #ifdef USE_I2C4
181  i2c4_init();
182 #endif
183 #ifdef USE_SOFTI2C0
184  softi2c0_init();
185 #endif
186 #ifdef USE_SOFTI2C1
187  softi2c1_init();
188 #endif
189 #if USE_ADC
190  adc_init();
191 #endif
192 #if USE_USB_SERIAL
193  VCOM_init();
194 #endif
195 
196 #if USE_SPI
197 #if SPI_MASTER
198 
199 #if USE_SPI0
200  spi0_init();
201 #endif
202 #if USE_SPI1
203  spi1_init();
204 #endif
205 #if USE_SPI2
206  spi2_init();
207 #endif
208 #if USE_SPI3
209  spi3_init();
210 #endif
211 #if USE_SPI4
212  spi4_init();
213 #endif
214  spi_init_slaves();
215 #endif // SPI_MASTER
216 
217 #if SPI_SLAVE
218 #if USE_SPI0_SLAVE
219  spi0_slave_init();
220 #endif
221 #if USE_SPI1_SLAVE
222  spi1_slave_init();
223 #endif
224 #if USE_SPI2_SLAVE
225  spi2_slave_init();
226 #endif
227 #if USE_SPI3_SLAVE
228  spi3_slave_init();
229 #endif
230 #endif // SPI_SLAVE
231 
232 #if SPI_SLAVE_HS
234 #endif
235 #endif // USE_SPI
236 
237 #ifdef USE_DAC
238  dac_init();
239 #endif
240 
241 #if USE_UDP0 || USE_UDP1 || USE_UDP2
242  udp_arch_init();
243 #endif
244 
245 #ifdef USE_RNG
246  rng_init();
247 #endif
248 
249 #else
250  INFO("PERIPHERALS_AUTO_INIT not enabled! Peripherals (including sys_time) need explicit initialization.")
251 #endif /* PERIPHERALS_AUTO_INIT */
252 
253  board_init2();
254 }
255 
256 
257 
258 void mcu_event(void)
259 {
260 #if USING_I2C
261  i2c_event();
262 #endif
263 #if USING_SOFTI2C
264  softi2c_event();
265 #endif
266 
267 #if USE_USB_SERIAL
268  VCOM_event();
269 #endif
270 }
#define PERIPHERAL3V3_ENABLE_PORT
Definition: px4fmu.h:282
#define MCU_PWR_OFF
Definition: opa_ftd_1.0.h:40
arch independent PIPE API
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void mcu_init(void)
Microcontroller peripherals initialization.
Definition: mcu.c:87
#define MCU_PWR
Definition: opa_ftd_1.0.h:37
Platform-independent software I2C implementation.
void VCOM_event(void)
Definition: usb_ser_hw.c:571
#define PERIPHERAL3V3_ENABLE_PIN
Definition: px4fmu.h:283
Some architecture independent helper functions for GPIOs.
void softi2c_event(void)
Definition: softi2c.c:624
void mcu_arch_init(void)
Definition: mcu_arch.c:109
void spi_slave_hs_init(void)
#define RADIO_CONTROL_POWER_PORT
Definition: opa_ftd_1.0.h:149
#define MCU_PWR_PIN
Definition: opa_ftd_1.0.h:38
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
Definition: gpio_arch.c:33
arch independent ADC (Analog to Digital Converter) API
Architecture independent SPI (Serial Peripheral Interface) API.
#define RADIO_CONTROL_POWER_PIN
Definition: opa_ftd_1.0.h:150
#define BTN_ON
Definition: opa_ftd_1.0.h:73
void uart_arch_init(void)
Definition: uart_arch.c:54
void WEAK board_init2(void)
Optional board init function called at the end of mcu_init().
Definition: mcu.c:82
Architecture independent timing functions.
void udp_arch_init(void)
Definition: udp_arch.c:43
static void led_init(void)
Automatic initialization of actived LED Set to OFF at startup.
Definition: led.h:39
void rng_init(void)
Definition: rng_arch.c:34
void WEAK board_init(void)
Optional board init function called at the start of mcu_init().
Definition: mcu.c:77
#define RADIO_CONTROL_POWER_ON
Definition: opa_ftd_1.0.h:151
arch independent Random Number Generator API
void sys_time_init(void)
Definition: sys_time.c:78
#define PERIPHERAL3V3_ENABLE_ON
Definition: px4fmu.h:284
void spi1_init(void)
Definition: spi.c:48
Arch independent mcu ( Micro Controller Unit ) utilities.
static uint8_t gpio_get(ioportid_t port, uint16_t pin)
Get level of a gpio.
Definition: gpio_arch.h:88
void spi2_init(void)
Definition: spi.c:59
#define MCU_PWR_ON
Definition: opa_ftd_1.0.h:39
arch independent LED (Light Emitting Diodes) API
void dac_init(void)
Definition: dac_arch.c:33
void mcu_event(void)
MCU event functions.
Definition: mcu.c:258
void adc_init(void)
Adc init.
Definition: adc_arch.c:304
void i2c_event(void)
i2c_event() function
Definition: i2c_arch.c:428
void gpio_setup_input(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs.
Definition: gpio_arch.c:40
void spi_init_slaves(void)
spi_init_slaves() function
Definition: spi_arch.c:657
#define BTN_ON_PIN
Definition: opa_ftd_1.0.h:74
arch independent UDP API
void VCOM_init(void)
Definition: usb_ser_hw.c:586
void spi0_init(void)
Definition: spi.c:37
arch independent USB API
Architecture independent I2C (Inter-Integrated Circuit Bus) API.