mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-02-06 02:52:42 +08:00
[rotorcraft][linux] limit main/event loop to 1kHz
This is a kludge until we can better leverage threads and have real events. Without this limit the event flags will constantly polled as fast as possible, resulting on 100% cpu load on boards with an (RT)OS. On bare metal boards this is not an issue, as you have nothing else running anyway. Enable this for the bebop and ardrone2 by default. Alternative to #1239 and should fix #1233
This commit is contained in:
@@ -42,6 +42,9 @@ $(TARGET).CFLAGS += -DUSE_LINUX_SIGNAL -D_GNU_SOURCE
|
||||
$(TARGET).CFLAGS += -DLINUX_LINK_STATIC
|
||||
$(TARGET).LDFLAGS += -static
|
||||
|
||||
# limit main loop to 1kHz so ap doesn't need 100% cpu
|
||||
$(TARGET).CFLAGS += -DLIMIT_EVENT_POLLING
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
|
||||
# default LED configuration
|
||||
|
||||
@@ -38,6 +38,9 @@ $(TARGET).srcs += $(SRC_BOARD)/video.c
|
||||
$(TARGET).CFLAGS += -DLINUX_LINK_STATIC
|
||||
$(TARGET).LDFLAGS += -static
|
||||
|
||||
# limit main loop to 1kHz so ap doesn't need 100% cpu
|
||||
$(TARGET).CFLAGS += -DLIMIT_EVENT_POLLING
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
|
||||
# default LED configuration
|
||||
|
||||
@@ -120,10 +120,34 @@ int main(void)
|
||||
{
|
||||
main_init();
|
||||
|
||||
#if LIMIT_EVENT_POLLING
|
||||
/* Limit main loop frequency to 1kHz.
|
||||
* This is a kludge until we can better leverage threads and have real events.
|
||||
* Without this limit the event flags will constantly polled as fast as possible,
|
||||
* resulting on 100% cpu load on boards with an (RT)OS.
|
||||
* On bare metal boards this is not an issue, as you have nothing else running anyway.
|
||||
*/
|
||||
uint32_t t_begin = 0;
|
||||
uint32_t t_diff = 0;
|
||||
while (1) {
|
||||
t_begin = get_sys_time_usec();
|
||||
|
||||
handle_periodic_tasks();
|
||||
main_event();
|
||||
|
||||
/* sleep remaining time to limit to 1kHz */
|
||||
t_diff = get_sys_time_usec() - t_begin;
|
||||
if (t_diff < 1000) {
|
||||
sys_time_usleep(1000 - t_diff);
|
||||
}
|
||||
}
|
||||
#else
|
||||
while (1) {
|
||||
handle_periodic_tasks();
|
||||
main_event();
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* SITL */
|
||||
|
||||
Reference in New Issue
Block a user