Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
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
27
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_CAN1 || USE_CAN2
55#include "mcu_periph/can.h"
56#endif
57#if USE_ADC
58#include "mcu_periph/adc.h"
59#endif
60#if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
61#define USING_USB_SERIAL 1
63#endif
64#ifdef USE_UDP
65#include "mcu_periph/udp.h"
66#endif
67#if USE_SPI
68#include "mcu_periph/spi.h"
69#endif
70#ifdef USE_RNG
71#include "mcu_periph/rng.h"
72#endif
73#ifdef USE_PIPE
74#include "mcu_periph/pipe.h"
75#endif
76#endif /* PERIPHERALS_AUTO_INIT */
77
78void WEAK board_init(void)
79{
80 /* default board init function does nothing... */
81}
82
83void WEAK board_init2(void)
84{
85 /* default board init function does nothing... */
86}
87
88void WEAK mcu_reboot(enum reboot_state_t reboot_state __attribute__((unused)))
89{
90 /* default reboot function does nothing... */
91}
92
93void WEAK mcu_energy_save(void)
94{
95 /* default power saving function does nothing... */
96}
97
98uint8_t WEAK mcu_get_uid(uint8_t *uid __attribute__((unused)), uint8_t max_len __attribute__((unused)))
99{
100 /* default has no unique ID */
101 return 0;
102}
103
104void mcu_init(void)
105{
106 /* If we have a board specific init function, call it.
107 * Otherwise it will simply call the empty weak function.
108 *
109 * For example a board can use it to stop the OEM program that is still
110 * running and accessing the sensors
111 */
112 board_init();
113
115
116 /* First enable the power of the MCU if needed */
117#if defined MCU_PWR
118 gpio_setup_output(MCU_PWR, MCU_PWR_PIN);
119 MCU_PWR_ON(MCU_PWR, MCU_PWR_PIN);
120
121#if defined BTN_ON
122 gpio_setup_input(BTN_ON, BTN_ON_PIN);
123 if (gpio_get(BTN_ON, BTN_ON_PIN)) {
124 MCU_PWR_ON(MCU_PWR, MCU_PWR_PIN);
125 } else {
126 // Turn off and stop: wait until all power is off
127 while (true) {
128 MCU_PWR_OFF(MCU_PWR, MCU_PWR_PIN);
129 }
130 }
131#endif //BTN_ON
132
133#endif //MCU_PWR
134
135#ifdef PERIPHERALS_AUTO_INIT
137#ifdef USE_LED
138 led_init();
139#endif
140 /* First enable power of RC */
141#if defined RADIO_CONTROL_POWER_PORT
144#endif
145#ifdef PERIPHERAL3V3_ENABLE_PORT
148#endif
149 /* for now this means using spektrum */
150#if defined RADIO_CONTROL && defined RADIO_CONTROL_BIND_IMPL_FUNC && defined SPEKTRUM_BIND_PIN_PORT
151 RADIO_CONTROL_BIND_IMPL_FUNC();
152#endif
153#if USE_UART0
154 uart0_init();
155#endif
156#if USE_UART1
157 uart1_init();
158#endif
159#if USE_UART2
160 uart2_init();
161#endif
162#if USE_UART3
163 uart3_init();
164#endif
165#if USE_UART4
166 uart4_init();
167#endif
168#if USE_UART5
169 uart5_init();
170#endif
171#if USE_UART6
172 uart6_init();
173#endif
174#if USE_UART7
175 uart7_init();
176#endif
177#if USE_UART8
178 uart8_init();
179#endif
180#if USING_UART
182#endif
183#ifdef USE_I2C0
184 i2c0_init();
185#endif
186#ifdef USE_I2C1
187 i2c1_init();
188#endif
189#ifdef USE_I2C2
190 i2c2_init();
191#endif
192#ifdef USE_I2C3
193 i2c3_init();
194#endif
195#ifdef USE_I2C4
196 i2c4_init();
197#endif
198#ifdef USE_SOFTI2C0
199 softi2c0_init();
200#endif
201#ifdef USE_SOFTI2C1
202 softi2c1_init();
203#endif
204#if USE_CAN1 || USE_CAN2
205 can_init();
206#endif
207#if USE_ADC
208 adc_init();
209#endif
210#if USING_USB_SERIAL
211 VCOM_init();
212#endif
213
214#if USE_SPI
215#if SPI_MASTER
216
217#if USE_SPI0
218 spi0_init();
219#endif
220#if USE_SPI1
221 spi1_init();
222#endif
223#if USE_SPI2
224 spi2_init();
225#endif
226#if USE_SPI3
227 spi3_init();
228#endif
229#if USE_SPI4
230 spi4_init();
231#endif
232#if USE_SPI6
233 spi6_init();
234#endif
236#endif // SPI_MASTER
237
238#if SPI_SLAVE
239#if USE_SPI0_SLAVE
240 spi0_slave_init();
241#endif
242#if USE_SPI1_SLAVE
243 spi1_slave_init();
244#endif
245#if USE_SPI2_SLAVE
246 spi2_slave_init();
247#endif
248#if USE_SPI3_SLAVE
249 spi3_slave_init();
250#endif
251#endif // SPI_SLAVE
252
253#if SPI_SLAVE_HS
254 spi_slave_hs_init();
255#endif
256#endif // USE_SPI
257
258#if USE_UDP0 || USE_UDP1 || USE_UDP2
260#endif
261
262#ifdef USE_RNG
263 rng_init();
264#endif
265
266#else
267 INFO("PERIPHERALS_AUTO_INIT not enabled! Peripherals (including sys_time) need explicit initialization.")
268#endif /* PERIPHERALS_AUTO_INIT */
269
270 board_init2();
271}
272
273
274
275void mcu_event(void)
276{
277#if USING_I2C
278 i2c_event();
279#endif
280#if USING_SOFTI2C
282#endif
283
284#if USING_USB_SERIAL
285 VCOM_event();
286#endif
287}
arch independent ADC (Analog to Digital Converter) API
void can_init()
Definition can.c:69
void mcu_arch_init(void)
Initialize the specific archittecture functions.
Definition mcu_arch.c:157
void adc_init(void)
Adc init.
Definition adc_arch.c:332
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
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
static uint8_t gpio_get(ioportid_t port, uint16_t pin)
Get level of a gpio.
Definition gpio_arch.h:94
void rng_init(void)
Definition rng_arch.c:77
Some architecture independent helper functions for GPIOs.
void i2c_event(void)
i2c_event() function
Definition i2c_arch.c:394
void WEAK mcu_reboot(enum reboot_state_t reboot_state)
Reboot the MCU Should not be called during flight or ciritcal operations.
Definition mcu.c:88
reboot_state_t
The requested reboot states.
Definition mcu.h:43
void WEAK board_init(void)
Optional board init function called at the start of mcu_init().
Definition mcu.c:78
void mcu_init(void)
Microcontroller peripherals initialization.
Definition mcu.c:104
void WEAK mcu_energy_save(void)
Puts the MCU in energy save mode This disables features of the MCU to save energy.
Definition mcu.c:93
uint8_t WEAK mcu_get_uid(uint8_t *uid, uint8_t max_len)
Get the unique hardware ID of the MCU.
Definition mcu.c:98
void mcu_event(void)
MCU event functions.
Definition mcu.c:275
void WEAK board_init2(void)
Optional board init function called at the end of mcu_init().
Definition mcu.c:83
void spi2_init(void)
Definition spi.c:59
void spi0_init(void)
Definition spi.c:37
void spi1_init(void)
Definition spi.c:48
void spi_init_slaves(void)
spi_init_slaves() function
Definition spi_arch.c:735
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
arch independent LED (Light Emitting Diodes) API
static void led_init(void)
Automatic initialization of actived LED Set to OFF at startup.
Definition led.h:39
void uart_arch_init(void)
Definition uart_arch.c:54
void udp_arch_init(void)
Definition udp_arch.c:213
Arch independent mcu ( Micro Controller Unit ) utilities.
arch independent PIPE API
#define PERIPHERAL3V3_ENABLE_ON
Definition px4fmu.h:324
#define RADIO_CONTROL_POWER_ON
Definition px4fmu.h:318
#define RADIO_CONTROL_POWER_PIN
Definition px4fmu.h:317
#define PERIPHERAL3V3_ENABLE_PORT
Definition px4fmu.h:322
#define RADIO_CONTROL_POWER_PORT
Definition px4fmu.h:316
#define PERIPHERAL3V3_ENABLE_PIN
Definition px4fmu.h:323
arch independent Random Number Generator API
void softi2c_event(void)
Definition softi2c.c:620
Platform-independent software I2C implementation.
Radio control spektrum interface.
Architecture independent SPI (Serial Peripheral Interface) API.
void sys_time_init(void)
Definition sys_time.c:263
Architecture independent timing functions.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
arch independent UDP API
arch independent USB API
void VCOM_event(void)
void VCOM_init(void)
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.