altos: Enable pyro channel control in telepyro
authorKeith Packard <keithp@keithp.com>
Mon, 16 Jul 2012 22:32:26 +0000 (15:32 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 16 Jul 2012 22:32:26 +0000 (15:32 -0700)
This should make the board actually work now.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/avr/ao_pins.h
src/core/ao_pyro.c
src/core/ao_pyro.h
src/drivers/ao_pyro_slave.c
src/product/ao_telepyro.c

index 3c9010a81cc90ddad86179ea1d8cc921947a913f..bc423ff7b61404011e17f4baf1eb9f3bcca3a778 100644 (file)
@@ -59,6 +59,8 @@
 
        #define SPI_SLAVE_PIN_0_3       1
        #define SPI_SLAVE_PIN_2_5       0
+
+       #define IS_COMPANION            1
 #endif
 
 #ifdef TELEPYRO
@@ -77,6 +79,7 @@
        #define DISABLE_HELP            1
        #define HAS_STORAGE_DEBUG       0
        #define IS_COMPANION            1
+       #define HAS_ORIENT              0
        #define ao_storage_pos_t        uint16_t
 
        #define AVR_VCC_5V              0
 
        #define SPI_SLAVE_PIN_0_3       1
        #define SPI_SLAVE_PIN_2_5       0
+
+       #define AO_PYRO_NUM             8
+
+       #define AO_PYRO_PORT_0  B
+       #define AO_PYRO_PIN_0   5
+
+       #define AO_PYRO_PORT_1  B
+       #define AO_PYRO_PIN_1   6
+
+       #define AO_PYRO_PORT_2  B
+       #define AO_PYRO_PIN_2   7
+
+       #define AO_PYRO_PORT_3  C
+       #define AO_PYRO_PIN_3   6
+
+       #define AO_PYRO_PORT_4  C
+       #define AO_PYRO_PIN_4   7
+
+       #define AO_PYRO_PORT_5  D
+       #define AO_PYRO_PIN_5   5
+
+       #define AO_PYRO_PORT_6  D
+       #define AO_PYRO_PIN_6   3
+
+       #define AO_PYRO_PORT_7  D
+       #define AO_PYRO_PIN_7   2
+
 #endif
 
 #define AO_M25_SPI_CS_PORT     SPI_CS_PORT
index a1377d21a2b8972b974624ce3a68629772b5ddb3..4f37e9793e6cbe0c37dc424119e93445adc8a89f 100644 (file)
 #include <ao_sample.h>
 #include <ao_flight.h>
 
+#if IS_COMPANION
+#include <ao_companion.h>
+#define ao_accel ao_companion_command.accel
+#define ao_speed ao_companion_command.speed
+#define ao_height ao_companion_command.height
+#define ao_flight_state ao_companion_command.flight_state
+#define ao_motor_number ao_companion_command.motor_number
+#endif
+
 #define ao_lowbit(x)   ((x) & (-x))
 
 /*
@@ -152,6 +161,8 @@ ao_pyro_fire(uint8_t p)
        ao_delay(AO_MS_TO_TICKS(50));
 }
 
+uint8_t        ao_pyro_wakeup;
+
 static void
 ao_pyro(void)
 {
@@ -163,7 +174,9 @@ ao_pyro(void)
                ao_sleep(&ao_flight_state);
 
        for (;;) {
-               ao_delay(AO_MS_TO_TICKS(100));
+               ao_alarm(AO_MS_TO_TICKS(100));
+               ao_sleep(&ao_pyro_wakeup);
+               ao_clear_alarm();
                for (p = 0; p < AO_PYRO_NUM; p++) {
                        pyro = &ao_config.pyro[p];
 
index 1989a9e55c28a74f27a97464f50fb7f0fadc0fb3..5deb69d0bf3eccafef80479f28d176c43be7f51b 100644 (file)
@@ -57,6 +57,8 @@ struct ao_pyro {
        uint8_t                 fired;
 };
 
+extern uint8_t ao_pyro_wakeup;
+
 void
 ao_pyro_set(void);
 
index 70206a00a994fca62b7551bb2439089a287ebe4e..f07c2cba184ddb47fdd67dfaac6bb53be13c4e38 100644 (file)
@@ -18,6 +18,8 @@
 #include <ao.h>
 #include <ao_product.h>
 #include <ao_companion.h>
+#include <ao_flight.h>
+#include <ao_pyro.h>
 
 struct ao_companion_command    ao_companion_command;
 
@@ -28,6 +30,11 @@ static const struct ao_companion_setup       ao_telepyro_setup = {
        .channels               = AO_TELEPYRO_NUM_ADC,
 };
 
+struct ao_config ao_config;
+
+extern volatile __data uint16_t ao_tick_count;
+uint16_t ao_boost_tick;
+
 void ao_spi_slave(void)
 {
        if (!ao_spi_slave_recv((uint8_t *) &ao_companion_command,
@@ -45,6 +52,10 @@ void ao_spi_slave(void)
                                  AO_TELEPYRO_NUM_ADC * sizeof (uint16_t));
                break;
        case AO_COMPANION_NOTIFY:
+               /* Can't use ao_time because we have interrupts suspended */
+               if (ao_companion_command.flight_state < ao_flight_boost && ao_companion_command.flight_state >= ao_flight_boost)
+                       ao_boost_tick = ao_tick_count;
+               ao_wakeup(&ao_pyro_wakeup);
                break;
        default:
                return;
index a2b8f83cad4a021a9264d61e654a14549c693797..79454fb7d75bcfa001549972db987af33bbea647 100644 (file)
@@ -31,6 +31,9 @@ main(void)
        ao_spi_slave_init();
        ao_usb_init();
        ao_adc_init();
+       ao_storage_init();
+       ao_config_init();
+       ao_pyro_init();
        ao_start_scheduler();
        return 0;
 }