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
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 SYS_TIME_FREQUENCY != CH_CFG_ST_FREQUENCY
32 #error SYS_TIME_FREQUENCY should be equal to CH_CFG_ST_FREQUENCY
33 #elif CH_CFG_ST_FREQUENCY < (2 * PERIODIC_FREQUENCY)
34 #error CH_CFG_ST_FREQUENCY and SYS_TIME_FREQUENCY should be >= 2 x PERIODIC_FREQUENCY
35 #endif
36 
38 
39 #ifndef THD_WORKING_AREA_MAIN
40 #define THD_WORKING_AREA_MAIN 8192
41 #endif
42 
43 /*
44  * PPRZ/AP thread
45  * Also include FBW on single MCU
46  */
47 static void thd_ap(void *arg);
49 static thread_t *apThdPtr = NULL;
50 
54 int main(void)
55 {
56  // Init
57  main_init();
58 
59  chThdSleepMilliseconds(100);
60 
61  // Create threads
62  apThdPtr = chThdCreateStatic(wa_thd_ap, sizeof(wa_thd_ap), NORMALPRIO, thd_ap, NULL);
63 
64  // Main loop, do nothing
65  while (TRUE) {
66  chThdSleepMilliseconds(1000);
67  }
68  return 0;
69 }
70 
71 /*
72  * PPRZ/AP thread
73  *
74  * Call PPRZ AP periodic and event functions
75  */
76 static void thd_ap(void *arg)
77 {
78  (void) arg;
79  chRegSetThreadName("AP");
80 
81  while (!chThdShouldTerminateX()) {
83  main_event();
84  chThdSleepMicroseconds(500);
85  }
86 
87  chThdExit(0);
88 }
89 
90 /*
91  * Terminate autopilot threads
92  * Wait until proper stop
93  */
95 {
96  if (apThdPtr != NULL) {
97  chThdTerminate(apThdPtr);
98  chThdWait(apThdPtr);
99  apThdPtr = NULL;
100  }
101 }
102 
#define THD_WORKING_AREA_MAIN
Definition: main_chibios.c:40
static thread_t * apThdPtr
Definition: main_chibios.c:49
STATIC_INLINE void handle_periodic_tasks(void)
Definition: main_ap.c:202
THD_WORKING_AREA(wa_thd_ap, THD_WORKING_AREA_MAIN)
#define TRUE
Definition: std.h:4
Architecture independent timing functions.
static void thd_ap(void *arg)
Definition: main_chibios.c:76
static void main_event(void)
Definition: uart_tunnel.c:85
Rotorcraft main loop.
void pprz_terminate_autopilot_threads(void)
Terminate all autopilot threads Wait until proper stop.
Definition: main_chibios.c:166
Arch independent mcu ( Micro Controller Unit ) utilities.
static void main_init(void)
int main(void)
Main function.
Definition: main_chibios.c:87