AnsweredAssumed Answered

FXAS21002_Idle() and interrupt status

Question asked by Michael Durian on Jul 6, 2018

This is not really a question. It's a bug report with patch.

 

I've noticed that if you call FXAS21002_Idle() when the gyro is not needed, you might be left with a stuck interrupt. FXAS21002_Idle() puts the sensor in Ready mode (vs Active) and then set a flag in the driver indicating it is no longer initialized. This is fine. However, there still might be data in the FIFO which will keep the interrupt from the sensor asserted (if you are using interrupts). Since the sensor has been marked as not initialized, a call to FXAS21002_Read() to empty the FIFO and clear the interrupt will return without doing anything. This will leave the interrupt hanging.

 

I believe the fix is to call FXAS21002_Read() in FXAS21002_Idle() after putting the sensor in Ready mode, but before setting isInitialized to 0. Because isInitialized is still true, FXAS21002_Read() will succeed, emptying the FIFO and clearing the interrupt. Since the sensor is now in Ready mode, it won't collect any more data in the FIFO either.

 

The diff looks something like this. The line offsets will be different since I've made other changes to the driver to enable FIFO watermark interrupts. A more complete solution will check the return status of FXAS21002_Read().

 

@@ -336,6 +356,11 @@ int8_t FXAS21002_Idle(struct PhysicalSensor *sensor, SensorFusionGlobals *sfg)

     int32_t     status;

     if(sensor->isInitialized == F_USING_GYRO) {

         status = Sensor_I2C_Write(sensor->bus_driver, &sensor->deviceInfo, sensor->addr, FXAS21002_IDLE );

+        /*

+         * Clear out any data in the FIFO before marking the sensor as

+         * uninitialized.

+         */

+        FXAS21002_Read(sensor, sfg);

         sensor->isInitialized = 0;

         sfg->Gyro.isEnabled = false;

     } else {

Outcomes