Ardupilot2/libraries/AP_HAL_Linux/AP_HAL_Linux_Main.h
Víctor Mayoral Vilches 9f5b4ffca4 AP_HAL_Linux_Class: Correct deadlock, and infinite loop in setup()
(credit to Mitch Miers <mmiers@mmiers.com>):

setup() is attempting to initialize the hardware, and while doing so
is attempting to output some text via the console (and maybe mavlink
data).  The problem is, the output isn't going to complete once a
write buffer is full, because LinuxUARTDriver::_timer_tick() doesn't
perform work until _initialized is true.  So, what happens is,
setup() (and subroutines) call LinuxUARTDriver::_write(uint8_t c),
which loops waiting for buffer space to become available (once the
write buffer is full).  The buffer never gets space, because the
UART thread is waiting for initialization to complete before it
will write out data and drain the buffer, but that doesn't happen
until setup() returns (see AP_HAL_Linux_main.h).

Refer to https://groups.google.com/forum/#!topic/beaglepilot/dQlxse11JNI
2014-07-14 09:02:47 +10:00

19 lines
470 B
C

#ifndef __AP_HAL_LINUX_MAIN_H__
#define __AP_HAL_LINUX_MAIN_H__
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX || CONFIG_HAL_BOARD == HAL_BOARD_ERLE
#define AP_HAL_MAIN() extern "C" {\
int main (int argc, char * const argv[]) { \
hal.init(argc, argv); \
hal.scheduler->system_initialized(); \
setup();\
for(;;) loop();\
return 0;\
}\
}
#endif // HAL_BOARD_LINUX || HAL_BOARD_ERLE
#endif // __AP_HAL_LINUX_MAIN_H__