From c8395bb2c126af73e549b5ab4b14d052f6da6afd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 30 Jan 2020 08:25:24 +1100 Subject: [PATCH] HAL_ChibiOS: use blocking semaphore for new_input() this prevents a race where we continually fail to get new input --- libraries/AP_HAL_ChibiOS/RCInput.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/RCInput.cpp b/libraries/AP_HAL_ChibiOS/RCInput.cpp index faece37f74f..547d2a4e99b 100644 --- a/libraries/AP_HAL_ChibiOS/RCInput.cpp +++ b/libraries/AP_HAL_ChibiOS/RCInput.cpp @@ -73,13 +73,12 @@ bool RCInput::new_input() if (!_init) { return false; } - if (!rcin_mutex.take_nonblocking()) { - return false; + bool valid; + { + WITH_SEMAPHORE(rcin_mutex); + valid = _rcin_timestamp_last_signal != _last_read; + _last_read = _rcin_timestamp_last_signal; } - bool valid = _rcin_timestamp_last_signal != _last_read; - - _last_read = _rcin_timestamp_last_signal; - rcin_mutex.give(); #if HAL_RCINPUT_WITH_AP_RADIO if (!_radio_init) { @@ -134,7 +133,7 @@ uint8_t RCInput::read(uint16_t* periods, uint8_t len) memcpy(periods, _rc_values, len*sizeof(periods[0])); } #if HAL_RCINPUT_WITH_AP_RADIO - if (radio && channel == 0) { + if (radio) { // hook to allow for update of radio on main thread, for mavlink sends radio->update(); }