altos: Ensure flight code gets first crack at new ADC data
authorKeith Packard <keithp@keithp.com>
Sat, 15 Jan 2011 20:12:02 +0000 (12:12 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 17 Jan 2011 04:24:34 +0000 (20:24 -0800)
Instead of having everyone wait on the raw ADC ring, have the flight
code wait on that and have everyone else wait for the flight code to
finish looking at the data and move its pointer forwards.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao.h
src/ao_adc.c
src/ao_config.c
src/ao_flight.c
src/ao_flight_test.c
src/ao_ignite.c
src/ao_log.c
src/ao_test.c

index 5721c34484c319f37f16c178aba1a6131b57298b..abac22a31e619322b644e49264022c52c3d63c40 100644 (file)
--- a/src/ao.h
+++ b/src/ao.h
@@ -649,7 +649,7 @@ enum ao_flight_state {
        ao_flight_invalid = 9
 };
 
-extern __xdata struct ao_adc           ao_flight_data;
+extern __data uint8_t                  ao_flight_adc;
 extern __pdata enum ao_flight_state    ao_flight_state;
 extern __pdata uint16_t                        ao_flight_tick;
 extern __pdata int16_t                 ao_flight_accel;
index 49d2519e209d5c4f2faf594c5afb08da9da42af6..f577b4582afe02ca838500b2d3d9e5e344612835 100644 (file)
@@ -27,16 +27,10 @@ ao_adc_poll(void)
        ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | 0;
 }
 
-void
-ao_adc_sleep(void)
-{
-       ao_sleep(&ao_adc_ring);
-}
-
 void
 ao_adc_get(__xdata struct ao_adc *packet)
 {
-       uint8_t i = ao_adc_ring_prev(ao_adc_head);
+       uint8_t i = ao_adc_ring_prev(ao_flight_adc);
        memcpy(packet, &ao_adc_ring[i], sizeof (struct ao_adc));
 }
 
@@ -65,7 +59,7 @@ ao_adc_isr(void) __interrupt 1
                /* record this conversion series */
                ao_adc_ring[ao_adc_head].tick = ao_time();
                ao_adc_head = ao_adc_ring_next(ao_adc_head);
-               ao_wakeup(ao_adc_ring);
+               ao_wakeup(DATA_TO_XDATA(&ao_adc_head));
        }
 }
 
index e97b7eb121192a41d1876fa530e9188d828e75e5..bbee3b443e6a0a7e17bfb9805af311dfba6e3982 100644 (file)
@@ -209,10 +209,10 @@ ao_config_accel_calibrate_auto(char *orientation) __reentrant
        puts("Calibrating..."); flush();
        i = ACCEL_CALIBRATE_SAMPLES;
        accel_total = 0;
-       cal_adc_ring = ao_adc_head;
+       cal_adc_ring = ao_flight_adc;
        while (i) {
-               ao_sleep(&ao_adc_ring);
-               while (i && cal_adc_ring != ao_adc_head) {
+               ao_sleep(DATA_TO_XDATA(&ao_flight_adc));
+               while (i && cal_adc_ring != ao_flight_adc) {
                        accel_total += (int32_t) ao_adc_ring[cal_adc_ring].accel;
                        cal_adc_ring = ao_adc_ring_next(cal_adc_ring);
                        i--;
index e99692a3f21d51df219e819c4413a4ce8db5423b..9eb9a0145ac54614afd519f89a88cd143061694a 100644 (file)
@@ -146,7 +146,8 @@ ao_flight(void)
        ao_raw_pres = 0;
        ao_flight_tick = 0;
        for (;;) {
-               ao_sleep(&ao_adc_ring);
+               ao_wakeup(DATA_TO_XDATA(&ao_flight_adc));
+               ao_sleep(DATA_TO_XDATA(&ao_adc_head));
                while (ao_flight_adc != ao_adc_head) {
                        __pdata uint8_t ticks;
                        __pdata int16_t ao_vel_change;
index 108d2c19fff5271beee64d45ef8a35542af6ec2e..5c61951853d63c84ddc6905be651b002a1e9a2d0 100644 (file)
@@ -180,7 +180,7 @@ void
 ao_sleep(void *wchan)
 {
        ao_dump_state();
-       if (wchan == &ao_adc_ring) {
+       if (wchan == &ao_adc_head) {
                char            type;
                uint16_t        tick;
                uint16_t        a, b;
index f2b15dd23e741da0d29df0682d7c02d830717890..603fcd25f3e37105487ad1005894cfdbabcc9815 100644 (file)
@@ -52,7 +52,6 @@ ao_igniter_status(enum ao_igniter igniter)
        __xdata uint8_t request, firing, fired;
 
        __critical {
-               ao_adc_sleep();
                ao_adc_get(&adc);
                request = ao_ignition[igniter].request;
                fired = ao_ignition[igniter].fired;
index fa0725502332fe10b884adff4090d37e6fb8ad6d..099c5f6ff9683aebf4a7048f2ed212e71578f60e 100644 (file)
@@ -99,10 +99,10 @@ ao_log(void)
        /* Write the whole contents of the ring to the log
         * when starting up.
         */
-       ao_log_adc_pos = ao_adc_ring_next(ao_adc_head);
+       ao_log_adc_pos = ao_adc_ring_next(ao_flight_adc);
        for (;;) {
                /* Write samples to EEPROM */
-               while (ao_log_adc_pos != ao_adc_head) {
+               while (ao_log_adc_pos != ao_flight_adc) {
                        log.type = AO_LOG_SENSOR;
                        log.tick = ao_adc_ring[ao_log_adc_pos].tick;
                        log.u.sensor.accel = ao_adc_ring[ao_log_adc_pos].accel;
index b9f7d33840dfe53ee724674df05485f457cda1c6..14c2eb75c41e2656996673a0cb29d4d4d4973c0f 100644 (file)
@@ -53,7 +53,7 @@ blink_1(void)
        static __xdata struct ao_adc adc;
 
        for (;;) {
-               ao_sleep(&ao_adc_ring);
+               ao_sleep(&ao_adc_head);
                ao_adc_get(&adc);
                if (adc.accel < 15900)
                        ao_led_on(AO_LED_RED);