From 91785e03363f328b644f2c03b5438235f3a44c3e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 12 Aug 2011 21:34:37 -0700 Subject: altos-avr: Store TM tick and state in log, get logging on/off working To sync TM and TS data after flight, store the TM tick data in the log along with the TM state. This should provide sufficient data to synchronize the two data streams. Use the TM state to enable/disable logging, log from boost to landing and otherwise do not log. Signed-off-by: Keith Packard --- src-avr/ao_spi_slave.c | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'src-avr/ao_spi_slave.c') diff --git a/src-avr/ao_spi_slave.c b/src-avr/ao_spi_slave.c index 8e01f586..d44e4d0e 100644 --- a/src-avr/ao_spi_slave.c +++ b/src-avr/ao_spi_slave.c @@ -26,7 +26,7 @@ static const struct ao_companion_setup ao_companion_setup = { .channels = NUM_ADC }; -static void ao_spi_slave_recv(void) +static uint8_t ao_spi_slave_recv(void) { uint8_t *buf; uint8_t len; @@ -35,7 +35,8 @@ static void ao_spi_slave_recv(void) buf = (uint8_t *) &ao_companion_command; while (len--) { while (!(SPSR & (1 << SPIF))) - ; + if ((PINB & (1 << PINB0))) + return 0; *buf++ = SPDR; } @@ -49,17 +50,28 @@ static void ao_spi_slave_recv(void) buf = (uint8_t *) &ao_adc_ring[ao_adc_ring_prev(ao_adc_head)].adc; len = NUM_ADC * sizeof (uint16_t); break; + case AO_COMPANION_STATE: + break; default: - return; + return 0; } - /* Send the outbound data */ - while (len--) { - SPDR = *buf++; - while (!(SPSR & (1 << SPIF))) - ; + if (len) { + /* Send the outbound data */ + while (len--) { + SPDR = *buf++; + while (!(SPSR & (1 << SPIF))) + if ((PINB & (1 << PINB0))) + return 0; + } + (void) SPDR; } - (void) SPDR; + ao_log_store.tm_tick = ao_companion_command.tick; + if (ao_log_store.tm_state != ao_companion_command.flight_state) { + ao_log_store.tm_state = ao_companion_command.flight_state; + return 1; + } + return 0; } static uint8_t ao_spi_slave_running; @@ -67,16 +79,18 @@ static uint8_t ao_spi_slave_running; ISR(PCINT0_vect) { if ((PINB & (1 << PINB0)) == 0) { - if (!(PCMSK0 & (1 << PCINT1))) - PCMSK0 |= (1 << PCINT1); - else { - PCMSK0 &= ~(1 << PCINT1); + if (!ao_spi_slave_running) { + uint8_t changed; + ao_spi_slave_running = 1; cli(); - if (!ao_spi_slave_running) { - ao_spi_slave_running = 1; - ao_spi_slave_recv(); - } + changed = ao_spi_slave_recv(); sei(); + if (changed && ao_flight_boost <= ao_log_store.tm_state) { + if (ao_log_store.tm_state < ao_flight_landed) + ao_log_start(); + else + ao_log_stop(); + } } } else { ao_spi_slave_running = 0; -- cgit v1.2.3