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
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/sys_time.h"
33 #ifdef USE_LED
34 #include "led.h"
35 #endif
36 #if defined RADIO_CONTROL
37 #if defined RADIO_CONTROL_BIND_IMPL_FUNC & defined SPEKTRUM_BIND_PIN_PORT
39 #endif
40 #endif
41 #if USE_UART0 || USE_UART1 || USE_UART2 || USE_UART3 || USE_UART4 || USE_UART5 || USE_UART6 || USE_UART7 || USE_UART8
42 #define USING_UART 1
43 #include "mcu_periph/uart.h"
44 #endif
45 #if USE_I2C0 || USE_I2C1 || USE_I2C2 || USE_I2C3
46 #define USING_I2C 1
47 #include "mcu_periph/i2c.h"
48 #endif
49 #if USE_ADC
50 #include "mcu_periph/adc.h"
51 #endif
52 #if USE_USB_SERIAL
53 #include "mcu_periph/usb_serial.h"
54 #endif
55 #ifdef USE_UDP
56 #include "mcu_periph/udp.h"
57 #endif
58 #if USE_SPI
59 #include "mcu_periph/spi.h"
60 #endif
61 #ifdef USE_DAC
62 #include "mcu_periph/dac.h"
63 #endif
64 #ifdef USE_RNG
65 #include "mcu_periph/rng.h"
66 #endif
67 #ifdef USE_PIPE
68 #include "mcu_periph/pipe.h"
69 #endif
70 #endif /* PERIPHERALS_AUTO_INIT */
71 
72 void WEAK board_init(void)
73 {
74  /* default board init function does nothing... */
75 }
76 
77 void WEAK board_init2(void)
78 {
79  /* default board init function does nothing... */
80 }
81 
82 void mcu_init(void)
83 {
84  /* If we have a board specific init function, call it.
85  * Otherwise it will simply call the empty weak function.
86  *
87  * For example the ARDrone2 has this implemented to prevent stray data of IMU
88  * from OEM program still running and also accessing AC sensors
89  */
90  board_init();
91 
92  mcu_arch_init();
93 
94  /* First enable the power of the MCU if needed */
95 #if defined MCU_PWR
98 
99 #if defined BTN_ON
102  {
104  }
105  else {
106  // Turn off and stop: wait until all power is off
107  while(true) {
109  }
110  }
111 #endif //BTN_ON
112 
113 #endif //MCU_PWR
114 
115 #ifdef PERIPHERALS_AUTO_INIT
116  sys_time_init();
117 #ifdef USE_LED
118  led_init();
119 #endif
120  /* First enable power of RC */
121 #if defined RADIO_CONTROL_POWER_PORT
124 #endif
125 #ifdef PERIPHERAL3V3_ENABLE_PORT
128 #endif
129  /* for now this means using spektrum */
130 #if defined RADIO_CONTROL & defined RADIO_CONTROL_BIND_IMPL_FUNC & defined SPEKTRUM_BIND_PIN_PORT
131  RADIO_CONTROL_BIND_IMPL_FUNC();
132 #endif
133 #if USE_UART0
134  uart0_init();
135 #endif
136 #if USE_UART1
137  uart1_init();
138 #endif
139 #if USE_UART2
140  uart2_init();
141 #endif
142 #if USE_UART3
143  uart3_init();
144 #endif
145 #if USE_UART4
146  uart4_init();
147 #endif
148 #if USE_UART5
149  uart5_init();
150 #endif
151 #if USE_UART6
152  uart6_init();
153 #endif
154 #if USE_UART7
155  uart7_init();
156 #endif
157 #if USE_UART8
158  uart8_init();
159 #endif
160 #if USING_UART
161  uart_arch_init();
162 #endif
163 #ifdef USE_I2C0
164  i2c0_init();
165 #endif
166 #ifdef USE_I2C1
167  i2c1_init();
168 #endif
169 #ifdef USE_I2C2
170  i2c2_init();
171 #endif
172 #ifdef USE_I2C3
173  i2c3_init();
174 #endif
175 #if USE_ADC
176  adc_init();
177 #endif
178 #if USE_USB_SERIAL
179  VCOM_init();
180 #endif
181 
182 #if USE_SPI
183 #if SPI_MASTER
184 
185 #if USE_SPI0
186  spi0_init();
187 #endif
188 #if USE_SPI1
189  spi1_init();
190 #endif
191 #if USE_SPI2
192  spi2_init();
193 #endif
194 #if USE_SPI3
195  spi3_init();
196 #endif
197  spi_init_slaves();
198 #endif // SPI_MASTER
199 
200 #if SPI_SLAVE
201 #if USE_SPI0_SLAVE
202  spi0_slave_init();
203 #endif
204 #if USE_SPI1_SLAVE
205  spi1_slave_init();
206 #endif
207 #if USE_SPI2_SLAVE
208  spi2_slave_init();
209 #endif
210 #if USE_SPI3_SLAVE
211  spi3_slave_init();
212 #endif
213 #endif // SPI_SLAVE
214 
215 #if SPI_SLAVE_HS
217 #endif
218 #endif // USE_SPI
219 
220 #ifdef USE_DAC
221  dac_init();
222 #endif
223 
224 #if USE_UDP0 || USE_UDP1 || USE_UDP2
225  udp_arch_init();
226 #endif
227 
228 #ifdef USE_RNG
229  rng_init();
230 #endif
231 
232 #else
233  INFO("PERIPHERALS_AUTO_INIT not enabled! Peripherals (including sys_time) need explicit initialization.")
234 #endif /* PERIPHERALS_AUTO_INIT */
235 
236  board_init2();
237 }
238 
239 
240 
241 void mcu_event(void)
242 {
243 #if USING_I2C
244  i2c_event();
245 #endif
246 
247 #if USE_USB_SERIAL
248  VCOM_event();
249 #endif
250 }
#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:82
#define MCU_PWR
Definition: opa_ftd_1.0.h:37
#define PERIPHERAL3V3_ENABLE_ON
Definition: px4fmu_4.0.h:119
void VCOM_event(void)
Definition: usb_ser_hw.c:571
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:77
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:72
#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
void spi1_init(void)
Definition: spi.c:48
#define PERIPHERAL3V3_ENABLE_PORT
Definition: px4fmu_4.0.h:117
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
#define PERIPHERAL3V3_ENABLE_PIN
Definition: px4fmu_4.0.h:118
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:241
void adc_init(void)
Adc init.
Definition: adc_arch.c:304
void i2c_event(void)
i2c_event() function
Definition: i2c_arch.c:347
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:604
#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.