From 5102f1511b962c7a27c8c2107a160157aac89d57 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 29 Sep 2013 10:32:51 +1000 Subject: [PATCH] HAL_Linux: fixed callbacks from delay() --- libraries/AP_HAL_Linux/Scheduler.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libraries/AP_HAL_Linux/Scheduler.cpp b/libraries/AP_HAL_Linux/Scheduler.cpp index 6568d0f438..d4929a13f5 100644 --- a/libraries/AP_HAL_Linux/Scheduler.cpp +++ b/libraries/AP_HAL_Linux/Scheduler.cpp @@ -10,6 +10,7 @@ #include #include #include +#include using namespace Linux; @@ -63,7 +64,21 @@ void LinuxScheduler::init(void* machtnichts) void LinuxScheduler::delay(uint16_t ms) { - usleep(ms * 1000); + if (_in_timer_proc) { + ::printf("ERROR: delay() from timer process\n"); + return; + } + uint32_t start = millis(); + + while ((millis() - start) < ms) { + // this yields the CPU to other apps + poll(NULL, 0, 1); + if (_min_delay_cb_ms <= ms) { + if (_delay_cb) { + _delay_cb(); + } + } + } } uint32_t LinuxScheduler::millis()