Add back the RDF tone generator
authorKeith Packard <keithp@keithp.com>
Fri, 4 Sep 2009 18:45:52 +0000 (11:45 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 4 Sep 2009 18:45:52 +0000 (11:45 -0700)
Tracking the rocket on the ground may be easier using tones than using
the digital data stream, so we'll try that and see what we think.

This reverts commit 3a3bfd471a868d546d83cdc431b53c8f5208edb9.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao.h
src/ao_flight.c
src/ao_flight_test.c
src/ao_radio.c
src/ao_telemetry.c

index 8e34255830ab7ca7032a3460beb8833045748e49..37f21508dd0877f1f6f4ae2427f13e1b0a22e273 100644 (file)
--- a/src/ao.h
+++ b/src/ao.h
@@ -777,6 +777,9 @@ struct ao_telemetry {
 void
 ao_telemetry_set_interval(uint16_t interval);
 
 void
 ao_telemetry_set_interval(uint16_t interval);
 
+void
+ao_rdf_set(uint8_t rdf);
+
 void
 ao_telemetry_init(void);
 
 void
 ao_telemetry_init(void);
 
@@ -796,6 +799,12 @@ struct ao_radio_recv {
 void
 ao_radio_recv(__xdata struct ao_radio_recv *recv) __reentrant;
 
 void
 ao_radio_recv(__xdata struct ao_radio_recv *recv) __reentrant;
 
+void
+ao_radio_rdf(void);
+
+void
+ao_radio_rdf_abort(void);
+
 void
 ao_radio_init(void);
 
 void
 ao_radio_init(void);
 
index be9b3bb6f4cfdbf4e55a9681dac98bbec304b471..2b062c13fbec8a0a545530015f077a5ad8b8307c 100644 (file)
@@ -227,6 +227,7 @@ ao_flight(void)
 
                                /* Turn on telemetry system
                                 */
 
                                /* Turn on telemetry system
                                 */
+                               ao_rdf_set(1);
                                ao_telemetry_set_interval(AO_TELEMETRY_INTERVAL_PAD);
 
                                ao_flight_state = ao_flight_pad;
                                ao_telemetry_set_interval(AO_TELEMETRY_INTERVAL_PAD);
 
                                ao_flight_state = ao_flight_pad;
@@ -277,6 +278,9 @@ ao_flight(void)
                                /* Increase telemetry rate */
                                ao_telemetry_set_interval(AO_TELEMETRY_INTERVAL_FLIGHT);
 
                                /* Increase telemetry rate */
                                ao_telemetry_set_interval(AO_TELEMETRY_INTERVAL_FLIGHT);
 
+                               /* disable RDF beacon */
+                               ao_rdf_set(0);
+
                                ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
                                break;
                        }
                                ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
                                break;
                        }
@@ -356,6 +360,9 @@ ao_flight(void)
                                /* slow down the ADC sample rate */
                                ao_timer_set_adc_interval(10);
 
                                /* slow down the ADC sample rate */
                                ao_timer_set_adc_interval(10);
 
+                               /* 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
                                /*
                                 * Start recording min/max accel and pres for a while
                                 * to figure out when the rocket has landed
index 1466b886cae1576d062dad778c6ac49cf03b9aea..9fcb00c2412d4b3b49ece5d1c4740643ca2921c6 100644 (file)
@@ -68,6 +68,7 @@ uint8_t ao_adc_head;
 #define ao_cmd_register(c)
 #define ao_usb_disable()
 #define ao_telemetry_set_interval(x)
 #define ao_cmd_register(c)
 #define ao_usb_disable()
 #define ao_telemetry_set_interval(x)
+#define ao_rdf_set(rdf)
 
 enum ao_igniter {
        ao_igniter_drogue = 0,
 
 enum ao_igniter {
        ao_igniter_drogue = 0,
index ca1ec7e8fcaa1cbdb8ca49a40ad53f184167bd58..e4d42c6c32734b2f1542c9ae411c872a0bc3f6ef 100644 (file)
 #define DEVIATION_M    6
 #define DEVIATION_E    3
 
 #define DEVIATION_M    6
 #define DEVIATION_E    3
 
+/*
+ * For our RDF beacon, set the symbol rate to 2kBaud (for a 1kHz tone),
+ * so the DRATE_E and DRATE_M values are:
+ *
+ * M is 94 and E is 6
+ *
+ * To make the tone last for 200ms, we need 2000 * .2 = 400 bits or 50 bytes
+ */
+
+#define RDF_DRATE_E    6
+#define RDF_DRATE_M    94
+#define RDF_PACKET_LEN 50
+
+/*
+ * RDF deviation should match the normal NFM value of 5kHz
+ *
+ * M is 6 and E is 1
+ *
+ */
+
+#define RDF_DEVIATION_M        6
+#define RDF_DEVIATION_E        1
+
 /* This are from the table for 433MHz */
 
 #define RF_POWER_M30_DBM       0x12
 /* This are from the table for 433MHz */
 
 #define RF_POWER_M30_DBM       0x12
@@ -184,6 +207,28 @@ static __code uint8_t radio_setup[] = {
        RF_IOCFG0_OFF,          0x00,
 };
 
        RF_IOCFG0_OFF,          0x00,
 };
 
