altos: Don't start ADC ring until the other sensors have a valid value
authorKeith Packard <keithp@keithp.com>
Sun, 27 May 2012 22:46:00 +0000 (16:46 -0600)
committerKeith Packard <keithp@keithp.com>
Sun, 27 May 2012 22:46:00 +0000 (16:46 -0600)
Yes, this is still an ugly kludge, but it's easy.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_mpu6000.c
src/drivers/ao_mpu6000.h
src/drivers/ao_ms5607.c
src/drivers/ao_ms5607.h
src/stm/ao_adc_stm.c

index df400fcb096fa1be1130ca67e71d04191a0bde4e..065ed2214e3d02dd5cb96cc2b6728c1a35676b32 100644 (file)
@@ -246,6 +246,7 @@ ao_mpu6000_setup(void)
 }
 
 struct ao_mpu6000_sample ao_mpu6000_current;
+uint8_t ao_mpu6000_valid;
 
 static void
 ao_mpu6000(void)
@@ -257,6 +258,7 @@ ao_mpu6000(void)
                ao_mpu6000_sample(&ao_mpu6000_next);
                ao_arch_critical(
                        ao_mpu6000_current = ao_mpu6000_next;
+                       ao_mpu6000_valid = 1;
                        );
                ao_delay(0);
        }
@@ -288,6 +290,7 @@ void
 ao_mpu6000_init(void)
 {
        ao_mpu6000_configured = 0;
+       ao_mpu6000_valid = 0;
 
        ao_add_task(&ao_mpu6000_task, ao_mpu6000, "mpu6000");
        ao_cmd_register(&ao_mpu6000_cmds[0]);
index 5e52148d396f6511a647374601d1ca9586335d68..fc7af1e0390c289c308a5c445175bdf04940e96b 100644 (file)
@@ -156,6 +156,7 @@ struct ao_mpu6000_sample {
 };
 
 extern struct ao_mpu6000_sample ao_mpu6000_current;
+extern uint8_t ao_mpu6000_valid;
 
 void
 ao_mpu6000_init(void);
index f79c315a2a683df13c01636dc979625fb4e64fbd..7db7022fda4f0965641f11001c739fe373aab989 100644 (file)
@@ -195,6 +195,7 @@ ao_ms5607_convert(struct ao_ms5607_sample *sample, struct ao_ms5607_value *value
 }
 
 struct ao_ms5607_sample        ao_ms5607_current;
+uint8_t ao_ms5607_valid;
 
 static void
 ao_ms5607(void)
@@ -206,6 +207,7 @@ ao_ms5607(void)
                ao_ms5607_sample(&ao_ms5607_next);
                ao_arch_critical(
                        ao_ms5607_current = ao_ms5607_next;
+                       ao_ms5607_valid = 1;
                        );
                ao_delay(0);
        }
@@ -244,6 +246,7 @@ void
 ao_ms5607_init(void)
 {
        ms5607_configured = 0;
+       ao_ms5607_valid = 0;
        ao_cmd_register(&ao_ms5607_cmds[0]);
        ao_spi_init_cs(AO_MS5607_CS_GPIO, (1 << AO_MS5607_CS));
 
index fd5bc984e9930b244fb80e90153daae007ca6541..1384d3a2ce6a026749769a485b1ec47bf9967fb2 100644 (file)
@@ -51,6 +51,7 @@ struct ao_ms5607_sample {
        uint32_t        temp;   /* raw 24 bit sensor */
 };
 
+extern uint8_t ao_ms5607_valid;
 extern struct ao_ms5607_sample ao_ms5607_current;
 
 struct ao_ms5607_value {
index 576dbf5d6c76b78c946575aa94f0c29f8d3d55ee..02187205eb18a82b4256c9669c33ee5cde2bb4ee 100644 (file)
@@ -50,15 +50,22 @@ static uint8_t                      ao_adc_ready;
  */
 static void ao_adc_done(int index)
 {
+       uint8_t step = 1;
        ao_data_ring[ao_data_head].tick = ao_time();
 #if HAS_MPU6000
+       if (!ao_mpu6000_valid)
+               step = 0;
        ao_data_ring[ao_data_head].mpu6000 = ao_mpu6000_current;
 #endif
 #if HAS_MS5607
+       if (!ao_ms5607_valid)
+               step = 0;
        ao_data_ring[ao_data_head].ms5607 = ao_ms5607_current;
 #endif 
-       ao_data_head = ao_data_ring_next(ao_data_head);
-       ao_wakeup((void *) &ao_data_head);
+       if (step) {
+               ao_data_head = ao_data_ring_next(ao_data_head);
+               ao_wakeup((void *) &ao_data_head);
+       }
        ao_dma_done_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1));
        ao_adc_ready = 1;
 }