altos: Trigger sample complete when all data are ready
authorKeith Packard <keithp@keithp.com>
Sun, 26 Aug 2012 16:53:16 +0000 (09:53 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 26 Aug 2012 16:53:16 +0000 (09:53 -0700)
This has each sensor mark a bit in the current data record which is
then sent for processing when all of the data are present.

Signed-off-by: Keith Packard <keithp@keithp.com>
14 files changed:
src/core/ao_data.h
src/drivers/ao_hmc5883.c
src/drivers/ao_hmc5883.h
src/drivers/ao_mma655x.c
src/drivers/ao_mpu6000.c
src/drivers/ao_mpu6000.h
src/drivers/ao_ms5607.c
src/drivers/ao_ms5607.h
src/megametrum-v0.1/Makefile
src/megametrum-v0.1/ao_pins.h
src/megametrum-v0.1/stlink-pins
src/stm-demo/Makefile
src/stm/ao_adc_stm.c
src/stm/ao_timer.c

index fdc49ca202df0425eb56e75162f8adc86b13e037..3b66ef5d1a598e65e9369d6d7adcb33f10a08eee 100644 (file)
 #ifndef _AO_DATA_H_
 #define _AO_DATA_H_
 
+#if HAS_ADC
+#define AO_DATA_ADC    (1 << 0)
+#else
+#define AO_DATA_ADC    0
+#endif
+
 #if HAS_MS5607
 #include <ao_ms5607.h>
+#define AO_DATA_MS5607 (1 << 1)
+#else
+#define AO_DATA_MS5607 (1 << 1)
 #endif
 
 #if HAS_MPU6000
 #include <ao_mpu6000.h>
+#define AO_DATA_MPU6000        (1 << 2)
+#else
+#define AO_DATA_MPU6000        0
 #endif
 
 #if HAS_HMC5883
 #include <ao_hmc5883.h>
+#define AO_DATA_HMC5883        (1 << 3)
+#else
+#define AO_DATA_HMC5883        0
+#endif
+
+#if HAS_MMA655X
+#include <ao_mma655x.h>
+#define AO_DATA_MMA655X (1 << 4)
+#else
+#define AO_DATA_MMA655X 0
 #endif
 
+#define AO_DATA_ALL    (AO_DATA_ADC|AO_DATA_MS5607|AO_DATA_MPU6000|AO_DATA_HMC5883|AO_DATA_MMA655X)
+
 struct ao_data {
        uint16_t                        tick;
 #if HAS_ADC
@@ -45,6 +69,9 @@ struct ao_data {
 #if HAS_HMC5883
        struct ao_hmc5883_sample        hmc5883;
 #endif
+#if HAS_MMA655X
+       uint16_t                        mma655x;
+#endif
 };
 
 #define ao_data_ring_next(n)   (((n) + 1) & (AO_DATA_RING - 1))
@@ -52,6 +79,29 @@ struct ao_data {
 
 extern volatile __xdata struct ao_data ao_data_ring[AO_DATA_RING];
 extern volatile __data uint8_t         ao_data_head;
+extern volatile __data uint8_t         ao_data_present;
+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);
+
+/*
+ * Wait for data to be completed by looking at the
+ * indicated bit
+ */
+#define AO_DATA_WAIT() do {                            \
+               ao_sleep((void *) &ao_data_count);      \
+       } while (0)
+
 
 #if HAS_MS5607
 
index dbeb66b818905e4ac2c455744c4c71c8f3bd30bb..ade6c263d84236823d7d366cdb1c42b8b18348c8 100644 (file)
@@ -19,7 +19,7 @@
 #include <ao_hmc5883.h>
 #include <ao_exti.h>
 
-uint8_t        ao_hmc5883_valid;
+#if HAS_HMC5883
 
 static uint8_t ao_hmc5883_configured;
 
@@ -123,21 +123,16 @@ ao_hmc5883_setup(void)
        return 1;
 }
 
-struct ao_hmc5883_sample ao_hmc5883_current;
-
 static void
 ao_hmc5883(void)
 {
        ao_hmc5883_setup();
        for (;;) {
-               struct ao_hmc5883_sample ao_hmc5883_next;
-
-               ao_hmc5883_sample(&ao_hmc5883_next);
+               ao_hmc5883_sample((struct ao_hmc5883_sample *) &ao_data_ring[ao_data_head].hmc5883);
                ao_arch_critical(
-                       ao_hmc5883_current = ao_hmc5883_next;
-                       ao_hmc5883_valid = 1;
+                       AO_DATA_PRESENT(AO_DATA_HMC5883);
+                       AO_DATA_WAIT();
                        );
-               ao_delay(0);
        }
 }
 
