From 0aae8e13c113b49f1764d15c9c54544b2afe83f2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 19 Jan 2020 08:42:33 +1100 Subject: [PATCH] AP_HAL_ChibiOS: use take_blocking instead of HAL_SEMAPHORE_BLOCK_FOREVER this makes for cleaner and smaller code as the failure case is not needed --- libraries/AP_HAL_ChibiOS/Device.cpp | 6 ++---- libraries/AP_HAL_ChibiOS/RCInput.cpp | 10 +++++----- libraries/AP_HAL_ChibiOS/SPIDevice.cpp | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/Device.cpp b/libraries/AP_HAL_ChibiOS/Device.cpp index e14f1efb9e..7a0171ac38 100644 --- a/libraries/AP_HAL_ChibiOS/Device.cpp +++ b/libraries/AP_HAL_ChibiOS/Device.cpp @@ -58,10 +58,8 @@ void DeviceBus::bus_thread(void *arg) callback->next_usec += callback->period_usec; } // call it with semaphore held - if (binfo->semaphore.take(HAL_SEMAPHORE_BLOCK_FOREVER)) { - callback->cb(); - binfo->semaphore.give(); - } + WITH_SEMAPHORE(binfo->semaphore); + callback->cb(); } } diff --git a/libraries/AP_HAL_ChibiOS/RCInput.cpp b/libraries/AP_HAL_ChibiOS/RCInput.cpp index d06964ecba..114fca9173 100644 --- a/libraries/AP_HAL_ChibiOS/RCInput.cpp +++ b/libraries/AP_HAL_ChibiOS/RCInput.cpp @@ -90,7 +90,7 @@ uint16_t RCInput::read(uint8_t channel) if (!_init || (channel >= MIN(RC_INPUT_MAX_CHANNELS, _num_channels))) { return 0; } - rcin_mutex.take(HAL_SEMAPHORE_BLOCK_FOREVER); + rcin_mutex.take_blocking(); uint16_t v = _rc_values[channel]; rcin_mutex.give(); #if HAL_RCINPUT_WITH_AP_RADIO @@ -145,7 +145,7 @@ void RCInput::_timer_tick(void) #endif if (AP::RC().new_input()) { - rcin_mutex.take(HAL_SEMAPHORE_BLOCK_FOREVER); + rcin_mutex.take_blocking(); _rcin_timestamp_last_signal = AP_HAL::micros(); _num_channels = AP::RC().num_channels(); _num_channels = MIN(_num_channels, RC_INPUT_MAX_CHANNELS); @@ -163,7 +163,7 @@ void RCInput::_timer_tick(void) #if HAL_RCINPUT_WITH_AP_RADIO if (radio && radio->last_recv_us() != last_radio_us) { last_radio_us = radio->last_recv_us(); - rcin_mutex.take(HAL_SEMAPHORE_BLOCK_FOREVER); + rcin_mutex.take_blocking(); _rcin_timestamp_last_signal = last_radio_us; _num_channels = radio->num_channels(); _num_channels = MIN(_num_channels, RC_INPUT_MAX_CHANNELS); @@ -175,7 +175,7 @@ void RCInput::_timer_tick(void) #endif #if HAL_WITH_IO_MCU - rcin_mutex.take(HAL_SEMAPHORE_BLOCK_FOREVER); + rcin_mutex.take_blocking(); if (AP_BoardConfig::io_enabled() && iomcu.check_rcinput(last_iomcu_us, _num_channels, _rc_values, RC_INPUT_MAX_CHANNELS)) { _rcin_timestamp_last_signal = last_iomcu_us; @@ -204,7 +204,7 @@ void RCInput::_timer_tick(void) bool RCInput::rc_bind(int dsmMode) { #if HAL_WITH_IO_MCU - rcin_mutex.take(HAL_SEMAPHORE_BLOCK_FOREVER); + rcin_mutex.take_blocking(); if (AP_BoardConfig::io_enabled()) { iomcu.bind_dsm(dsmMode); } diff --git a/libraries/AP_HAL_ChibiOS/SPIDevice.cpp b/libraries/AP_HAL_ChibiOS/SPIDevice.cpp index 338d0ccdfb..14d88da32d 100644 --- a/libraries/AP_HAL_ChibiOS/SPIDevice.cpp +++ b/libraries/AP_HAL_ChibiOS/SPIDevice.cpp @@ -220,7 +220,7 @@ bool SPIDevice::clock_pulse(uint32_t n) { if (!cs_forced) { //special mode to init sdcard without cs asserted - bus.semaphore.take(HAL_SEMAPHORE_BLOCK_FOREVER); + bus.semaphore.take_blocking(); acquire_bus(true, true); spiIgnore(spi_devices[device_desc.bus].driver, n); acquire_bus(false, true);