Paparazzi UAS  v5.8.2_stable-0-g6260b7c
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_LINK || defined RADIO_CONTROL_SPEKTRUM_PRIMARY_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 #endif /* PERIPHERALS_AUTO_INIT */
65 
66 void WEAK board_init(void)
67 {
68  // default board init function does nothing...
69 }
70 
71 void mcu_init(void)
72 {
73 
74  mcu_arch_init();
75  /* If we have a board specific init function, call it.
76  * Otherwise it will simply call the empty weak function.
77  */
78  board_init();
79 
80 #ifdef PERIPHERALS_AUTO_INIT
81  sys_time_init();
82 #ifdef USE_LED
83  led_init();
84 #endif
85  /* for now this means using spektrum */
86 #if defined RADIO_CONTROL & defined RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT & defined RADIO_CONTROL_BIND_IMPL_FUNC
87  RADIO_CONTROL_BIND_IMPL_FUNC();
88 #endif
89 #if USE_UART0
90  uart0_init();
91 #endif
92 #if USE_UART1
93  uart1_init();
94 #endif
95 #if USE_UART2
96  uart2_init();
97 #endif
98 #if USE_UART3
99  uart3_init();
100 #endif
101 #if USE_UART4
102  uart4_init();
103 #endif
104 #if USE_UART5
105  uart5_init();
106 #endif
107 #if USE_UART6
108  uart6_init();
109 #endif
110 #if USE_UART7
111  uart7_init();
112 #endif
113 #if USE_UART8
114  uart8_init();
115 #endif
116 #if USING_UART
117  uart_arch_init();
118 #endif
119 #ifdef USE_I2C0
120  i2c0_init();
121 #endif
122 #ifdef USE_I2C1
123  i2c1_init();
124 #endif
125 #ifdef USE_I2C2
126  i2c2_init();
127 #endif
128 #ifdef USE_I2C3
129  i2c3_init();
130 #endif
131 #if USE_ADC
132  adc_init();
133 #endif
134 #if USE_USB_SERIAL
135  VCOM_init();
136 #endif
137 
138 #if USE_SPI
139 #if SPI_MASTER
140 
141 #if USE_SPI0
142  spi0_init();
143 #endif
144 #if USE_SPI1
145  spi1_init();
146 #endif
147 #if USE_SPI2
148  spi2_init();
149 #endif
150 #if USE_SPI3
151  spi3_init();
152 #endif
153  spi_init_slaves();
154 #endif // SPI_MASTER
155 
156 #if SPI_SLAVE
157 #if USE_SPI0_SLAVE
158  spi0_slave_init();
159 #endif
160 #if USE_SPI1_SLAVE
161  spi1_slave_init();
162 #endif
163 #if USE_SPI2_SLAVE
164  spi2_slave_init();
165 #endif
166 #if USE_SPI3_SLAVE
167  spi3_slave_init();
168 #endif
169 #endif // SPI_SLAVE
170 
171 #if SPI_SLAVE_HS
173 #endif
174 #endif // USE_SPI
175 
176 #ifdef USE_DAC
177  dac_init();
178 #endif
179 
180 #if USE_UDP0 || USE_UDP1 || USE_UDP2
181  udp_arch_init();
182 #endif
183 
184 #else
185  INFO("PERIPHERALS_AUTO_INIT not enabled! Peripherals (including sys_time) need explicit initialization.")
186 #endif /* PERIPHERALS_AUTO_INIT */
187 
188 }
189 
190 
191 
192 void mcu_event(void)
193 {
194 #if USING_I2C
195  i2c_event();
196 #endif
197 
198 #if USE_USB_SERIAL
199  VCOM_event();
200 #endif
201 }
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void mcu_init(void)
Microcontroller peripherals initialization.
Definition: mcu.c:71
void VCOM_event(void)
Definition: usb_ser_hw.c:563
void spi_slave_hs_init(void)
void mcu_arch_init(void)
Definition: mcu_arch.c:77
arch independent ADC (Analog to Digital Converter) API
Architecture independent SPI (Serial Peripheral Interface) API.
void uart_arch_init(void)
Definition: uart_arch.c:54
Architecture independent timing functions.
void udp_arch_init(void)
Definition: udp_arch.c:44
static void led_init(void)
Definition: led.h:36
void WEAK board_init(void)
Optional board init function called at the end of mcu_init().
Definition: mcu.c:66
void sys_time_init(void)
Definition: sys_time.c:73
void adc_init(void)
Initialize the ADC.
Definition: adc_arch.c:78
void spi1_init(void)
Definition: spi.c:48
Arch independent mcu ( Micro Controller Unit ) utilities.
void spi2_init(void)
Definition: spi.c:59
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:192
void i2c_event(void)
Definition: i2c_arch.c:37
void spi_init_slaves(void)
Initialize all used slaves and unselect them.
Definition: spi_arch.c:39
arch independent UDP API
void VCOM_init(void)
Definition: usb_ser_hw.c:578
void spi0_init(void)
Definition: spi.c:37
arch independent USB API
Architecture independent I2C (Inter-Integrated Circuit Bus) API.