From 63556b9804757328231676cf757f4851e0f02dee Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 12 Oct 2018 10:35:32 +1100 Subject: [PATCH] HAL_Linux: removed hal.util->new_semaphore() replaced with HAL_Semaphore --- libraries/AP_HAL_Linux/AnalogIn_IIO.cpp | 48 ++++++++++++------------- libraries/AP_HAL_Linux/AnalogIn_IIO.h | 2 +- libraries/AP_HAL_Linux/Util.h | 3 -- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/libraries/AP_HAL_Linux/AnalogIn_IIO.cpp b/libraries/AP_HAL_Linux/AnalogIn_IIO.cpp index 475a6ac4ec..3d15c16e31 100644 --- a/libraries/AP_HAL_Linux/AnalogIn_IIO.cpp +++ b/libraries/AP_HAL_Linux/AnalogIn_IIO.cpp @@ -1,6 +1,7 @@ #include "AnalogIn_IIO.h" #include +#include extern const AP_HAL::HAL &hal; @@ -23,7 +24,6 @@ AnalogSource_IIO::AnalogSource_IIO(int16_t pin, float initial_value, float volta _sum_count(0), _pin_fd(-1) { - _semaphore = hal.util->new_semaphore(); init_pins(); select_pin(); } @@ -51,16 +51,16 @@ void AnalogSource_IIO::select_pin(void) float AnalogSource_IIO::read_average() { read_latest(); - if (_semaphore->take(1)) { - if (_sum_count == 0) { - _semaphore->give(); - return _value; - } - _value = _sum_value / _sum_count; - _sum_value = 0; - _sum_count = 0; - _semaphore->give(); + WITH_SEMAPHORE(_semaphore); + + if (_sum_count == 0) { + return _value; } + + _value = _sum_value / _sum_count; + _sum_value = 0; + _sum_count = 0; + return _value; } @@ -78,12 +78,11 @@ float AnalogSource_IIO::read_latest() _latest = 0; return 0; } - if (_semaphore->take(1)) { - _latest = atoi(sbuf) * _voltage_scaling; - _sum_value += _latest; - _sum_count++; - _semaphore->give(); - } + WITH_SEMAPHORE(_semaphore); + + _latest = atoi(sbuf) * _voltage_scaling; + _sum_value += _latest; + _sum_count++; return _latest; } @@ -106,15 +105,14 @@ void AnalogSource_IIO::set_pin(uint8_t pin) return; } - if (_semaphore->take(HAL_SEMAPHORE_BLOCK_FOREVER)) { - _pin = pin; - _sum_value = 0; - _sum_count = 0; - _latest = 0; - _value = 0; - select_pin(); - _semaphore->give(); - } + WITH_SEMAPHORE(_semaphore); + + _pin = pin; + _sum_value = 0; + _sum_count = 0; + _latest = 0; + _value = 0; + select_pin(); } void AnalogSource_IIO::set_stop_pin(uint8_t p) diff --git a/libraries/AP_HAL_Linux/AnalogIn_IIO.h b/libraries/AP_HAL_Linux/AnalogIn_IIO.h index cd5255837f..e6ce28157b 100644 --- a/libraries/AP_HAL_Linux/AnalogIn_IIO.h +++ b/libraries/AP_HAL_Linux/AnalogIn_IIO.h @@ -42,7 +42,7 @@ private: int16_t _pin; int _pin_fd; int fd_analog_sources[IIO_ANALOG_IN_COUNT]; - AP_HAL::Semaphore *_semaphore; + HAL_Semaphore _semaphore; void init_pins(void); void select_pin(void); diff --git a/libraries/AP_HAL_Linux/Util.h b/libraries/AP_HAL_Linux/Util.h index 13ff1801c1..88a50a395c 100644 --- a/libraries/AP_HAL_Linux/Util.h +++ b/libraries/AP_HAL_Linux/Util.h @@ -90,9 +90,6 @@ public: return Perf::get_instance()->count(perf); } - // create a new semaphore - AP_HAL::Semaphore *new_semaphore(void) override { return new Semaphore; } - int get_hw_arm32(); bool toneAlarm_init() override { return _toneAlarm.init(); }