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) 2013-2015 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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
26 #include "mcu_periph/sys_time.h"
27 #include "mcu.h"
28 #include <ch.h>
29 
30 #ifndef SYS_TIME_FREQUENCY
31 #error SYS_TIME_FREQUENCY should be defined in Makefile.chibios or airframe.xml and be equal to CH_CFG_ST_FREQUENCY
32 #elif SYS_TIME_FREQUENCY != CH_CFG_ST_FREQUENCY
33 #error SYS_TIME_FREQUENCY should be equal to CH_CFG_ST_FREQUENCY
34 #elif CH_CFG_ST_FREQUENCY < (2 * PERIODIC_FREQUENCY)
35 #error CH_CFG_ST_FREQUENCY and SYS_TIME_FREQUENCY should be >= 2 x PERIODIC_FREQUENCY
36 #endif
37 
39 
40 #ifndef THD_WORKING_AREA_MAIN
41 #define THD_WORKING_AREA_MAIN 8192
42 #endif
43 
44 /*
45  * PPRZ/AP thread
46  * Also include FBW on single MCU
47  */
48 static void thd_ap(void *arg);
50 static thread_t *apThdPtr = NULL;
51 
55 int main(void)
56 {
57  // Init
58  main_init();
59 
60  chThdSleepMilliseconds(100);
61 
62  // Create threads
63  apThdPtr = chThdCreateStatic(wa_thd_ap, sizeof(wa_thd_ap), NORMALPRIO, thd_ap, NULL);
64 
65  // Main loop, do nothing
66  while (TRUE) {
67  chThdSleepMilliseconds(1000);
68  }
69  return 0;
70 }
71 
72 /*
73  * PPRZ/AP thread
74  *
75  * Call PPRZ AP periodic and event functions
76  */
77 static void thd_ap(void *arg)
78 {
79  (void) arg;
80  chRegSetThreadName("AP");
81 
82  while (!chThdShouldTerminateX()) {
84  main_event();
85  chThdSleepMicroseconds(500);
86  }
87 
88  chThdExit(0);
89 }
90 
91 /*
92  * Terminate autopilot threads
93  * Wait until proper stop
94  */
96 {
97  if (apThdPtr != NULL) {
98  chThdTerminate(apThdPtr);
99  chThdWait(apThdPtr);
100  apThdPtr = NULL;
101  }
102 }
103 
#define THD_WORKING_AREA_MAIN
Definition: main_chibios.c:41
STATIC_INLINE void handle_periodic_tasks(void)
Definition: main_ap.c:202
THD_WORKING_AREA(wa_thd_ap, THD_WORKING_AREA_MAIN)
static void thd_ap(void *arg)
Definition: main_chibios.c:77
#define TRUE
Definition: std.h:4
Architecture independent timing functions.
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)
static thread_t * apThdPtr
Definition: main_chibios.c:50
int main(void)
Main function.
Definition: main_chibios.c:87