+static __code uint8_t rdf_setup[] = {
+       RF_MDMCFG4_OFF,         ((CHANBW_E << RF_MDMCFG4_CHANBW_E_SHIFT) |
+                                (CHANBW_M << RF_MDMCFG4_CHANBW_M_SHIFT) |
+                                (RDF_DRATE_E << RF_MDMCFG4_DRATE_E_SHIFT)),
+       RF_MDMCFG3_OFF,         (RDF_DRATE_M << RF_MDMCFG3_DRATE_M_SHIFT),
+       RF_MDMCFG2_OFF,         (RF_MDMCFG2_DEM_DCFILT_OFF |
+                                RF_MDMCFG2_MOD_FORMAT_GFSK |
+                                RF_MDMCFG2_SYNC_MODE_15_16_THRES),
+       RF_MDMCFG1_OFF,         (RF_MDMCFG1_FEC_DIS |
+                                RF_MDMCFG1_NUM_PREAMBLE_2 |
+                                (2 << RF_MDMCFG1_CHANSPC_E_SHIFT)),
+
+       RF_DEVIATN_OFF,         ((RDF_DEVIATION_E << RF_DEVIATN_DEVIATION_E_SHIFT) |
+                                (RDF_DEVIATION_M << RF_DEVIATN_DEVIATION_M_SHIFT)),
+
+       /* packet length */
+       RF_PKTLEN_OFF,          RDF_PACKET_LEN,
+       RF_PKTCTRL1_OFF,        ((1 << PKTCTRL1_PQT_SHIFT)|
+                                PKTCTRL1_ADR_CHK_NONE),
+       RF_PKTCTRL0_OFF,        (RF_PKTCTRL0_PKT_FORMAT_NORMAL|
+                                RF_PKTCTRL0_LENGTH_CONFIG_FIXED),
+};
 
 static __code uint8_t telemetry_setup[] = {
        RF_MDMCFG4_OFF,         ((CHANBW_E << RF_MDMCFG4_CHANBW_E_SHIFT) |
 
 static __code uint8_t telemetry_setup[] = {
        RF_MDMCFG4_OFF,         ((CHANBW_E << RF_MDMCFG4_CHANBW_E_SHIFT) |
@@ -275,6 +320,50 @@ ao_radio_recv(__xdata struct ao_radio_recv *radio) __reentrant
        ao_mutex_put(&ao_radio_mutex);
 }
 
        ao_mutex_put(&ao_radio_mutex);
 }
 
+__xdata ao_radio_rdf_running;
+__xdata ao_radio_rdf_value = 0x55;
+
+void
+ao_radio_rdf(void)
+{
+       uint8_t i;
+       ao_mutex_get(&ao_radio_mutex);
+       ao_radio_idle();
+       ao_radio_rdf_running = 1;
+       for (i = 0; i < sizeof (rdf_setup); i += 2)
+               RF[rdf_setup[i]] = rdf_setup[i+1];
+
+       ao_dma_set_transfer(ao_radio_dma,
+                           &ao_radio_rdf_value,
+                           &RFDXADDR,
+                           RDF_PACKET_LEN,
+                           DMA_CFG0_WORDSIZE_8 |
+                           DMA_CFG0_TMODE_SINGLE |
+                           DMA_CFG0_TRIGGER_RADIO,
+                           DMA_CFG1_SRCINC_0 |
+                           DMA_CFG1_DESTINC_0 |
+                           DMA_CFG1_PRIORITY_HIGH);
+       ao_dma_start(ao_radio_dma);
+       RFST = RFST_STX;
+
+       __critical while (!ao_radio_dma_done)
+               ao_sleep(&ao_radio_dma_done);
+       ao_radio_rdf_running = 0;
+       ao_radio_idle();
+       for (i = 0; i < sizeof (rdf_setup); i += 2)
+               RF[telemetry_setup[i]] = telemetry_setup[i+1];
+       ao_mutex_put(&ao_radio_mutex);
+}
+
+void
+ao_radio_rdf_abort(void)
+{
+       if (ao_radio_rdf_running) {
+               ao_dma_abort(ao_radio_dma);
+               ao_radio_idle();
+       }
+}
+
 void
 ao_radio_init(void)
 {
 void
 ao_radio_init(void)
 {
index 9f57f3a9cacbc803bc62217802d930cb3bf0cc8e..7eefee3c2ea7554a494bdf0c0c29f77c032e7b23 100644 (file)
 #include "ao.h"
 
 __xdata uint16_t ao_telemetry_interval = 0;
 #include "ao.h"
 
 __xdata uint16_t ao_telemetry_interval = 0;
+__xdata uint8_t ao_rdf = 0;
+__xdata uint16_t ao_rdf_time;
+
+#define AO_RDF_INTERVAL        AO_SEC_TO_TICKS(3)
 
 void
 ao_telemetry(void)
 
 void
 ao_telemetry(void)
@@ -27,6 +31,7 @@ ao_telemetry(void)
        ao_config_get();
        memcpy(telemetry.callsign, ao_config.callsign, AO_MAX_CALLSIGN);
        telemetry.addr = ao_serial_number;
        ao_config_get();
        memcpy(telemetry.callsign, ao_config.callsign, AO_MAX_CALLSIGN);
        telemetry.addr = ao_serial_number;
+       ao_rdf_time = ao_time();
        for (;;) {
                while (ao_telemetry_interval == 0)
                        ao_sleep(&ao_telemetry_interval);
        for (;;) {
                while (ao_telemetry_interval == 0)
                        ao_sleep(&ao_telemetry_interval);
@@ -43,6 +48,13 @@ ao_telemetry(void)
                ao_mutex_put(&ao_gps_mutex);
                ao_radio_send(&telemetry);
                ao_delay(ao_telemetry_interval);
                ao_mutex_put(&ao_gps_mutex);
                ao_radio_send(&telemetry);
                ao_delay(ao_telemetry_interval);
+               if (ao_rdf &&
+                   (int16_t) (ao_time() - ao_rdf_time) >= 0)
+               {
+                       ao_rdf_time = ao_time() + AO_RDF_INTERVAL;
+                       ao_radio_rdf();
+                       ao_delay(ao_telemetry_interval);
+               }
        }
 }
 
        }
 }
 
@@ -53,6 +65,14 @@ ao_telemetry_set_interval(uint16_t interval)
        ao_wakeup(&ao_telemetry_interval);
 }
 
        ao_wakeup(&ao_telemetry_interval);
 }
 
+void
+ao_rdf_set(uint8_t rdf)
+{
+       ao_rdf = rdf;
+       if (rdf == 0)
+               ao_radio_rdf_abort();
+}
+
 __xdata struct ao_task ao_telemetry_task;
 
 void
 __xdata struct ao_task ao_telemetry_task;
 
 void