From d15097f3fcbb2f8128c5d2a4599f0ed705c114aa Mon Sep 17 00:00:00 2001 From: Julien BERAUD Date: Mon, 3 Aug 2015 18:16:01 +0200 Subject: [PATCH] AP_Baro_MS5611: Support for timesliced timers fallback if current scheduler doesn't support it --- libraries/AP_Baro/AP_Baro_MS5611.cpp | 6 ++++-- libraries/AP_Baro/AP_Baro_MS5611.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/AP_Baro/AP_Baro_MS5611.cpp b/libraries/AP_Baro/AP_Baro_MS5611.cpp index d53f187c0e..422249e430 100644 --- a/libraries/AP_Baro/AP_Baro_MS5611.cpp +++ b/libraries/AP_Baro/AP_Baro_MS5611.cpp @@ -223,7 +223,8 @@ void AP_Baro_MS56XX::_init() hal.scheduler->resume_timer_procs(); if (_use_timer) { - hal.scheduler->register_timer_process(FUNCTOR_BIND_MEMBER(&AP_Baro_MS56XX::_timer, void)); + /* timer needs to be called every 10ms so set the freq_div to 10 */ + _timesliced = hal.scheduler->register_timer_process(FUNCTOR_BIND_MEMBER(&AP_Baro_MS56XX::_timer, void), 10); } } @@ -310,7 +311,8 @@ bool AP_Baro_MS5637::_read_prom(uint16_t prom[8]) void AP_Baro_MS56XX::_timer(void) { // Throttle read rate to 100hz maximum. - if (AP_HAL::micros() - _last_timer < 10000) { + if (!_timesliced && + AP_HAL::micros() - _last_timer < 10000) { return; } diff --git a/libraries/AP_Baro/AP_Baro_MS5611.h b/libraries/AP_Baro/AP_Baro_MS5611.h index 959fdd17c6..f7d3e51e26 100644 --- a/libraries/AP_Baro/AP_Baro_MS5611.h +++ b/libraries/AP_Baro/AP_Baro_MS5611.h @@ -94,6 +94,7 @@ protected: volatile uint32_t _s_D1, _s_D2; uint8_t _state; uint32_t _last_timer; + bool _timesliced; bool _use_timer;