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.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 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 
31 #if FBW
33 #else
35 #endif
36 
37 #include "mcu_periph/sys_time.h"
38 
39 #ifndef SITL
40 int main(void)
41 {
42  main_init();
43 
44 #if LIMIT_EVENT_POLLING
45  /* Limit main loop frequency to 1kHz.
46  * This is a kludge until we can better leverage threads and have real events.
47  * Without this limit the event flags will constantly polled as fast as possible,
48  * resulting on 100% cpu load on boards with an (RT)OS.
49  * On bare metal boards this is not an issue, as you have nothing else running anyway.
50  */
51  uint32_t t_begin = 0;
52  uint32_t t_diff = 0;
53  while (1) {
54  t_begin = get_sys_time_usec();
55 
57  main_event();
58 
59  /* sleep remaining time to limit to 1kHz */
60  t_diff = get_sys_time_usec() - t_begin;
61  if (t_diff < 1000) {
62  sys_time_usleep(1000 - t_diff);
63  }
64  }
65 #else
66  while (1) {
68  main_event();
69  }
70 #endif
71 
72  return 0;
73 }
74 #endif /* SITL */
75 
STATIC_INLINE void handle_periodic_tasks(void)
Definition: main_ap.c:200
void sys_time_usleep(uint32_t us)
sys_time_usleep(uint32_t us)
Definition: sys_time_arch.c:95
Architecture independent timing functions.
static void main_event(void)
Definition: uart_tunnel.c:85
unsigned long uint32_t
Definition: types.h:18
int main(void)
Definition: main.c:42
Rotorcraft main loop.
Fly By Wire:
static void main_init(void)
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68