Browse Source

AP_HAL_Linux: add semaphore to AnalogIn::channel to make it thread safe

zr-v5.1
Iampete1 4 years ago committed by Andrew Tridgell
parent
commit
4315a69b9d
  1. 1
      libraries/AP_HAL_Linux/AnalogIn_ADS1115.cpp
  2. 1
      libraries/AP_HAL_Linux/AnalogIn_ADS1115.h
  3. 1
      libraries/AP_HAL_Linux/AnalogIn_Navio2.cpp
  4. 1
      libraries/AP_HAL_Linux/AnalogIn_Navio2.h

1
libraries/AP_HAL_Linux/AnalogIn_ADS1115.cpp

@ -49,6 +49,7 @@ AnalogIn_ADS1115::AnalogIn_ADS1115()
AP_HAL::AnalogSource* AnalogIn_ADS1115::channel(int16_t pin) AP_HAL::AnalogSource* AnalogIn_ADS1115::channel(int16_t pin)
{ {
WITH_SEMAPHORE(_semaphore);
for (uint8_t j = 0; j < _channels_number; j++) { for (uint8_t j = 0; j < _channels_number; j++) {
if (_channels[j] == nullptr) { if (_channels[j] == nullptr) {
_channels[j] = new AnalogSource_ADS1115(pin); _channels[j] = new AnalogSource_ADS1115(pin);

1
libraries/AP_HAL_Linux/AnalogIn_ADS1115.h

@ -37,4 +37,5 @@ private:
AP_ADC_ADS1115 *_adc; AP_ADC_ADS1115 *_adc;
AnalogSource_ADS1115 *_channels[ADS1115_ADC_MAX_CHANNELS]; AnalogSource_ADS1115 *_channels[ADS1115_ADC_MAX_CHANNELS];
uint32_t _last_update_timestamp; uint32_t _last_update_timestamp;
HAL_Semaphore _semaphore;
}; };

1
libraries/AP_HAL_Linux/AnalogIn_Navio2.cpp

@ -107,6 +107,7 @@ float AnalogIn_Navio2::servorail_voltage(void)
AP_HAL::AnalogSource *AnalogIn_Navio2::channel(int16_t pin) AP_HAL::AnalogSource *AnalogIn_Navio2::channel(int16_t pin)
{ {
WITH_SEMAPHORE(_semaphore);
for (uint8_t j = 0; j < _channels_number; j++) { for (uint8_t j = 0; j < _channels_number; j++) {
if (_channels[j] == nullptr) { if (_channels[j] == nullptr) {
_channels[j] = new AnalogSource_Navio2(pin); _channels[j] = new AnalogSource_Navio2(pin);

1
libraries/AP_HAL_Linux/AnalogIn_Navio2.h

@ -36,4 +36,5 @@ private:
uint8_t _channels_number = NAVIO_ADC_MAX_CHANNELS; uint8_t _channels_number = NAVIO_ADC_MAX_CHANNELS;
AP_HAL::AnalogSource *_board_voltage_pin = nullptr; AP_HAL::AnalogSource *_board_voltage_pin = nullptr;
AP_HAL::AnalogSource *_servorail_pin = nullptr; AP_HAL::AnalogSource *_servorail_pin = nullptr;
HAL_Semaphore _semaphore;
}; };

Loading…
Cancel
Save