Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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
32
#include "
firmwares/rotorcraft/main_fbw.h
"
33
#else
34
#include "
firmwares/rotorcraft/main_ap.h
"
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
58
handle_periodic_tasks
();
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
) {
64
sys_time_usleep
(
POLLING_PERIOD
- t_diff);
65
}
66
}
67
#else
68
while
(1) {
69
handle_periodic_tasks
();
70
main_event
();
71
}
72
#endif
73
74
return
0;
75
}
76
#endif
/* SITL */
77
main
int main(void)
Definition:
main.c:42
sys_time_usleep
void sys_time_usleep(uint32_t us)
sys_time_usleep(uint32_t us)
Definition:
sys_time_arch.c:95
POLLING_PERIOD
#define POLLING_PERIOD
Definition:
main.c:39
uint32_t
unsigned long uint32_t
Definition:
types.h:18
main_fbw.h
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition:
sys_time_arch.c:68
sys_time.h
Architecture independent timing functions.
main_init
static void main_init(void)
Definition:
demo_ahrs_actuators.c:87
main_event
static void main_event(void)
Definition:
uart_tunnel.c:85
main_ap.h
handle_periodic_tasks
STATIC_INLINE void handle_periodic_tasks(void)
Definition:
main_ap.c:202
sw
airborne
firmwares
rotorcraft
main.c
Generated on Tue Feb 1 2022 13:51:13 for Paparazzi UAS by
1.8.17