Paparazzi UAS  v5.12_stable-4-g9b43e9b
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 /*
41  * PPRZ/AP thread
42  * Also include FBW on single MCU
43  */
44 static void thd_ap(void *arg);
45 static THD_WORKING_AREA(wa_thd_ap, 8192);
46 static thread_t *apThdPtr = NULL;
47 
51 int main(void)
52 {
53  // Init
54  main_init();
55 
56  chThdSleepMilliseconds(100);
57 
58  // Create threads
59  apThdPtr = chThdCreateStatic(wa_thd_ap, sizeof(wa_thd_ap), NORMALPRIO, thd_ap, NULL);
60 
61  // Main loop, do nothing
62  while (TRUE) {
63  chThdSleepMilliseconds(1000);
64  }
65  return 0;
66 }
67 
68 /*
69  * PPRZ/AP thread
70  *
71  * Call PPRZ AP periodic and event functions
72  */
73 static void thd_ap(void *arg)
74 {
75  (void) arg;
76  chRegSetThreadName("AP");
77 
78  while (!chThdShouldTerminateX()) {
80  main_event();
81  chThdSleepMicroseconds(500);
82  }
83 
84  chThdExit(0);
85 }
86 
87 /*
88  * Terminate autopilot threads
89  * Wait until proper stop
90  */
92 {
93  if (apThdPtr != NULL) {
94  chThdTerminate(apThdPtr);
95  chThdWait(apThdPtr);
96  apThdPtr = NULL;
97  }
98 }
99 
STATIC_INLINE void handle_periodic_tasks(void)
Definition: main_ap.c:200
static void thd_ap(void *arg)
Definition: main_chibios.c:73
#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:152
Arch independent mcu ( Micro Controller Unit ) utilities.
static void main_init(void)
static thread_t * apThdPtr
Definition: main_chibios.c:46
int main(void)
Main function.
Definition: main_chibios.c:73
static THD_WORKING_AREA(wa_thd_ap, 8192)