Paparazzi UAS  v5.15_devel-230-gc96ce27
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 #define POLLING_PERIOD (500000/PERIODIC_FREQUENCY)
40 #include <stdio.h>
41 #ifndef SITL
42 int main(void)
43 {
44  main_init();
45 
46 #if LIMIT_EVENT_POLLING
47  /* Limit main loop frequency to 1kHz.
48  * This is a kludge until we can better leverage threads and have real events.
49  * Without this limit the event flags will constantly polled as fast as possible,
50  * resulting on 100% cpu load on boards with an (RT)OS.
51  * On bare metal boards this is not an issue, as you have nothing else running anyway.
52  */
53  uint32_t t_begin = 0;
54  uint32_t t_diff = 0;
55  while (1) {
56  t_begin = get_sys_time_usec();
57 
59  main_event();
60 
61  /* sleep remaining time to limit to polling frequency */
62  t_diff = get_sys_time_usec() - t_begin;
63  if (t_diff < POLLING_PERIOD) {
65  }
66  }
67 #else
68  while (1) {
70  main_event();
71  }
72 #endif
73 
74  return 0;
75 }
76 #endif /* SITL */
77 
STATIC_INLINE void handle_periodic_tasks(void)
Definition: main_ap.c:202
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
#define POLLING_PERIOD
Definition: main.c:39