altos: Create ao_data_fill shared function
authorKeith Packard <keithp@keithp.com>
Fri, 19 Oct 2018 15:12:22 +0000 (08:12 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 19 Oct 2018 15:37:56 +0000 (08:37 -0700)
This fills a data ring entry with all of the current sensor values
other than the ADC. It is used in all of the adc completion functions.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/kernel/ao_data.h
src/lpc/ao_adc_lpc.c
src/stm/ao_adc_stm.c
src/stmf0/ao_adc_stm.c

index f88b30c92666f001c26f3e3be21e11f5d4d22704..97f7e06e5669943c99266df66c63e497d2a4f6fd 100644 (file)
@@ -400,4 +400,32 @@ typedef int16_t ao_mag_t;          /* in raw sample units */
 
 #endif
 
+#ifdef AO_DATA_RING
+
+static inline void
+ao_data_fill(int head) {
+       if (ao_data_present == AO_DATA_ALL) {
+#if HAS_MS5607
+               ao_data_ring[head].ms5607_raw = ao_ms5607_current;
+#endif
+#if HAS_MMA655X
+               ao_data_ring[head].mma655x = ao_mma655x_current;
+#endif
+#if HAS_HMC5883
+               ao_data_ring[head].hmc5883 = ao_hmc5883_current;
+#endif
+#if HAS_MPU6000
+               ao_data_ring[head].mpu6000 = ao_mpu6000_current;
+#endif
+#if HAS_MPU9250
+               ao_data_ring[head].mpu9250 = ao_mpu9250_current;
+#endif
+               ao_data_ring[head].tick = ao_tick_count;
+               ao_data_head = ao_data_ring_next(head);
+               ao_wakeup((void *) &ao_data_head);
+       }
+}
+
+#endif
+
 #endif /* _AO_DATA_H_ */
index 6743c1f46ba0d292fc2983da96bde8ab9fe4a917..6324155977a7a4a538bf3cdbd051e274fae42a33 100644 (file)
@@ -112,23 +112,7 @@ void  lpc_adc_isr(void)
        }
 
        AO_DATA_PRESENT(AO_DATA_ADC);
-       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_data_fill(ao_data_head);
        ao_adc_ready = 1;
 }
 
index 2399e6a281bf7196f1e75474d89fb84d77b056c6..ffdcccc05adaf48bc1b885935238eec6d7c35517 100644 (file)
@@ -45,26 +45,7 @@ static void ao_adc_done(int index)
        (void) 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
-#if HAS_MPU9250
-               ao_data_ring[ao_data_head].mpu9250 = ao_mpu9250_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_data_fill(ao_data_head);
        ao_adc_ready = 1;
 }
 
index e62bb16e23be38ae4c53759cbc0fb0ab521990fe..d48726a1c66ad13761ce8b32ff8f1fadbb87f7a0 100644 (file)
@@ -38,23 +38,7 @@ static void ao_adc_done(int index)
 
        AO_DATA_PRESENT(AO_DATA_ADC);
        ao_dma_done_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC_1));
-       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_data_fill(ao_data_head);
        ao_adc_ready = 1;
 }