Paparazzi UAS  v6.1.0_stable
Paparazzi is a free software Unmanned Aircraft System.
main_chibios.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 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 
25 #include "mcu_periph/sys_time.h"
26 #include "mcu.h"
27 #include <ch.h>
28 
29 #ifndef SYS_TIME_FREQUENCY
30 #error SYS_TIME_FREQUENCY should be defined in Makefile.chibios or airframe.xml and be equal to CH_CFG_ST_FREQUENCY
31 #elif CH_CFG_ST_FREQUENCY < (2 * PERIODIC_FREQUENCY)
32 #error CH_CFG_ST_FREQUENCY and SYS_TIME_FREQUENCY should be >= 2 x PERIODIC_FREQUENCY
33 #endif
34 
36 
37 #ifndef THD_WORKING_AREA_MAIN
38 #define THD_WORKING_AREA_MAIN 8192
39 #endif
40 
41 /*
42  * PPRZ/AP thread
43  * Also include FBW on single MCU
44  */
45 static void thd_ap(void *arg);
47 static thread_t *apThdPtr = NULL;
48 
52 int main(void)
53 {
54  // Init
55  main_init();
56 
57  chThdSleepMilliseconds(100);
58 
59  // Create threads
60  apThdPtr = chThdCreateStatic(wa_thd_ap, sizeof(wa_thd_ap), NORMALPRIO, thd_ap, NULL);
61 
62  // Main loop, do nothing
63  while (TRUE) {
64  chThdSleepMilliseconds(1000);
65  }
66  return 0;
67 }
68 
69 /*
70  * PPRZ/AP thread
71  *
72  * Call PPRZ AP periodic and event functions
73  */
74 static void thd_ap(void *arg)
75 {
76  (void) arg;
77  chRegSetThreadName("AP");
78 
79  while (!chThdShouldTerminateX()) {
80  systime_t t = chVTGetSystemTime();
82  main_event();
83  // The sleep time is computed to have a polling interval of
84  // 1e6 / CH_CFG_ST_FREQUENCY. If time is passed, thanks to the
85  // "Windowed" sleep function, the execution is not blocked until
86  // a complet roll-over.
87  chThdSleepUntilWindowed(t, t + TIME_US2I(1000000 / CH_CFG_ST_FREQUENCY));
88  }
89 
90  chThdExit(0);
91 }
92 
93 /*
94  * Terminate autopilot threads
95  * Wait until proper stop
96  */
98 {
99  if (apThdPtr != NULL) {
100  chThdTerminate(apThdPtr);
101  chThdWait(apThdPtr);
102  apThdPtr = NULL;
103  }
104 }
105 
main_event
static void main_event(void)
Definition: uart_tunnel.c:85
main
int main(void)
Main function.
Definition: main_chibios.c:85
apThdPtr
static thread_t * apThdPtr
Definition: main_chibios.c:47
CH_CFG_ST_FREQUENCY
#define CH_CFG_ST_FREQUENCY
System tick frequency.
Definition: chconf.h:55
pprz_terminate_autopilot_threads
void pprz_terminate_autopilot_threads(void)
Terminate all autopilot threads Wait until proper stop.
Definition: main_chibios.c:172
thd_ap
static void thd_ap(void *arg)
Definition: main_chibios.c:74
THD_WORKING_AREA
THD_WORKING_AREA(wa_thd_ap, THD_WORKING_AREA_MAIN)
mcu.h
Arch independent mcu ( Micro Controller Unit ) utilities.
sys_time.h
Architecture independent timing functions.
THD_WORKING_AREA_MAIN
#define THD_WORKING_AREA_MAIN
Definition: main_chibios.c:38
main_init
static void main_init(void)
Definition: demo_ahrs_actuators.c:87
main_ap.h
TRUE
#define TRUE
Definition: std.h:4
handle_periodic_tasks
STATIC_INLINE void handle_periodic_tasks(void)
Definition: main_ap.c:128