Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
main_chibios.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013-2021 Gautier Hattenberger, Alexandre Bustico
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, see
18 * <http://www.gnu.org/licenses/>.
19 *
20 */
21
30#include "mcu_periph/sys_time.h"
31#include "mcu.h"
32#include <ch.h>
33
34#ifndef SYS_TIME_FREQUENCY
35#error SYS_TIME_FREQUENCY should be defined in Makefile.chibios or airframe.xml and be equal to CH_CFG_ST_FREQUENCY
36#elif CH_CFG_ST_FREQUENCY < (2 * PERIODIC_FREQUENCY) || SYS_TIME_FREQUENCY < (2 * PERIODIC_FREQUENCY)
37#error CH_CFG_ST_FREQUENCY and SYS_TIME_FREQUENCY should be >= 2 x PERIODIC_FREQUENCY
38#endif
39
40#if (defined AP) && (defined FBW)
41#error "AP and FBW can't be defined at the same time"
42#endif
43#if (!defined AP) && (!defined FBW)
44#error "AP or FBW should be defined"
45#endif
46
47#ifdef FBW
48#include "main_fbw.h"
49#define Call(f) main_fbw_ ## f
50#endif
51
52#ifdef AP
53#include "main_ap.h"
54#define Call(f) main_ap_ ## f
55#endif
56
57#include "generated/modules.h"
58
59#ifndef THD_WORKING_AREA_MAIN
60#define THD_WORKING_AREA_MAIN 8192
61#endif
62
63/*
64 * PPRZ/AP thread
65 */
66static void thd_ap(void *arg);
69
70#if USE_HARD_FAULT_RECOVERY
71#include "main_recovery.h"
72
73#ifndef THD_WORKING_AREA_RECOVERY
74#define THD_WORKING_AREA_RECOVERY 1024
75#endif
76
77static void thd_recovery(void *arg);
80#endif
81
85int main(void)
86{
87 // Init
88
89 // mcu modules init in all cases
91
92#if USE_HARD_FAULT_RECOVERY
93 // if recovering from hard fault, don't call AP init, only FBW
95#endif
96 Call(init());
98
99 // Create threads
101
102#if USE_HARD_FAULT_RECOVERY
103 } else {
106
107 // Create threads
109 }
110#endif
111
112 // Main loop, do nothing
114 return 0;
115}
116
117/*
118 * PPRZ/AP thread
119 *
120 * Call PPRZ AP periodic and event functions
121 */
122static void thd_ap(void *arg)
123{
124 (void) arg;
125 chRegSetThreadName("AP");
126
127 while (!chThdShouldTerminateX()) {
129 Call(periodic());
130 Call(event());
131 // The sleep time is computed to have a polling interval of
132 // 1e6 / CH_CFG_ST_FREQUENCY. If time is passed, thanks to the
133 // "Windowed" sleep function, the execution is not blocked until
134 // a complet roll-over.
136 }
137
138 chThdExit(0);
139}
140
141#if USE_HARD_FAULT_RECOVERY
142/*
143 * PPRZ/RECOVERY thread
144 *
145 * Call PPRZ minimal AP after MCU hard fault
146 */
147static void thd_recovery(void *arg)
148{
149 (void) arg;
150 chRegSetThreadName("RECOVERY");
151
152 while (!chThdShouldTerminateX()) {
156 // The sleep time is computed to have a polling interval of
157 // 1e6 / CH_CFG_ST_FREQUENCY. If time is passed, thanks to the
158 // "Windowed" sleep function, the execution is not blocked until
159 // a complet roll-over.
161 }
162
163 chThdExit(0);
164}
165#endif
166
167/*
168 * Terminate autopilot threads
169 * Wait until proper stop
170 */
172{
173 if (apThdPtr != NULL) {
176 apThdPtr = NULL;
177 }
178#if USE_HARD_FAULT_RECOVERY
179 if (recoveryThdPtr != NULL) {
183 }
184#endif
185}
186
#define CH_CFG_ST_FREQUENCY
System tick frequency.
Definition chconf.h:75
Autopilot main loop.
static thread_t * apThdPtr
static void thd_ap(void *arg)
#define THD_WORKING_AREA_MAIN
int main(void)
Main function.
THD_WORKING_AREA(wa_thd_ap, THD_WORKING_AREA_MAIN)
void pprz_terminate_autopilot_threads(void)
Terminate all autopilot threads Wait until proper stop.
uint16_t foo
Definition main_demo5.c:58
Fly By Wire:
void main_recovery_periodic(void)
void main_recovery_event(void)
void main_recovery_init(void)
Recovery mode: run manual mode in case of hardfault Based on legacy FBW.
Arch independent mcu ( Micro Controller Unit ) utilities.
bool init
Definition nav_gls.c:57
Architecture independent timing functions.