altos: Make telescience reliably log only when told to
authorKeith Packard <keithp@keithp.com>
Tue, 24 May 2011 21:10:01 +0000 (15:10 -0600)
committerKeith Packard <keithp@keithp.com>
Tue, 24 May 2011 21:10:01 +0000 (15:10 -0600)
Use a pull-up on telescience and tri-state input on telemetrum at boot
time. Enable logging by pulling the TM output low and enabling as an
output, disable by pulling the TM output high and switching back to
input mode.

Also, ignore pin state changes for 5 seconds at boot to give things a
chance  to settle down.

Should work when both boards are powered up together.

Signed-off-by: Keith Packard <keithp@keithp.com>
src-avr/ao_log_telescience.c
src/ao_flight.c

index 04e494fdc39aacd8070ed4a5eaf9cd43f2dc05e3..ef5a1c97d3e03c386cea94968918e5f126c64028 100644 (file)
@@ -111,8 +111,6 @@ ao_log_check_pin(void)
 void
 ao_log_telescience(void)
 {
-       ao_log_check_pin();
-
        ao_storage_setup();
 
        /* Find end of data */
@@ -122,12 +120,21 @@ ao_log_telescience(void)
                if (!ao_log_valid(&log))
                        break;
        }
+
+       /*
+        * Wait for the other side to settle down
+        */
+       ao_delay(AO_SEC_TO_TICKS(5));
+
+       ao_log_check_pin();
+
        ao_log_current_pos = ao_log_start_pos;
        ao_log_end_pos = ao_storage_config;
        for (;;) {
                while (!ao_log_running)
                        ao_sleep(&ao_log_running);
 
+               flush();
                memset(&log, '\0', sizeof (struct ao_log_telescience));
                log.type = AO_LOG_TELESCIENCE_START;
                log.tick = ao_time();
@@ -149,12 +156,14 @@ ao_log_telescience(void)
                        /* Wait for more ADC data to arrive */
                        ao_sleep((void *) &ao_adc_head);
                }
+               flush();
        }
 }
 
 void
 ao_log_set(void)
 {
+       printf("Logging currently %s\n", ao_log_running ? "on" : "off");
        ao_cmd_hex();
        if (ao_cmd_status == ao_cmd_success) {
                if (ao_cmd_lex_i) {
@@ -165,6 +174,7 @@ ao_log_set(void)
                        ao_log_stop();
                }
        }
+       ao_cmd_status = ao_cmd_success;
 }
 
 void
@@ -174,7 +184,7 @@ ao_log_list(void)
        uint32_t        start = 0;
        uint8_t         flight = 0;
 
-       for (pos = 0; pos < ao_storage_config; pos += sizeof (struct ao_log_telescience)) {
+       for (pos = 0; ; pos += sizeof (struct ao_log_telescience)) {
                if (!ao_storage_read(pos, &log, sizeof (struct ao_log_telescience)))
                        break;
                if (!ao_log_valid(&log) || log.type == AO_LOG_TELESCIENCE_START) {
@@ -206,6 +216,7 @@ ao_log_delete(void)
                printf("No such flight: %d\n", ao_cmd_lex_i);
                return;
        }
+       ao_log_stop();
        for (pos = 0; pos < ao_storage_config; pos += ao_storage_block) {
                if (!ao_storage_read(pos, &log, sizeof (struct ao_log_telescience)))
                        break;
@@ -213,6 +224,7 @@ ao_log_delete(void)
                        break;
                ao_storage_erase(pos);
        }
+       ao_log_current_pos = ao_log_start_pos = 0;
        if (pos == 0)
                printf("No such flight: %d\n", ao_cmd_lex_i);
        else
@@ -236,12 +248,14 @@ ao_log_init(void)
 {
        ao_log_running = 0;
 
+       DDRB &= ~(1 << DDB0);
+
+       PORTB |= (1 << PORTB0);         /* Pull input up; require input to log */
+
        PCMSK0 |= (1 << PCINT0);        /* Enable PCINT0 pin change */
 
        PCICR |= (1 << PCIE0);          /* Enable pin change interrupt */
 
-       PORTB &= ~(1 << PORTB0);        /* Pull input down; always log if NC */
-
        ao_cmd_register(&ao_log_cmds[0]);
 
        ao_add_task(&ao_log_task, ao_log_telescience, "log");
index cfecc5af5d770509d1341a63ae958d4e92550891..822a20b81f04c777ffb26eee50ed49dcd640fb70 100644 (file)
@@ -168,8 +168,9 @@ ao_flight(void)
                                ao_wakeup(&ao_gps_data);
                                ao_wakeup(&ao_gps_tracking_data);
 #endif
-#ifdef ASCENT_PIN
-                               ASCENT_PIN = 0;
+#ifdef ASCENT_SIGNAL
+                               ASCENT_SIGNAL = 0;
+                               ASCENT_SIGNAL_DIR |= (1 << ASCENT_SIGNAL_PIN);
 #endif
 
                                ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
@@ -240,8 +241,9 @@ ao_flight(void)
                                /* Turn the RDF beacon back on */
                                ao_rdf_set(1);
 
-#ifdef ASCENT_PIN
-                               ASCENT_PIN = 1;
+#ifdef ASCENT_SIGNAL
+                               ASCENT_SIGNAL_DIR &= ~(1 << ASCENT_SIGNAL_PIN);
+                               ASCENT_SIGNAL = 0;
 #endif
                                /*
                                 * Start recording min/max height
@@ -320,9 +322,10 @@ void
 ao_flight_init(void)
 {
 #ifdef ASCENT_SIGNAL
-       ASCENT_SIGNAL = 1;
-       ASCENT_SIGNAL_DIR |= (1 << ASCENT_SIGNAL_PIN);
        ASCENT_SIGNAL_SEL &= ~(1 << ASCENT_SIGNAL_PIN);
+       ASCENT_SIGNAL_DIR &= ~(1 << ASCENT_SIGNAL_PIN);
+       P1INP |= (1 << ASCENT_SIGNAL_PIN);
+       ASCENT_SIGNAL = 1;
 #endif
        ao_flight_state = ao_flight_startup;
        ao_add_task(&flight_task, ao_flight, "flight");