@@ -146,11 +141,10 @@ static struct ao_task ao_hmc5883_task;
 static void
 ao_hmc5883_show(void)
 {
-       struct ao_hmc5883_sample        sample;
-
-       sample = ao_hmc5883_current;
+       struct ao_data  sample;
+       ao_data_get(&sample);
        printf ("X: %d Y: %d Z: %d missed irq: %lu\n",
-               sample.x, sample.y, sample.z, ao_hmc5883_missed_irq);
+               sample.hmc5883.x, sample.hmc5883.y, sample.hmc5883.z, ao_hmc5883_missed_irq);
 }
 
 static const struct ao_cmds ao_hmc5883_cmds[] = {
@@ -162,7 +156,6 @@ void
 ao_hmc5883_init(void)
 {
        ao_hmc5883_configured = 0;
-       ao_hmc5883_valid = 0;
 
        ao_enable_port(AO_HMC5883_INT_PORT);
        ao_exti_setup(AO_HMC5883_INT_PORT,
@@ -173,3 +166,5 @@ ao_hmc5883_init(void)
        ao_add_task(&ao_hmc5883_task, ao_hmc5883, "hmc5883");
        ao_cmd_register(&ao_hmc5883_cmds[0]);
 }
+
+#endif
index 8d726510911558ae4e6ec3b8883941f286bf0bfc..556909784040f9be4fd5979d793d189f5b1ec7ec 100644 (file)
 #define HMC5883_ID_B           11
 #define HMC5883_ID_C           12
 
-extern uint8_t ao_hmc5883_valid;
-
 struct ao_hmc5883_sample {
        int16_t         x, y, z;
 };
 
-extern struct ao_hmc5883_sample ao_hmc5883_current;
-
 void
 ao_hmc5883_init(void);
 
index e4e416270fb26f9b2bdf6113f53f73eb12f2343b..cd304d80affcf8cec7e7d289bedaacef33bec6fd 100644 (file)
@@ -18,8 +18,9 @@
 #include <ao.h>
 #include <ao_mma655x.h>
 
+#if HAS_MMA655X
+
 static uint8_t mma655x_configured;
-uint8_t                ao_mma655x_valid;
 
 static void
 ao_mma655x_start(void) {
@@ -197,14 +198,30 @@ __code struct ao_cmds ao_mma655x_cmds[] = {
        { 0, NULL },
 };
 
+static void
+ao_mma655x(void)
+{
+       ao_mma655x_setup();
+       for (;;) {
+               ao_data_ring[ao_data_head].mma655x = ao_mma655x_value();
+               ao_arch_critical(
+                       AO_DATA_PRESENT(AO_DATA_MMA655X);
+                       AO_DATA_WAIT();
+                       );
+       }
+}
+
+static __xdata struct ao_task ao_mma655x_task;
+
 void
 ao_mma655x_init(void)
 {
        mma655x_configured = 0;
-       ao_mma655x_valid = 0;
 
        ao_cmd_register(&ao_mma655x_cmds[0]);
        ao_spi_init_cs(AO_MMA655X_CS_GPIO, (1 << AO_MMA655X_CS));
 
-//     ao_add_task(&ao_mma655x_task, ao_mma655x, "mma655x");
+       ao_add_task(&ao_mma655x_task, ao_mma655x, "mma655x");
 }
+
+#endif
index a1c32d4d836db80808389009a8b38d0e6d2565ee..e8c80f12428943bf365977a03dbc9695656003ac 100644 (file)
@@ -240,22 +240,17 @@ ao_mpu6000_setup(void)
        ao_mpu6000_configured = 1;
 }
 
-struct ao_mpu6000_sample ao_mpu6000_current;
-uint8_t ao_mpu6000_valid;
-
 static void
 ao_mpu6000(void)
 {
        ao_mpu6000_setup();
        for (;;)
        {
-               struct ao_mpu6000_sample ao_mpu6000_next;
-               ao_mpu6000_sample(&ao_mpu6000_next);
+               ao_mpu6000_sample((struct ao_mpu6000_sample *) &ao_data_ring[ao_data_head].mpu6000);
                ao_arch_critical(
-                       ao_mpu6000_current = ao_mpu6000_next;
-                       ao_mpu6000_valid = 1;
+                       AO_DATA_PRESENT(AO_DATA_MPU6000);
+                       AO_DATA_WAIT();
                        );
-               ao_delay(0);
        }
 }
 
@@ -264,18 +259,16 @@ static struct ao_task ao_mpu6000_task;
 static void
 ao_mpu6000_show(void)
 {
-       struct ao_mpu6000_sample        sample;
+       struct ao_data  sample;
 
-       ao_arch_critical(
-               sample = ao_mpu6000_current;
-               );
+       ao_data_get(&sample);
        printf ("Accel: %7d %7d %7d Gyro: %7d %7d %7d\n",
-               sample.accel_x,
-               sample.accel_y,
-               sample.accel_z,
-               sample.gyro_x,
-               sample.gyro_y,
-               sample.gyro_z);
+               sample.mpu6000.accel_x,
+               sample.mpu6000.accel_y,
+               sample.mpu6000.accel_z,
+               sample.mpu6000.gyro_x,
+               sample.mpu6000.gyro_y,
+               sample.mpu6000.gyro_z);
 }
 
 static const struct ao_cmds ao_mpu6000_cmds[] = {
@@ -287,7 +280,6 @@ 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 fc7af1e0390c289c308a5c445175bdf04940e96b..ca76b08128ddc3888cb611f30a295b5f9cbdd6bc 100644 (file)
@@ -155,9 +155,6 @@ struct ao_mpu6000_sample {
        int16_t         gyro_z;
 };
 
-extern struct ao_mpu6000_sample ao_mpu6000_current;
-extern uint8_t ao_mpu6000_valid;
-
 void
 ao_mpu6000_init(void);
 
index 1b55b7fdeea61d4f99101425fb3f38aed1606a4c..ec0d2202216c3fcff64f06a950de37b47d5fd4d8 100644 (file)
@@ -19,6 +19,8 @@
 #include <ao_exti.h>
 #include "ao_ms5607.h"
 
+#if HAS_MS5607
+
 static struct ao_ms5607_prom   ms5607_prom;
 static uint8_t                 ms5607_configured;
 
@@ -201,22 +203,17 @@ ao_ms5607_convert(struct ao_ms5607_sample *sample, struct ao_ms5607_value *value
        value->temp = TEMP;
 }
 
-struct ao_ms5607_sample        ao_ms5607_current;
-uint8_t ao_ms5607_valid;
-
 static void
 ao_ms5607(void)
 {
        ao_ms5607_setup();
        for (;;)
        {
-               static struct ao_ms5607_sample  ao_ms5607_next;
-               ao_ms5607_sample(&ao_ms5607_next);
+               ao_ms5607_sample((struct ao_ms5607_sample *) &ao_data_ring[ao_data_head].ms5607_raw);
                ao_arch_critical(
-                       ao_ms5607_current = ao_ms5607_next;
-                       ao_ms5607_valid = 1;
+                       AO_DATA_PRESENT(AO_DATA_MS5607);
+                       AO_DATA_WAIT();
                        );
-               ao_delay(0);
        }
 }
 
@@ -238,13 +235,13 @@ ao_ms5607_info(void)
 static void
 ao_ms5607_dump(void)
 {
-       struct ao_ms5607_sample sample;
+       struct ao_data  sample;
        struct ao_ms5607_value value;
 
-       sample = ao_ms5607_current;
-       ao_ms5607_convert(&sample, &value);
-       printf ("Pressure:    %8u %8d\n", sample.pres, value.pres);
-       printf ("Temperature: %8u %8d\n", sample.temp, value.temp);
+       ao_data_get(&sample);
+       ao_ms5607_convert(&sample.ms5607_raw, &value);
+       printf ("Pressure:    %8u %8d\n", sample.ms5607_raw.pres, value.pres);
+       printf ("Temperature: %8u %8d\n", sample.ms5607_raw.temp, value.temp);
        printf ("Altitude: %ld\n", ao_pa_to_altitude(value.pres));
 }
 
@@ -257,7 +254,6 @@ 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));
 
