summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2012-08-26 09:53:16 -0700
committerKeith Packard <keithp@keithp.com>2012-08-26 09:53:16 -0700
commitf89e7de20374141b367205aa517a08ee203bfaf3 (patch)
treeccda232f72dd067d88fd1b7e03196c24f943b494 /src
parentdec1481786ad54e22634e32109b5ed6e5483938e (diff)
altos: Trigger sample complete when all data are ready
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>
Diffstat (limited to 'src')
-rw-r--r--src/core/ao_data.h50
-rw-r--r--src/drivers/ao_hmc5883.c23
-rw-r--r--src/drivers/ao_hmc5883.h4
-rw-r--r--src/drivers/ao_mma655x.c23
-rw-r--r--src/drivers/ao_mpu6000.c30
-rw-r--r--src/drivers/ao_mpu6000.h3
-rw-r--r--src/drivers/ao_ms5607.c26
-rw-r--r--src/drivers/ao_ms5607.h3
-rw-r--r--src/megametrum-v0.1/Makefile2
-rw-r--r--src/megametrum-v0.1/ao_pins.h2
-rw-r--r--src/megametrum-v0.1/stlink-pins8
-rw-r--r--src/stm-demo/Makefile1
-rw-r--r--src/stm/ao_adc_stm.c42
-rw-r--r--src/stm/ao_timer.c19
14 files changed, 126 insertions, 110 deletions
diff --git a/src/core/ao_data.h b/src/core/ao_data.h
index fdc49ca2..3b66ef5d 100644
--- a/src/core/ao_data.h
+++ b/src/core/ao_data.h
@@ -18,18 +18,42 @@
#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
diff --git a/src/drivers/ao_hmc5883.c b/src/drivers/ao_hmc5883.c
index dbeb66b8..ade6c263 100644
--- a/src/drivers/ao_hmc5883.c
+++ b/src/drivers/ao_hmc5883.c
@@ -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
diff --git a/src/drivers/ao_hmc5883.h b/src/drivers/ao_hmc5883.h
index 8d726510..55690978 100644
--- a/src/drivers/ao_hmc5883.h
+++ b/src/drivers/ao_hmc5883.h
@@ -75,14 +75,10 @@
#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);
diff --git a/src/drivers/ao_mma655x.c b/src/drivers/ao_mma655x.c
index e4e41627..cd304d80 100644
--- a/src/drivers/ao_mma655x.c
+++ b/src/drivers/ao_mma655x.c
@@ -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
diff --git a/src/drivers/ao_mpu6000.c b/src/drivers/ao_mpu6000.c
index a1c32d4d..e8c80f12 100644
--- a/src/drivers/ao_mpu6000.c
+++ b/src/drivers/ao_mpu6000.c
@@ -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]);
diff --git a/src/drivers/ao_mpu6000.h b/src/drivers/ao_mpu6000.h
index fc7af1e0..ca76b081 100644
--- a/src/drivers/ao_mpu6000.h
+++ b/src/drivers/ao_mpu6000.h
@@ -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);
diff --git a/src/drivers/ao_ms5607.c b/src/drivers/ao_ms5607.c
index 1b55b7fd..ec0d2202 100644
--- a/src/drivers/ao_ms5607.c
+++ b/src/drivers/ao_ms5607.c
@@ -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
diff --git a/src/drivers/ao_ms5607.h b/src/drivers/ao_ms5607.h
index fa3b1c5b..e9c364d9 100644
--- a/src/drivers/ao_ms5607.h
+++ b/src/drivers/ao_ms5607.h
@@ -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 */
diff --git a/src/megametrum-v0.1/Makefile b/src/megametrum-v0.1/Makefile
index 1dfebca0..a93f6f17 100644
--- a/src/megametrum-v0.1/Makefile
+++ b/src/megametrum-v0.1/Makefile
@@ -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 \
diff --git a/src/megametrum-v0.1/ao_pins.h b/src/megametrum-v0.1/ao_pins.h
index 6256d2f6..8b631ae9 100644
--- a/src/megametrum-v0.1/ao_pins.h
+++ b/src/megametrum-v0.1/ao_pins.h
@@ -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
diff --git a/src/megametrum-v0.1/stlink-pins b/src/megametrum-v0.1/stlink-pins
index 71042acc..e6094372 100644
--- a/src/megametrum-v0.1/stlink-pins
+++ b/src/megametrum-v0.1/stlink-pins
@@ -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
diff --git a/src/stm-demo/Makefile b/src/stm-demo/Makefile
index 340967fc..09c9c3ca 100644
--- a/src/stm-demo/Makefile
+++ b/src/stm-demo/Makefile
@@ -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 \
diff --git a/src/stm/ao_adc_stm.c b/src/stm/ao_adc_stm.c
index 7564c7fa..18ca6ea0 100644
--- a/src/stm/ao_adc_stm.c
+++ b/src/stm/ao_adc_stm.c
@@ -17,15 +17,6 @@
#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
{
diff --git a/src/stm/ao_timer.c b/src/stm/ao_timer.c
index adec7aad..78228e65 100644
--- a/src/stm/ao_timer.c
+++ b/src/stm/ao_timer.c
@@ -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