altos: Go back to recording sensor data in globals mm-ms5611
authorKeith Packard <keithp@keithp.com>
Tue, 9 Oct 2012 06:04:16 +0000 (23:04 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 9 Oct 2012 06:04:16 +0000 (23:04 -0700)
Instead of trying to get things into the ring from a variety of
functions, go back to the simpler method of storing them in globals
and having the ADC code just pluck out the most recent values.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/core/ao_data.h
src/drivers/ao_hmc5883.c
src/drivers/ao_hmc5883.h
src/drivers/ao_mma655x.c
src/drivers/ao_mma655x.h
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 2b9ef5ace922e5f4e5c4809da63d5524a1cf7305..30208dfbdef780852b9df5646e88630ccf23532f 100644 (file)
@@ -85,14 +85,7 @@ extern volatile __data uint8_t               ao_data_count;
 /*
  * Mark a section of data as ready, check for data complete
  */
-#define AO_DATA_PRESENT(bit)   do {                                    \
-               if ((ao_data_present |= (bit)) == AO_DATA_ALL) {        \
-                       ao_data_ring[ao_data_head].tick = ao_tick_count; \
-                       ao_data_head = ao_data_ring_next(ao_data_head); \
-                       ao_data_present = 0;                            \
-                       ao_wakeup((void *) &ao_data_head);              \
-               }                                                       \
-       } while (0);
+#define AO_DATA_PRESENT(bit)   (ao_data_present |= (bit))
 
 /*
  * Wait until it is time to write a sensor sample; this is
index ade6c263d84236823d7d366cdb1c42b8b18348c8..059fc2c8d5fb85d75872d9325e34f341f50a5991 100644 (file)
@@ -123,12 +123,14 @@ ao_hmc5883_setup(void)
        return 1;
 }
 
+struct ao_hmc5883_sample ao_hmc5883_current;
+
 static void
 ao_hmc5883(void)
 {
        ao_hmc5883_setup();
        for (;;) {
-               ao_hmc5883_sample((struct ao_hmc5883_sample *) &ao_data_ring[ao_data_head].hmc5883);
+               ao_hmc5883_sample(&ao_hmc5883_current);
                ao_arch_critical(
                        AO_DATA_PRESENT(AO_DATA_HMC5883);
                        AO_DATA_WAIT();
index 556909784040f9be4fd5979d793d189f5b1ec7ec..ff2725ebdaa6820a10476452576fe25569b3e19b 100644 (file)
@@ -79,6 +79,8 @@ struct ao_hmc5883_sample {
        int16_t         x, y, z;
 };
 
+extern struct ao_hmc5883_sample        ao_hmc5883_current;
+
 void
 ao_hmc5883_init(void);
 
index 005bc68461bb27d8fa146e51aa6b05970937e8c4..18c5317ce8c89f6d4791062f2fec1b4d04940223 100644 (file)
@@ -250,12 +250,14 @@ __code struct ao_cmds ao_mma655x_cmds[] = {
        { 0, NULL },
 };
 
+uint16_t       ao_mma655x_current;
+
 static void
 ao_mma655x(void)
 {
        ao_mma655x_setup();
        for (;;) {
-               ao_data_ring[ao_data_head].mma655x = ao_mma655x_value();
+               ao_mma655x_current = ao_mma655x_value();
                ao_arch_critical(
                        AO_DATA_PRESENT(AO_DATA_MMA655X);
                        AO_DATA_WAIT();
index 9c0c59dc10d0933bb44a3f4f5d9ab44009c053d4..2d951e07a4a110b01b2cf87b8ebaa0e66c6c82ce 100644 (file)
@@ -78,6 +78,7 @@
 #define AO_MMA655X_COUNT       0x15
 #define AO_MMA655X_OFFCORR     0x16
 
+extern uint16_t        ao_mma655x_current;
 
 void
 ao_mma655x_init(void);
index b3e284e0bfb2988f0ff7e40e525c4a892a736704..495967057336ef8930263467cb3cbdfc15850e4f 100644 (file)
@@ -240,13 +240,15 @@ ao_mpu6000_setup(void)
        ao_mpu6000_configured = 1;
 }
 
+struct ao_mpu6000_sample       ao_mpu6000_current;
+
 static void
 ao_mpu6000(void)
 {
        ao_mpu6000_setup();
        for (;;)
        {
-               ao_mpu6000_sample((struct ao_mpu6000_sample *) &ao_data_ring[ao_data_head].mpu6000);
+               ao_mpu6000_sample(&ao_mpu6000_current);
                ao_arch_critical(
                        AO_DATA_PRESENT(AO_DATA_MPU6000);
                        AO_DATA_WAIT();
index ca76b08128ddc3888cb611f30a295b5f9cbdd6bc..ab36d6f27aeacf801aeec6fe943bfea5dc84ab70 100644 (file)
@@ -155,6 +155,8 @@ struct ao_mpu6000_sample {
        int16_t         gyro_z;
 };
 
+extern struct ao_mpu6000_sample        ao_mpu6000_current;
+
 void
 ao_mpu6000_init(void);
 
index 3295baac0348935256260bfc9e0781cb81b2335c..492199b8b4061d4d1d856f3f6b770d13efcbc1a5 100644 (file)
@@ -207,13 +207,15 @@ ao_ms5607_convert(struct ao_ms5607_sample *sample, struct ao_ms5607_value *value
        value->temp = TEMP;
 }
 
+struct ao_ms5607_sample        ao_ms5607_current;
+
 static void
 ao_ms5607(void)
 {
        ao_ms5607_setup();
        for (;;)
        {
-               ao_ms5607_sample((struct ao_ms5607_sample *) &ao_data_ring[ao_data_head].ms5607_raw);
+               ao_ms5607_sample(&ao_ms5607_current);
                ao_arch_critical(
                        AO_DATA_PRESENT(AO_DATA_MS5607);
                        AO_DATA_WAIT();
index e9c364d900917f7149289e43182b3e930e035cfa..4c29f6a7448facf7d4e44c333a60108af2474146 100644 (file)
@@ -56,6 +56,8 @@ struct ao_ms5607_value {
        int32_t         temp;   /* in °C * 100 */
 };
 
+extern struct ao_ms5607_sample ao_ms5607_current;
+
 void
 ao_ms5607_init(void);
 
index 18ca6ea01885770a2cb18190f3ad20c2481becff..48fc4262f7cb822f298168e7f55d5a9478c757b9 100644 (file)
@@ -43,6 +43,23 @@ static void ao_adc_done(int index)
 {
        AO_DATA_PRESENT(AO_DATA_ADC);
        ao_dma_done_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1));
+       if (ao_data_present == AO_DATA_ALL) {
+#if HAS_MS5607
+               ao_data_ring[ao_data_head].ms5607_raw = ao_ms5607_current;
+#endif
+#if HAS_MMA655X
+               ao_data_ring[ao_data_head].mma655x = ao_mma655x_current;
+#endif
+#if HAS_HMC5883
+               ao_data_ring[ao_data_head].hmc5883 = ao_hmc5883_current;
+#endif
+#if HAS_MPU6000
+               ao_data_ring[ao_data_head].mpu6000 = ao_mpu6000_current;
+#endif
+               ao_data_ring[ao_data_head].tick = ao_tick_count;
+               ao_data_head = ao_data_ring_next(ao_data_head);
+               ao_wakeup((void *) &ao_data_head);
+       }
        ao_adc_ready = 1;
 }