@@ -279,3 +275,5 @@ ao_ms5607_init(void)
                      AO_MS5607_MISO,
                      STM_MODER_ALTERNATE);
 }
+
+#endif
index fa3b1c5b83df662386411e1a36d7439b2e7c29b9..e9c364d900917f7149289e43182b3e930e035cfa 100644 (file)
@@ -51,9 +51,6 @@ 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 {
        int32_t         pres;   /* in Pa * 10 */
        int32_t         temp;   /* in °C * 100 */
index 1dfebca0730cff328ae176daae27aa1a77241bee..a93f6f1742d856ad19a36718a1590a4f04007ab1 100644 (file)
@@ -56,8 +56,10 @@ ALTOS_SRC = \
        ao_cc1120.c \
        ao_fec_tx.c \
        ao_fec_rx.c \
+       ao_data.c \
        ao_ms5607.c \
        ao_mma655x.c \
+       ao_hmc5883.c \
        ao_adc_stm.c \
        ao_beep_stm.c \
        ao_storage.c \
index 6256d2f64a07f37790b7e75177ded24ecce7fa3a..8b631ae970dff80f19787919843a9c7d30fc5adb 100644 (file)
@@ -309,7 +309,7 @@ struct ao_adc {
  * mma655x
  */
 
-#define HAS_MMA655X            1
+#define HAS_MMA655X            0
 #define AO_MMA655X_SPI_INDEX   AO_SPI_1_PA5_PA6_PA7
 #define AO_MMA655X_CS_GPIO     (&stm_gpiod)
 #define AO_MMA655X_CS          4
index 71042acc841a3f28096d34dae12c11405de94af8..e6094372120676fd72573cb5eed91cde3031b86c 100644 (file)
@@ -34,6 +34,14 @@ GND  3       7
 JTMS   4       8
 NRST   5       2
 
+TL debug connector:
+
+       TL      ST
+GND    1       3
+NRST   2       5
+SWDIO  3       4
+SWCLK  4       2
+
 MegaAccel:
 
 Jumpers
index 340967fcc1c2390bf22d5af40a58e90586faddc2..09c9c3cabfe83b7c37445ed0dd6b3e160a01f719 100644 (file)
@@ -32,6 +32,7 @@ ALTOS_SRC = \
        ao_dma_stm.c \
        ao_spi_stm.c \
        ao_adc_stm.c \
+       ao_data.c \
        ao_i2c_stm.c \
        ao_usb_stm.c \
        ao_exti_stm.c \
index 7564c7fa9a0a810e466b0ce5418e0d27b800f53c..18ca6ea01885770a2cb18190f3ad20c2481becff 100644 (file)
 
 #include <ao.h>
 #include <ao_data.h>
-#if HAS_MPU6000
-#include <ao_mpu6000.h>
-#endif
-#if HAS_MS5607
-#include <ao_ms5607.h>
-#endif
-
-volatile __xdata struct ao_data        ao_data_ring[AO_DATA_RING];
-volatile __data uint8_t                ao_data_head;
 
 static uint8_t                 ao_adc_ready;
 
@@ -50,27 +41,7 @@ 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_raw = ao_ms5607_current;
-#endif 
-#if HAS_HMC5883
-       if (!ao_hmc5883_valid)
-               step = 0;
-       ao_data_ring[ao_data_head].hmc5883 = ao_hmc5883_current;
-#endif
-       if (step) {
-               ao_data_head = ao_data_ring_next(ao_data_head);
-               ao_wakeup((void *) &ao_data_head);
-       }
+       AO_DATA_PRESENT(AO_DATA_ADC);
        ao_dma_done_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1));
        ao_adc_ready = 1;
 }
