mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-08 17:08:28 -04:00
AP_InertialSensor: prevent a lockup in MPU6000 driver
thanks to the VRBrain port for noticing this bug. Failing to get the semaphore is an expected error with the MPU6000, as we read data both from timer context and mainline code. That means semaphore conflicts are inevitable. We shouldn't consider them an error, and shouldn't panic when some arbitrary number of them have happened since boot. Instead the wait_for_sample() code checks that we receive new data at least every 50ms. That is a much safer test.
This commit is contained in:
parent
c888f0256f
commit
770b7b5901
@ -419,18 +419,14 @@ void AP_InertialSensor_MPU6000::_poll_data(uint32_t now)
|
||||
*/
|
||||
void AP_InertialSensor_MPU6000::_read_data_from_timerprocess()
|
||||
{
|
||||
static uint8_t semfail_ctr = 0;
|
||||
bool got = _spi_sem->take_nonblocking();
|
||||
if (!got) {
|
||||
semfail_ctr++;
|
||||
if (semfail_ctr > 100) {
|
||||
hal.scheduler->panic(PSTR("PANIC: failed to take SPI semaphore "
|
||||
"100 times in AP_InertialSensor_MPU6000::"
|
||||
"_read_data_from_timerprocess"));
|
||||
}
|
||||
if (!_spi_sem->take_nonblocking()) {
|
||||
/*
|
||||
the semaphore being busy is an expected condition when the
|
||||
mainline code is calling num_samples_available() which will
|
||||
grab the semaphore. We return now and rely on the mainline
|
||||
code grabbing the latest sample.
|
||||
*/
|
||||
return;
|
||||
} else {
|
||||
semfail_ctr = 0;
|
||||
}
|
||||
|
||||
_last_sample_time_micros = hal.scheduler->micros();
|
||||
|
Loading…
Reference in New Issue
Block a user