diff options
author | Keith Packard <keithp@keithp.com> | 2017-06-11 22:31:17 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2017-06-11 22:54:22 -0700 |
commit | fed48732828c85ae56106cd72c5aeaaad47c552f (patch) | |
tree | 07154a8f5c925d70706ecda937d1daa73e4ff8b3 /src/drivers/ao_ms5607.c | |
parent | 171adbe7db8520f5ff52a5fe2c54fe165c6f91f8 (diff) |
altos: Update sensor data atomically
Read data into a temp variable, block interrupts, then update the
published value.
The bug is easy to see with the HMC5883 which has to byte-swap the
output of the chip, and hence can occasionally get caught with the
wrong byte order data.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/drivers/ao_ms5607.c')
-rw-r--r-- | src/drivers/ao_ms5607.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/drivers/ao_ms5607.c b/src/drivers/ao_ms5607.c index 0afdf012..914e0c1b 100644 --- a/src/drivers/ao_ms5607.c +++ b/src/drivers/ao_ms5607.c @@ -201,11 +201,13 @@ __xdata struct ao_ms5607_sample ao_ms5607_current; static void ao_ms5607(void) { + struct ao_ms5607_sample sample; ao_ms5607_setup(); for (;;) { - ao_ms5607_sample(&ao_ms5607_current); + ao_ms5607_sample(&sample); ao_arch_block_interrupts(); + ao_ms5607_current = sample; AO_DATA_PRESENT(AO_DATA_MS5607); AO_DATA_WAIT(); ao_arch_release_interrupts(); |