@@ -117,17 +88,6 @@ ao_adc_get(__xdata struct ao_adc *packet)
        memcpy(packet, (void *) &ao_data_ring[i].adc, sizeof (struct ao_adc));
 }
 
-void
-ao_data_get(__xdata struct ao_data *packet)
-{
-#if HAS_FLIGHT
-       uint8_t i = ao_data_ring_prev(ao_sample_data);
-#else
-       uint8_t i = ao_data_ring_prev(ao_data_head);
-#endif
-       memcpy(packet, (void *) &ao_data_ring[i], sizeof (struct ao_data));
-}
-
 static void
 ao_adc_dump(void) __reentrant
 {
index adec7aad950f617fc3effe7055db3749167ebaa5..78228e65b72d10ad43df98e47694fc92c4b374bf 100644 (file)
@@ -37,9 +37,9 @@ ao_delay(uint16_t ticks)
        ao_sleep(&ao_forever);
 }
 
-#if HAS_ADC
-volatile __data uint8_t        ao_adc_interval = 1;
-volatile __data uint8_t        ao_adc_count;
+#if AO_DATA_ALL
+volatile __data uint8_t        ao_data_interval = 1;
+volatile __data uint8_t        ao_data_count;
 #endif
 
 void
@@ -51,10 +51,13 @@ void stm_tim6_isr(void)
        if (stm_tim6.sr & (1 << STM_TIM67_SR_UIF)) {
                stm_tim6.sr = 0;
                ++ao_tick_count;
-#if HAS_ADC
-               if (++ao_adc_count == ao_adc_interval) {
-                       ao_adc_count = 0;
+#if AO_DATA_ALL
+               if (++ao_data_count == ao_data_interval) {
+                       ao_data_count = 0;
                        ao_adc_poll();
+#if (AO_DATA_ALL & ~(AO_DATA_ADC))
+                       ao_wakeup((void *) &ao_data_count);
+#endif
                }
 #endif
        }
@@ -64,8 +67,8 @@ void stm_tim6_isr(void)
 void
 ao_timer_set_adc_interval(uint8_t interval) __critical
 {
-       ao_adc_interval = interval;
-       ao_adc_count = 0;
+       ao_data_interval = interval;
+       ao_data_count = 0;
 }
 #endif