#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
#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))
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
#include <ao_hmc5883.h>
#include <ao_exti.h>
-uint8_t ao_hmc5883_valid;
+#if HAS_HMC5883
static uint8_t ao_hmc5883_configured;
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);
}
}
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[] = {
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,
ao_add_task(&ao_hmc5883_task, ao_hmc5883, "hmc5883");
ao_cmd_register(&ao_hmc5883_cmds[0]);
}
+
+#endif
#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);
#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) {
{ 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
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);
}
}
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[] = {
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]);
int16_t gyro_z;
};
-extern struct ao_mpu6000_sample ao_mpu6000_current;
-extern uint8_t ao_mpu6000_valid;
-
void
ao_mpu6000_init(void);
#include <ao_exti.h>
#include "ao_ms5607.h"
+#if HAS_MS5607
+
static struct ao_ms5607_prom ms5607_prom;
static uint8_t ms5607_configured;
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);
}
}
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));
}
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));
AO_MS5607_MISO,
STM_MODER_ALTERNATE);
}
+
+#endif
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 */
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 \
* 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
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
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 \
#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;
*/
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;
}
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
{
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
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
}
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