AP_InertialSensor: BMI160: convert it to use Device periodic callback

Some notes:
 - The only place that made sense to use
   suspend_timer_procs()/resume_timer_procs() calls were where we registered
   the timer process. Now there's no need for that anymore. Remove those calls
   from other place in the source too.
 - There's no need to acquire the device lock now that we are running as a
   periodic callback.
This commit is contained in:
Gustavo Jose de Sousa 2016-08-29 11:11:23 -03:00 committed by Lucas De Marchi
parent b259356703
commit b6c0e11200
2 changed files with 7 additions and 17 deletions

View File

@ -145,7 +145,6 @@ void AP_InertialSensor_BMI160::start()
{ {
bool r; bool r;
hal.scheduler->suspend_timer_procs();
if (!_dev->get_semaphore()->take(100)) { if (!_dev->get_semaphore()->take(100)) {
AP_HAL::panic("BMI160: Unable to get semaphore"); AP_HAL::panic("BMI160: Unable to get semaphore");
} }
@ -177,10 +176,9 @@ void AP_InertialSensor_BMI160::start()
_accel_instance = _imu.register_accel(BMI160_ODR_TO_HZ(BMI160_ODR)); _accel_instance = _imu.register_accel(BMI160_ODR_TO_HZ(BMI160_ODR));
_gyro_instance = _imu.register_gyro(BMI160_ODR_TO_HZ(BMI160_ODR)); _gyro_instance = _imu.register_gyro(BMI160_ODR_TO_HZ(BMI160_ODR));
hal.scheduler->register_timer_process( /* Call _poll_data() at 1kHz */
FUNCTOR_BIND_MEMBER(&AP_InertialSensor_BMI160::_poll_data, void)); _dev->register_periodic_callback(1000,
FUNCTOR_BIND_MEMBER(&AP_InertialSensor_BMI160::_poll_data, bool));
hal.scheduler->resume_timer_procs();
} }
bool AP_InertialSensor_BMI160::update() bool AP_InertialSensor_BMI160::update()
@ -407,15 +405,10 @@ read_fifo_end:
} }
} }
void AP_InertialSensor_BMI160::_poll_data() bool AP_InertialSensor_BMI160::_poll_data()
{ {
if (!_dev->get_semaphore()->take_nonblocking()) {
return;
}
_read_fifo(); _read_fifo();
return true;
_dev->get_semaphore()->give();
} }
bool AP_InertialSensor_BMI160::_hardware_init() bool AP_InertialSensor_BMI160::_hardware_init()
@ -485,10 +478,7 @@ bool AP_InertialSensor_BMI160::_init()
bool ret = false; bool ret = false;
_dev->set_read_flag(BMI160_READ_FLAG); _dev->set_read_flag(BMI160_READ_FLAG);
hal.scheduler->suspend_timer_procs();
ret = _hardware_init(); ret = _hardware_init();
hal.scheduler->resume_timer_procs();
if (!ret) { if (!ret) {
hal.console->printf("BMI160: failed to init\n"); hal.console->printf("BMI160: failed to init\n");
} }

View File

@ -96,9 +96,9 @@ private:
bool _configure_fifo(); bool _configure_fifo();
/** /**
* Timer routine to read data from the sensors. * Device periodic callback to read data from the sensors.
*/ */
void _poll_data(); bool _poll_data();
/** /**
* Read samples from fifo. * Read samples from fifo.