From 97cecb517cd7bf75e1219c76a93bfe6964c07052 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 10 May 2009 22:57:19 -0700 Subject: [PATCH 01/16] Increase the initial accel/baro average to 1000 samples To get an accurate baseline of the launchpad state, take a longer average of the two sensors as the unit boots up. Signed-off-by: Keith Packard --- ao_flight.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ao_flight.c b/ao_flight.c index 06d4ba3d..43fd98b2 100644 --- a/ao_flight.c +++ b/ao_flight.c @@ -136,7 +136,7 @@ __xdata int32_t ao_raw_accel_sum, ao_raw_pres_sum; void ao_flight(void) { - __pdata static uint8_t nsamples = 0; + __pdata static uint16_t nsamples = 0; ao_flight_adc = ao_adc_head; ao_raw_accel_prev = 0; @@ -194,10 +194,10 @@ ao_flight(void) /* startup state: * - * Collect 100 samples of acceleration and pressure + * Collect 1000 samples of acceleration and pressure * data and average them to find the resting values */ - if (nsamples < 100) { + if (nsamples < 1000) { ao_raw_accel_sum += ao_raw_accel; ao_raw_pres_sum += ao_raw_pres; ++nsamples; -- 2.30.2 From e9584e846b9bd7926d61451d32ba5d7a30416f7b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 10 May 2009 22:58:31 -0700 Subject: [PATCH 02/16] Decrease telemetry rate on the pad to 1/sec instead of 20/sec Transmitting telemetry through the radio consumes a significant amount of battery; reducing the rate to 1/sec will reduce power usage while waiting for launch. Signed-off-by: Keith Packard --- ao.h | 1 + ao_flight.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ao.h b/ao.h index 4505edfa..fb06df06 100644 --- a/ao.h +++ b/ao.h @@ -727,6 +727,7 @@ struct ao_telemetry { /* Set delay between telemetry reports (0 to disable) */ +#define AO_TELEMETRY_INTERVAL_PAD AO_MS_TO_TICKS(1000) #define AO_TELEMETRY_INTERVAL_FLIGHT AO_MS_TO_TICKS(50) #define AO_TELEMETRY_INTERVAL_RECOVER AO_MS_TO_TICKS(1000) diff --git a/ao_flight.c b/ao_flight.c index 43fd98b2..f4b5279b 100644 --- a/ao_flight.c +++ b/ao_flight.c @@ -223,7 +223,7 @@ ao_flight(void) /* Turn on telemetry system */ ao_rdf_set(1); - ao_telemetry_set_interval(AO_TELEMETRY_INTERVAL_FLIGHT); + ao_telemetry_set_interval(AO_TELEMETRY_INTERVAL_PAD); ao_flight_state = ao_flight_launchpad; ao_wakeup(DATA_TO_XDATA(&ao_flight_state)); @@ -259,6 +259,9 @@ ao_flight(void) /* start logging data */ ao_log_start(); + /* Increase telemetry rate */ + ao_telemetry_set_interval(AO_TELEMETRY_INTERVAL_FLIGHT); + /* disable RDF beacon */ ao_rdf_set(0); -- 2.30.2 From b623b1098bc7a10d471730259438fb82804221d0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 10 May 2009 23:00:06 -0700 Subject: [PATCH 03/16] Initialize ao_min_vel with |ao_flight_vel| As ao_min_vel is stored as an absolute value, it's important to preserve that invariant, even though we don't expect ao_flight_vel to be negative at coast. Signed-off-by: Keith Packard --- ao_flight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ao_flight.c b/ao_flight.c index f4b5279b..91953975 100644 --- a/ao_flight.c +++ b/ao_flight.c @@ -312,7 +312,7 @@ ao_flight(void) /* set min velocity to current velocity for * apogee detect */ - ao_min_vel = ao_flight_vel; + ao_min_vel = abs(ao_flight_vel); ao_flight_state = ao_flight_apogee; ao_wakeup(DATA_TO_XDATA(&ao_flight_state)); } -- 2.30.2 From ba3c53636e485450f48093d0a88a6629775f7c3a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 10 May 2009 23:01:16 -0700 Subject: [PATCH 04/16] Don't re-initialize the landing range data at each apogee detect sample The landing range values are used only after apogee detect, so we need only initialize them on the transition from apogee to drogue. Signed-off-by: Keith Packard --- ao_flight.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/ao_flight.c b/ao_flight.c index 91953975..3bc6b974 100644 --- a/ao_flight.c +++ b/ao_flight.c @@ -347,26 +347,28 @@ ao_flight(void) /* Enable RDF beacon */ ao_rdf_set(1); + /* + * Start recording min/max accel and pres for a while + * to figure out when the rocket has landed + */ + /* Set the 'last' limits to max range to prevent + * early resting detection + */ + ao_interval_min_accel = 0; + ao_interval_max_accel = 0x7fff; + ao_interval_min_pres = 0; + ao_interval_max_pres = 0x7fff; + + /* initialize interval values */ + ao_interval_end = ao_flight_tick + AO_INTERVAL_TICKS; + + ao_interval_cur_min_pres = ao_interval_cur_max_pres = ao_flight_pres; + ao_interval_cur_min_accel = ao_interval_cur_max_accel = ao_flight_accel; + + /* and enter drogue state */ ao_flight_state = ao_flight_drogue; ao_wakeup(DATA_TO_XDATA(&ao_flight_state)); } - /* - * Start recording min/max accel and pres for a while - * to figure out when the rocket has landed - */ - /* Set the 'last' limits to max range to prevent - * early resting detection - */ - ao_interval_min_accel = 0; - ao_interval_max_accel = 0x7fff; - ao_interval_min_pres = 0; - ao_interval_max_pres = 0x7fff; - - /* initialize interval values */ - ao_interval_end = ao_flight_tick + AO_INTERVAL_TICKS; - - ao_interval_cur_min_pres = ao_interval_cur_max_pres = ao_flight_pres; - ao_interval_cur_min_accel = ao_interval_cur_max_accel = ao_flight_accel; break; case ao_flight_drogue: -- 2.30.2 From 497c89a7d08920630894b2605c3b6a0bdc4c229b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 10 May 2009 23:11:06 -0700 Subject: [PATCH 05/16] Use recorded accelerometer baseline data in ao_flight_test With the flight computer recording a long-term average value for the accelerometer in the flight record, use that to prime the flight test code when running a log file through the simulator. Signed-off-by: Keith Packard --- ao_flight_test.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ao_flight_test.c b/ao_flight_test.c index dea7b31c..e9c6a530 100644 --- a/ao_flight_test.c +++ b/ao_flight_test.c @@ -163,6 +163,8 @@ ao_insert(void) } static int ao_records_read = 0; +static int ao_eof_read = 0; +static int ao_flight_ground_accel; void ao_sleep(void *wchan) @@ -177,20 +179,26 @@ ao_sleep(void *wchan) for (;;) { if (ao_records_read > 20 && ao_flight_state == ao_flight_startup) { + ao_adc_static.accel = ao_flight_ground_accel; ao_insert(); return; } ret = fscanf(emulator_in, "%c %hx %hx %hx\n", &type, &tick, &a, &b); if (ret == EOF) { - printf ("no more data, exiting simulation\n"); - exit(0); + if (++ao_eof_read >= 1000) { + printf ("no more data, exiting simulation\n"); + exit(0); + } + ao_adc_static.tick += 10; + ao_insert(); return; } if (ret != 4) continue; switch (type) { case 'F': + ao_flight_ground_accel = a; break; case 'S': break; -- 2.30.2 From 7a1aa3fdbc0d1fae5e7ee027bf8904598c6ebe41 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 13 May 2009 10:58:30 -0700 Subject: [PATCH 06/16] Typo in callsign --- ao_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ao_config.c b/ao_config.c index 02f1e082..657c7a8a 100644 --- a/ao_config.c +++ b/ao_config.c @@ -24,7 +24,7 @@ __xdata uint8_t ao_config_mutex; #define AO_CONFIG_DEFAULT_MAIN_DEPLOY 250 #define AO_CONFIG_DEFAULT_RADIO_CHANNEL 0 -#define AO_CONFIG_DEFAULT_CALLSIGN "KD7SGQ" +#define AO_CONFIG_DEFAULT_CALLSIGN "KD7SQG" #define AO_CONFIG_DEFAULT_ACCEL_ZERO_G 16000 static void -- 2.30.2 From 24fdda44ff8604e40510b196ead17564d8f8cd3d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 13 May 2009 10:59:04 -0700 Subject: [PATCH 07/16] Add velocity check for boost detect via accelerometer Bumping the rocket can cause a brief period of high acceleration, which may cause a mistaken boost detection. Require both a high acceleration and reasonable velocity to trigger boost phase. Signed-off-by: Keith Packard --- ao_flight.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ao_flight.c b/ao_flight.c index 3bc6b974..d50d37e3 100644 --- a/ao_flight.c +++ b/ao_flight.c @@ -83,6 +83,7 @@ __pdata int16_t ao_raw_accel, ao_raw_accel_prev, ao_raw_pres; #define ACCEL_VEL_MACH VEL_MPS_TO_COUNT(200) #define ACCEL_VEL_APOGEE VEL_MPS_TO_COUNT(2) #define ACCEL_VEL_MAIN VEL_MPS_TO_COUNT(100) +#define ACCEL_VEL_BOOST VEL_MPS_TO_COUNT(5) /* * Barometer calibration @@ -242,7 +243,7 @@ ao_flight(void) /* pad to boost: * - * accelerometer: > 2g + * accelerometer: > 2g AND velocity > 5m/s * OR * barometer: > 20m vertical motion * @@ -250,7 +251,8 @@ ao_flight(void) * the barometer, but we use both to make sure this * transition is detected */ - if (ao_flight_accel < ao_ground_accel - ACCEL_BOOST || + if ((ao_flight_accel < ao_ground_accel - ACCEL_BOOST && + ao_flight_vel > ACCEL_VEL_BOOST) || ao_flight_pres < ao_ground_pres - BARO_LAUNCH) { ao_flight_state = ao_flight_boost; -- 2.30.2 From 8168820b667cc1deffab64dd81cb4e6e2e6eabe4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 13 May 2009 11:00:43 -0700 Subject: [PATCH 08/16] Accelerometer-based velocity values are invalid after apogee Because the orientation of the flight computer relative to the ground is unknown after apogee, the accelerometer data cannot be integrated to compute velocity. Main deploy is now based purely on barometric altitude and landing detection no longer checks for a low velocity value. Signed-off-by: Keith Packard --- ao_flight.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/ao_flight.c b/ao_flight.c index d50d37e3..0b47bfa5 100644 --- a/ao_flight.c +++ b/ao_flight.c @@ -377,13 +377,17 @@ ao_flight(void) /* drogue to main deploy: * - * accelerometer: abs(velocity) > 100m/s (in case the drogue failed) - * OR * barometer: reach main deploy altitude + * + * Would like to use the accelerometer for this test, but + * the orientation of the flight computer is unknown after + * drogue deploy, so we ignore it. Could also detect + * high descent rate using the pressure sensor to + * recognize drogue deploy failure and eject the main + * at that point. Perhaps also use the drogue sense lines + * to notice continutity? */ - if (ao_flight_vel < -ACCEL_VEL_MAIN || - ao_flight_vel > ACCEL_VEL_MAIN || - ao_flight_pres >= ao_main_pres) + if (ao_flight_pres >= ao_main_pres) { ao_ignite(ao_igniter_main); ao_flight_state = ao_flight_main; @@ -395,8 +399,8 @@ ao_flight(void) /* drogue/main to land: * - * accelerometer: value stable and velocity less than 10m/s - * OR + * accelerometer: value stable + * AND * barometer: altitude stable and within 1000m of the launch altitude */ @@ -419,10 +423,9 @@ ao_flight(void) ao_interval_cur_min_accel = ao_interval_cur_max_accel = ao_flight_accel; } - if ((abs(ao_flight_vel) < ACCEL_VEL_LAND && - (uint16_t) (ao_interval_max_accel - ao_interval_min_accel) < (uint16_t) ACCEL_INT_LAND) || - (ao_flight_pres > ao_ground_pres - BARO_LAND && - (uint16_t) (ao_interval_max_pres - ao_interval_min_pres) < (uint16_t) BARO_INT_LAND)) + if ((uint16_t) (ao_interval_max_accel - ao_interval_min_accel) < (uint16_t) ACCEL_INT_LAND && + ao_flight_pres > ao_ground_pres - BARO_LAND && + (uint16_t) (ao_interval_max_pres - ao_interval_min_pres) < (uint16_t) BARO_INT_LAND) { ao_flight_state = ao_flight_landed; -- 2.30.2 From d3dbd8949e1102220ad5fd0863f493c819b96e46 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 13 May 2009 11:16:53 -0700 Subject: [PATCH 09/16] Print only RSSI when packet CRC is invalid Packets with invalid CRC usually contain bogus data, so don't print that, just print out the RSSI which may contain useful data. Signed-off-by: Keith Packard --- ao_monitor.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/ao_monitor.c b/ao_monitor.c index 17eee5a3..e05e84d8 100644 --- a/ao_monitor.c +++ b/ao_monitor.c @@ -40,22 +40,24 @@ ao_monitor(void) memcpy(callsign, recv.telemetry.callsign, AO_MAX_CALLSIGN); if (state > ao_flight_invalid) state = ao_flight_invalid; - printf ("CALL %s SERIAL %3d RSSI %3d STATUS %02x STATE %7s ", - callsign, - recv.telemetry.addr, - (int) recv.rssi - 74, recv.status, - ao_state_names[state]); - if (!(recv.status & PKT_APPEND_STATUS_1_CRC_OK)) - printf("CRC INVALID "); - printf("%5u a: %5d p: %5d t: %5d v: %5d d: %5d m: %5d ", - recv.telemetry.adc.tick, - recv.telemetry.adc.accel, - recv.telemetry.adc.pres, - recv.telemetry.adc.temp, - recv.telemetry.adc.v_batt, - recv.telemetry.adc.sense_d, - recv.telemetry.adc.sense_m); - ao_gps_print(&recv.telemetry.gps); + if (recv.status & PKT_APPEND_STATUS_1_CRC_OK) { + printf ("CALL %s SERIAL %3d RSSI %3d STATUS %02x STATE %7s ", + callsign, + recv.telemetry.addr, + (int) recv.rssi - 74, recv.status, + ao_state_names[state]); + printf("%5u a: %5d p: %5d t: %5d v: %5d d: %5d m: %5d ", + recv.telemetry.adc.tick, + recv.telemetry.adc.accel, + recv.telemetry.adc.pres, + recv.telemetry.adc.temp, + recv.telemetry.adc.v_batt, + recv.telemetry.adc.sense_d, + recv.telemetry.adc.sense_m); + ao_gps_print(&recv.telemetry.gps); + } else { + printf("CRC INVALID RSSI %3d\n", (int) recv.rssi - 74); + } ao_usb_flush(); ao_led_toggle(ao_monitor_led); } -- 2.30.2 From d91208fbf5fc7797b93087ef8619454c4bed0130 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 13 May 2009 11:18:24 -0700 Subject: [PATCH 10/16] Make ao_flight_test able to read raw logging data Protect ao_flight_test reading functions so that a simple 'script' output can be fed to the program and have it work correctly. Signed-off-by: Keith Packard --- ao_flight_test.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ao_flight_test.c b/ao_flight_test.c index e9c6a530..a94fc740 100644 --- a/ao_flight_test.c +++ b/ao_flight_test.c @@ -165,6 +165,7 @@ ao_insert(void) static int ao_records_read = 0; static int ao_eof_read = 0; static int ao_flight_ground_accel; +static int ao_flight_started = 0; void ao_sleep(void *wchan) @@ -175,6 +176,7 @@ ao_sleep(void *wchan) uint16_t tick; uint16_t a, b; int ret; + char line[1024]; for (;;) { if (ao_records_read > 20 && ao_flight_state == ao_flight_startup) @@ -184,8 +186,7 @@ ao_sleep(void *wchan) return; } - ret = fscanf(emulator_in, "%c %hx %hx %hx\n", &type, &tick, &a, &b); - if (ret == EOF) { + if (!fgets(line, sizeof (line), emulator_in)) { if (++ao_eof_read >= 1000) { printf ("no more data, exiting simulation\n"); exit(0); @@ -194,11 +195,16 @@ ao_sleep(void *wchan) ao_insert(); return; } + ret = sscanf(line, "%c %hx %hx %hx", &type, &tick, &a, &b); if (ret != 4) continue; + if (type != 'F' && !ao_flight_started) + continue; + switch (type) { case 'F': ao_flight_ground_accel = a; + ao_flight_started = 1; break; case 'S': break; -- 2.30.2 From 055331d5f7d5adc40c348c3efd331a562dcda82a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 13 May 2009 11:19:13 -0700 Subject: [PATCH 11/16] Make ao_flight_test show AGL altitude and positive acceleration under boost This makes the output more readable Signed-off-by: Keith Packard --- ao_flight_test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ao_flight_test.c b/ao_flight_test.c index a94fc740..0b03eb1f 100644 --- a/ao_flight_test.c +++ b/ao_flight_test.c @@ -240,10 +240,10 @@ ao_dump_state(void) return; printf ("\t\t\t\t\t%s accel %g vel %g alt %d main %d\n", ao_state_names[ao_flight_state], - (ao_flight_accel - ao_ground_accel) / COUNTS_PER_G * GRAVITY, + (ao_ground_accel - ao_flight_accel) / COUNTS_PER_G * GRAVITY, (double) ao_flight_vel / 100 / COUNTS_PER_G * GRAVITY, - ao_pres_to_altitude(ao_flight_pres), - ao_pres_to_altitude(ao_main_pres)); + ao_pres_to_altitude(ao_flight_pres) - ao_pres_to_altitude(ao_ground_pres), + ao_pres_to_altitude(ao_main_pres) - ao_pres_to_altitude(ao_ground_pres)); if (ao_flight_state == ao_flight_landed) exit(0); } -- 2.30.2 From d085d43701e3cdd2119e947a9ae45baa78c80318 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 13 May 2009 14:29:30 -0700 Subject: [PATCH 12/16] Indicate RSSI with a blinking LED Blink the red LED at a rate proportional to the RSSI value. Signed-off-by: Keith Packard --- Makefile | 3 ++- ao.h | 12 ++++++++++- ao_monitor.c | 1 + ao_rssi.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ ao_teledongle.c | 1 + ao_telemetrum.c | 1 + ao_teleterra.c | 1 + ao_tidongle.c | 1 + 8 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 ao_rssi.c diff --git a/Makefile b/Makefile index ab72b413..d574c67c 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,8 @@ TELE_COMMON_SRC = \ # Receiver code # TELE_RECEIVER_SRC =\ - ao_monitor.c + ao_monitor.c \ + ao_rssi.c # # Shared Tele drivers (on TeleMetrum, TeleTerra, TeleDongle) diff --git a/ao.h b/ao.h index fb06df06..96dd02d0 100644 --- a/ao.h +++ b/ao.h @@ -44,7 +44,7 @@ struct ao_task { extern __xdata struct ao_task *__data ao_cur_task; -#define AO_NUM_TASKS 10 /* maximum number of tasks */ +#define AO_NUM_TASKS 16 /* maximum number of tasks */ #define AO_NO_TASK 0 /* no task id */ /* @@ -833,6 +833,16 @@ ao_config_get(void); void ao_config_init(void); +/* + * ao_rssi.c + */ + +void +ao_rssi_set(int rssi_value); + +void +ao_rssi_init(uint8_t rssi_led); + /* * ao_product.c * diff --git a/ao_monitor.c b/ao_monitor.c index e05e84d8..5930afaa 100644 --- a/ao_monitor.c +++ b/ao_monitor.c @@ -55,6 +55,7 @@ ao_monitor(void) recv.telemetry.adc.sense_d, recv.telemetry.adc.sense_m); ao_gps_print(&recv.telemetry.gps); + ao_rssi_set((int) recv.rssi - 74); } else { printf("CRC INVALID RSSI %3d\n", (int) recv.rssi - 74); } diff --git a/ao_rssi.c b/ao_rssi.c new file mode 100644 index 00000000..6912b9a2 --- /dev/null +++ b/ao_rssi.c @@ -0,0 +1,53 @@ +/* + * Copyright © 2009 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include "ao.h" + +static __xdata volatile uint16_t ao_rssi_time; +static __xdata volatile uint16_t ao_rssi_delay; +static __xdata uint8_t ao_rssi_led; + +void +ao_rssi(void) +{ + for (;;) { + while ((int16_t) (ao_time() - ao_rssi_time) > AO_SEC_TO_TICKS(3)) + ao_sleep(&ao_rssi_time); + ao_led_for(ao_rssi_led, AO_MS_TO_TICKS(100)); + ao_delay(ao_rssi_delay); + } +} + +void +ao_rssi_set(int rssi_value) +{ + if (rssi_value > 0) + rssi_value = 0; + ao_rssi_delay = AO_MS_TO_TICKS((-rssi_value) * 5); + ao_rssi_time = ao_time(); + ao_wakeup(&ao_rssi_time); +} + +__xdata struct ao_task ao_rssi_task; + +void +ao_rssi_init(uint8_t rssi_led) +{ + ao_rssi_led = rssi_led; + ao_rssi_delay = 0; + ao_add_task(&ao_rssi_task, ao_rssi, "rssi"); +} diff --git a/ao_teledongle.c b/ao_teledongle.c index af14472b..98163109 100644 --- a/ao_teledongle.c +++ b/ao_teledongle.c @@ -33,6 +33,7 @@ main(void) ao_cmd_init(); ao_usb_init(); ao_monitor_init(AO_LED_GREEN); + ao_rssi_init(AO_LED_RED); ao_radio_init(); ao_dbg_init(); ao_config_init(); diff --git a/ao_telemetrum.c b/ao_telemetrum.c index d5d01f16..097b15d7 100644 --- a/ao_telemetrum.c +++ b/ao_telemetrum.c @@ -43,6 +43,7 @@ main(void) ao_telemetry_init(); ao_radio_init(); ao_monitor_init(AO_LED_GREEN); + ao_rssi_init(AO_LED_RED); ao_igniter_init(); ao_dbg_init(); ao_config_init(); diff --git a/ao_teleterra.c b/ao_teleterra.c index b5ab4857..ed72cd4b 100644 --- a/ao_teleterra.c +++ b/ao_teleterra.c @@ -35,6 +35,7 @@ main(void) ao_serial_init(); ao_gps_init(); ao_monitor_init(AO_LED_GREEN); + ao_monitor_init(AO_LED_RED); ao_radio_init(); ao_dbg_init(); ao_config_init(); diff --git a/ao_tidongle.c b/ao_tidongle.c index c8e165c2..4d9a77f7 100644 --- a/ao_tidongle.c +++ b/ao_tidongle.c @@ -33,6 +33,7 @@ main(void) ao_cmd_init(); ao_usb_init(); ao_monitor_init(AO_LED_RED); + ao_rssi_init(AO_LED_RED); ao_radio_init(); ao_dbg_init(); ao_config_init(); -- 2.30.2 From 05493b98eb1ae4d30cb0b600849d70b03fa33594 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 13 May 2009 20:38:11 -0700 Subject: [PATCH 13/16] Split out ao_state_names to separate file Allows state names to be used in programs without monitoring enabled. Signed-off-by: Keith Packard --- Makefile | 3 ++- ao_monitor.c | 5 ----- ao_state.c | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 ao_state.c diff --git a/Makefile b/Makefile index d574c67c..6fda8965 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,8 @@ ALTOS_DRIVER_SRC = \ ao_usb.c TELE_COMMON_SRC = \ - ao_gps_print.c + ao_gps_print.c \ + ao_state.c # # Receiver code diff --git a/ao_monitor.c b/ao_monitor.c index 5930afaa..2f6584bc 100644 --- a/ao_monitor.c +++ b/ao_monitor.c @@ -17,11 +17,6 @@ #include "ao.h" -const char const * const ao_state_names[] = { - "startup", "idle", "pad", "boost", "coast", - "apogee", "drogue", "main", "landed", "invalid" -}; - __xdata uint8_t ao_monitoring; __pdata uint8_t ao_monitor_led; diff --git a/ao_state.c b/ao_state.c new file mode 100644 index 00000000..96b4c1a4 --- /dev/null +++ b/ao_state.c @@ -0,0 +1,23 @@ +/* + * Copyright © 2009 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include "ao.h" + +const char const * const ao_state_names[] = { + "startup", "idle", "pad", "boost", "coast", + "apogee", "drogue", "main", "landed", "invalid" +}; -- 2.30.2 From 25fc03a333b2cfad0a93ebc385fbcf74b63c229e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 13 May 2009 20:39:28 -0700 Subject: [PATCH 14/16] Remove monitor/rssi functions from telemetrum load Telemetrum is now a flight-only load, use teleterra or teledongle for ground boards. Signed-off-by: Keith Packard --- Makefile | 1 - ao_telemetrum.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/Makefile b/Makefile index 6fda8965..0c2314c4 100644 --- a/Makefile +++ b/Makefile @@ -98,7 +98,6 @@ TM_SRC = \ $(ALTOS_SRC) \ $(ALTOS_DRIVER_SRC) \ $(TELE_DRIVER_SRC) \ - $(TELE_RECEIVER_SRC) \ $(TELE_COMMON_SRC) \ $(TM_DRIVER_SRC) \ $(TM_TASK_SRC) \ diff --git a/ao_telemetrum.c b/ao_telemetrum.c index 097b15d7..a680ce19 100644 --- a/ao_telemetrum.c +++ b/ao_telemetrum.c @@ -42,8 +42,6 @@ main(void) ao_gps_report_init(); ao_telemetry_init(); ao_radio_init(); - ao_monitor_init(AO_LED_GREEN); - ao_rssi_init(AO_LED_RED); ao_igniter_init(); ao_dbg_init(); ao_config_init(); -- 2.30.2 From 9b974217958b1017e62d6c4f4568f547ccc30c58 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 13 May 2009 20:40:42 -0700 Subject: [PATCH 15/16] Enable radio monitor by default in teleterra, teledongle and tidongle These ground loads want to monitor the radio constantly, and not require use of the 'm' command before listening. Signed-off-by: Keith Packard --- ao.h | 8 +++++++- ao_monitor.c | 20 +++++++++++++------- ao_teledongle.c | 2 +- ao_teleterra.c | 3 +-- ao_tidongle.c | 2 +- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/ao.h b/ao.h index 96dd02d0..76fc00ce 100644 --- a/ao.h +++ b/ao.h @@ -23,6 +23,9 @@ #include #include "cc1111.h" +#define TRUE 1 +#define FALSE 0 + /* Convert a __data pointer into an __xdata pointer */ #define DATA_TO_XDATA(a) ((void __xdata *) ((uint8_t) (a) | 0xff00)) @@ -775,7 +778,10 @@ void ao_monitor(void); void -ao_monitor_init(uint8_t led); +ao_set_monitor(uint8_t monitoring); + +void +ao_monitor_init(uint8_t led, uint8_t monitoring) __reentrant; /* * ao_stdio.c diff --git a/ao_monitor.c b/ao_monitor.c index 2f6584bc..6aed581a 100644 --- a/ao_monitor.c +++ b/ao_monitor.c @@ -61,24 +61,30 @@ ao_monitor(void) __xdata struct ao_task ao_monitor_task; +void +ao_set_monitor(uint8_t monitoring) +{ + ao_monitoring = monitoring; + ao_wakeup(&ao_monitoring); +} + static void -ao_set_monitor(void) +set_monitor(void) { ao_cmd_hex(); - ao_monitoring = ao_cmd_lex_i != 0; - ao_wakeup(&ao_monitoring); + ao_set_monitor(ao_cmd_lex_i != 0); } __code struct ao_cmds ao_monitor_cmds[] = { - { 'm', ao_set_monitor, "m <0 off, 1 on> Enable/disable radio monitoring" }, - { 0, ao_set_monitor, NULL }, + { 'm', set_monitor, "m <0 off, 1 on> Enable/disable radio monitoring" }, + { 0, set_monitor, NULL }, }; void -ao_monitor_init(uint8_t monitor_led) +ao_monitor_init(uint8_t monitor_led, uint8_t monitoring) __reentrant { ao_monitor_led = monitor_led; - ao_monitoring = 0; + ao_monitoring = monitoring; ao_cmd_register(&ao_monitor_cmds[0]); ao_add_task(&ao_monitor_task, ao_monitor, "monitor"); } diff --git a/ao_teledongle.c b/ao_teledongle.c index 98163109..67fe7614 100644 --- a/ao_teledongle.c +++ b/ao_teledongle.c @@ -32,7 +32,7 @@ main(void) ao_timer_init(); ao_cmd_init(); ao_usb_init(); - ao_monitor_init(AO_LED_GREEN); + ao_monitor_init(AO_LED_GREEN, TRUE); ao_rssi_init(AO_LED_RED); ao_radio_init(); ao_dbg_init(); diff --git a/ao_teleterra.c b/ao_teleterra.c index ed72cd4b..ad3e2d9b 100644 --- a/ao_teleterra.c +++ b/ao_teleterra.c @@ -34,8 +34,7 @@ main(void) ao_usb_init(); ao_serial_init(); ao_gps_init(); - ao_monitor_init(AO_LED_GREEN); - ao_monitor_init(AO_LED_RED); + ao_monitor_init(AO_LED_GREEN, TRUE); ao_radio_init(); ao_dbg_init(); ao_config_init(); diff --git a/ao_tidongle.c b/ao_tidongle.c index 4d9a77f7..b068d045 100644 --- a/ao_tidongle.c +++ b/ao_tidongle.c @@ -32,7 +32,7 @@ main(void) ao_timer_init(); ao_cmd_init(); ao_usb_init(); - ao_monitor_init(AO_LED_RED); + ao_monitor_init(AO_LED_RED, TRUE); ao_rssi_init(AO_LED_RED); ao_radio_init(); ao_dbg_init(); -- 2.30.2 From 37250b00f6286aee4b3b28604f5d463db3079a89 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 13 May 2009 20:41:54 -0700 Subject: [PATCH 16/16] Discard usb output before connection. Handle USB reset. Discarding output before USB is plugged in allows threads that send output and do other things to work without a USB connection. Unfortuantely, there doesn't appear to be any way to detect when the USB link is disconnected, which means that once USB is enabled, future writes will continue to block. USB reset causes the USB interrupts to all be reconfigured back to power-on state. Signed-off-by: Keith Packard --- ao_usb.c | 33 ++++++++++++++++++++++----------- cc1111.h | 6 ++++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ao_usb.c b/ao_usb.c index 69f87fc4..315eea08 100644 --- a/ao_usb.c +++ b/ao_usb.c @@ -23,7 +23,20 @@ struct ao_task __xdata ao_usb_task; static __xdata uint16_t ao_usb_in_bytes; static __xdata uint16_t ao_usb_out_bytes; static __xdata uint8_t ao_usb_iif; -static __xdata uint8_t ao_usb_oif; +static __xdata uint8_t ao_usb_running; + +static void +ao_usb_set_interrupts(void) +{ + /* IN interrupts on the control an IN endpoints */ + USBIIE = (1 << AO_USB_CONTROL_EP) | (1 << AO_USB_IN_EP); + + /* OUT interrupts on the OUT endpoint */ + USBOIE = (1 << AO_USB_OUT_EP); + + /* Only care about reset */ + USBCIE = USBCIE_RSTIE; +} /* This interrupt is shared with port 2, * so when we hook that up, fix this @@ -38,9 +51,11 @@ ao_usb_isr(void) interrupt 6 if (ao_usb_iif & (1 << AO_USB_IN_EP)) ao_wakeup(&ao_usb_in_bytes); - ao_usb_oif |= USBOIF; - if (ao_usb_oif & (1 << AO_USB_OUT_EP)) + if (USBOIF & (1 << AO_USB_OUT_EP)) ao_wakeup(&ao_usb_out_bytes); + + if (USBCIF & USBCIF_RSTIF) + ao_usb_set_interrupts(); } struct ao_usb_setup { @@ -136,6 +151,7 @@ ao_usb_ep0_queue_byte(uint8_t a) void ao_usb_set_address(uint8_t address) { + ao_usb_running = 1; USBADDR = address | 0x80; while (USBADDR & 0x80) ; @@ -318,6 +334,8 @@ ao_usb_flush(void) __critical void ao_usb_putchar(char c) __critical { + if (!ao_usb_running) + return; for (;;) { USBINDEX = AO_USB_IN_EP; if ((USBCSIL & USBCSIL_INPKT_RDY) == 0) @@ -362,15 +380,8 @@ ao_usb_enable(void) ao_usb_set_configuration(); - /* IN interrupts on the control an IN endpoints */ - USBIIE = (1 << AO_USB_CONTROL_EP) | (1 << AO_USB_IN_EP); + ao_usb_set_interrupts(); - /* OUT interrupts on the OUT endpoint */ - USBOIE = (1 << AO_USB_OUT_EP); - - /* Ignore control interrupts */ - USBCIE = 0; - /* enable USB interrupts */ IEN2 |= IEN2_USBIE; diff --git a/cc1111.h b/cc1111.h index 2045c716..4e451465 100644 --- a/cc1111.h +++ b/cc1111.h @@ -337,6 +337,12 @@ __xdata __at (0xde02) volatile uint8_t USBIIF; __xdata __at (0xde04) volatile uint8_t USBOIF; __xdata __at (0xde06) volatile uint8_t USBCIF; + +# define USBCIF_SOFIF (1 << 3) +# define USBCIF_RSTIF (1 << 2) +# define USBCIF_RESUMEIF (1 << 1) +# define USBCIF_SUSPENDIF (1 << 0) + __xdata __at (0xde07) volatile uint8_t USBIIE; __xdata __at (0xde09) volatile uint8_t USBOIE; -- 2.30.2