From d8fd590a3f4a7c534c3f3dbcd7b119bf4a20ce54 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 3 Nov 2018 17:27:10 +1100 Subject: [PATCH] AP_IOMCU: fixed a race in event trigger on startup this fixes the issue with initial safety option state, and with initial safety mask --- libraries/AP_IOMCU/AP_IOMCU.cpp | 4 ++++ libraries/AP_IOMCU/AP_IOMCU.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/libraries/AP_IOMCU/AP_IOMCU.cpp b/libraries/AP_IOMCU/AP_IOMCU.cpp index 9c0fc62cec..94dd0b3d7b 100644 --- a/libraries/AP_IOMCU/AP_IOMCU.cpp +++ b/libraries/AP_IOMCU/AP_IOMCU.cpp @@ -156,6 +156,7 @@ void AP_IOMCU::event_failed(uint8_t event) void AP_IOMCU::thread_main(void) { thread_ctx = chThdGetSelfX(); + chEvtSignal(thread_ctx, initial_event_mask); uart.begin(1500*1000, 256, 256); uart.set_blocking_writes(false); @@ -526,6 +527,9 @@ void AP_IOMCU::trigger_event(uint8_t event) { if (thread_ctx != nullptr) { chEvtSignal(thread_ctx, EVENT_MASK(event)); + } else { + // thread isn't started yet, trigger this event once it is started + initial_event_mask |= EVENT_MASK(event); } } diff --git a/libraries/AP_IOMCU/AP_IOMCU.h b/libraries/AP_IOMCU/AP_IOMCU.h index 11058c4779..205fc04bc3 100644 --- a/libraries/AP_IOMCU/AP_IOMCU.h +++ b/libraries/AP_IOMCU/AP_IOMCU.h @@ -109,6 +109,8 @@ private: // IOMCU thread thread_t *thread_ctx; + eventmask_t initial_event_mask; + // time when we last read various pages uint32_t last_status_read_ms; uint32_t last_rc_read_ms;