mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-28 09:58:23 +08:00
[ms5611] Fix baro i2c transactions
Since the simple i2c driver for linux does busy waiting on i2c_submit (and not queue a new transaction), setting the transaction status to done at the end (with a new transcaction in between) will set the status of the wrong transaction... Did not seem happen with the other i2c implementations (lpc21, stm32) so far, but since they add the transaction to the queue which is handled in the I2C ISR, it could also happen there (race condition). closes #960
This commit is contained in:
committed by
Felix Ruess
parent
5893091ea7
commit
eb38af898c
@@ -129,6 +129,7 @@ void ms5611_i2c_event(struct Ms5611_I2c *ms) {
|
||||
ms->data.d1 = (ms->i2c_trans.buf[0] << 16) |
|
||||
(ms->i2c_trans.buf[1] << 8) |
|
||||
ms->i2c_trans.buf[2];
|
||||
ms->i2c_trans.status = I2CTransDone;
|
||||
if (ms->data.d1 == 0) {
|
||||
/* if value is zero, it was read to soon and is invalid, back to idle */
|
||||
ms->status = MS5611_STATUS_IDLE;
|
||||
@@ -146,6 +147,7 @@ void ms5611_i2c_event(struct Ms5611_I2c *ms) {
|
||||
ms->data.d2 = (ms->i2c_trans.buf[0] << 16) |
|
||||
(ms->i2c_trans.buf[1] << 8) |
|
||||
ms->i2c_trans.buf[2];
|
||||
ms->i2c_trans.status = I2CTransDone;
|
||||
if (ms->data.d2 == 0) {
|
||||
/* if value is zero, it was read to soon and is invalid, back to idle */
|
||||
ms->status = MS5611_STATUS_IDLE;
|
||||
@@ -159,9 +161,9 @@ void ms5611_i2c_event(struct Ms5611_I2c *ms) {
|
||||
break;
|
||||
|
||||
default:
|
||||
ms->i2c_trans.status = I2CTransDone;
|
||||
break;
|
||||
}
|
||||
ms->i2c_trans.status = I2CTransDone;
|
||||
}
|
||||
}
|
||||
else if (ms->status != MS5611_STATUS_UNINIT) { // Configuring but not yet initialized
|
||||
@@ -178,6 +180,7 @@ void ms5611_i2c_event(struct Ms5611_I2c *ms) {
|
||||
/* read prom data */
|
||||
ms->data.c[ms->prom_cnt++] = (ms->i2c_trans.buf[0] << 8) |
|
||||
ms->i2c_trans.buf[1];
|
||||
ms->i2c_trans.status = I2CTransDone;
|
||||
if (ms->prom_cnt < PROM_NB) {
|
||||
/* get next prom data */
|
||||
ms->i2c_trans.buf[0] = MS5611_PROM_READ | (ms->prom_cnt << 1);
|
||||
@@ -195,10 +198,10 @@ void ms5611_i2c_event(struct Ms5611_I2c *ms) {
|
||||
}
|
||||
}
|
||||
}
|
||||
ms->i2c_trans.status = I2CTransDone;
|
||||
break;
|
||||
|
||||
default:
|
||||
ms->i2c_trans.status = I2CTransDone;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user