Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
main_bare.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017-2021 Gautier Hattenberger <gautier.hattenberger@enac.fr>
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 
32 #if (defined AP) && (defined FBW)
33 #error "AP and FBW can't be defined at the same time"
34 #endif
35 #if (!defined AP) && (!defined FBW)
36 #error "AP or FBW should be defined"
37 #endif
38 
39 #ifdef FBW
40 #include "main_fbw.h"
41 #define Call(f) main_fbw_ ## f
42 #endif
43 
44 #ifdef AP
45 #include "main_ap.h"
46 #define Call(f) main_ap_ ## f
47 #endif
48 
49 #include "generated/modules.h"
50 
51 #include "mcu_periph/sys_time.h"
52 
53 #define POLLING_PERIOD (500000/PERIODIC_FREQUENCY)
54 
55 #ifndef SITL
56 int main(void)
57 {
58  // mcu modules init in all cases
59  modules_mcu_init();
60 
61  Call(init());
62 
63 #if LIMIT_EVENT_POLLING
64  /* Limit main loop frequency to 1kHz.
65  * This is a kludge until we can better leverage threads and have real events.
66  * Without this limit the event flags will constantly polled as fast as possible,
67  * resulting on 100% cpu load on boards with an (RT)OS.
68  * On bare metal boards this is not an issue, as you have nothing else running anyway.
69  */
70  uint32_t t_begin = 0;
71  uint32_t t_diff = 0;
72  while (1) {
73  t_begin = get_sys_time_usec();
74 
75  Call(periodic());
76  Call(event());
77 
78  /* sleep remaining time to limit to polling frequency */
79  t_diff = get_sys_time_usec() - t_begin;
80  if (t_diff < POLLING_PERIOD) {
82  }
83  }
84 #else
85  while (1) {
86  Call(periodic());
87  Call(event());
88  }
89 #endif
90 
91  return 0;
92 }
93 #endif /* SITL */
94 
void sys_time_usleep(uint32_t us)
sys_time_usleep(uint32_t us)
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:71
Autopilot main loop.
#define POLLING_PERIOD
Definition: main_bare.c:53
int main(void)
Definition: main_bare.c:56
Fly By Wire:
bool init
Definition: nav_gls.c:57
Architecture independent timing functions.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78