*/
#define AO_CONFIG_MAJOR 1
-#define AO_CONFIG_MINOR 2
+#define AO_CONFIG_MINOR 3
struct ao_config {
uint8_t major;
uint8_t minor;
uint16_t main_deploy;
- int16_t accel_plus_g;
+ int16_t accel_plus_g; /* changed for minor version 2 */
uint8_t radio_channel;
char callsign[AO_MAX_CALLSIGN + 1];
- uint8_t apogee_delay;
- int16_t accel_minus_g;
+ uint8_t apogee_delay; /* minor version 1 */
+ int16_t accel_minus_g; /* minor version 2 */
+ uint32_t radio_frequency; /* minor version 3 */
};
extern __xdata struct ao_config ao_config;
#define AO_CONFIG_DEFAULT_CALLSIGN "N0CALL"
#define AO_CONFIG_DEFAULT_ACCEL_ZERO_G 16000
#define AO_CONFIG_DEFAULT_APOGEE_DELAY 0
+/*
+ * For 434.550MHz, the frequency value is:
+ *
+ * 434.550e6 / (24e6 / 2**16) = 1186611.2
+ */
+#define AO_CONFIG_DEFAULT_RADIO_FREQUENCY 1186611
static void
_ao_config_put(void)
memcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN,
sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1);
ao_config.apogee_delay = AO_CONFIG_DEFAULT_APOGEE_DELAY;
+ ao_config.radio_frequency = AO_CONFIG_DEFAULT_RADIO_FREQUENCY;
ao_config_dirty = 1;
}
if (ao_config.minor < AO_CONFIG_MINOR) {
/* Fixups for minor version 1 */
if (ao_config.minor < 1)
ao_config.apogee_delay = AO_CONFIG_DEFAULT_APOGEE_DELAY;
- /* Fixupes for minor version 2 */
+ /* Fixups for minor version 2 */
if (ao_config.minor < 2) {
ao_config.accel_plus_g = 0;
ao_config.accel_minus_g = 0;
}
+ /* Fixups for minor version 3 */
+ if (ao_config.minor < 3)
+ ao_config.radio_frequency = AO_CONFIG_DEFAULT_RADIO_FREQUENCY;
ao_config.minor = AO_CONFIG_MINOR;
ao_config_dirty = 1;
}
ao_config_apogee_delay_show();
}
+void
+ao_config_radio_frequency_show(void) __reentrant
+{
+ printf("Radio frequency: %ld\n", ao_config.radio_frequency);
+}
+
+void
+ao_config_radio_frequency_set(void) __reentrant
+{
+ ao_cmd_decimal();
+ if (ao_cmd_status != ao_cmd_success)
+ return;
+ ao_mutex_get(&ao_config_mutex);
+ _ao_config_get();
+ ao_config.radio_frequency = ao_cmd_lex_u32;
+ ao_config_dirty = 1;
+ ao_mutex_put(&ao_config_mutex);
+ ao_config_radio_frequency_show();
+}
+
struct ao_config_var {
char cmd;
void (*set)(void) __reentrant;
"a <+g> <-g> Set accelerometer calibration (0 for auto)" },
{ 'r', ao_config_radio_channel_set, ao_config_radio_channel_show,
"r <channel> Set radio channel (freq = 434.550 + channel * .1)" },
+ { 'f', ao_config_radio_frequency_set, ao_config_radio_frequency_show,
+ "f <cal> Set radio calibration value (cal = rf/(xtal/2^16))" },
{ 'c', ao_config_callsign_set, ao_config_callsign_show,
"c <call> Set callsign broadcast in each packet (8 char max)" },
{ 'd', ao_config_apogee_delay_set, ao_config_apogee_delay_show,
* RX filter: 93.75 kHz
*/
-/*
- * For 434.550MHz, the frequency value is:
- *
- * 434.550e6 / (24e6 / 2**16) = 1186611.2
- */
-
-#define FREQ_CONTROL 1186611
-
/*
* For IF freq of 140.62kHz, the IF value is:
*
RF_PA_TABLE1_OFF, RF_POWER,
RF_PA_TABLE0_OFF, RF_POWER,
- RF_FREQ2_OFF, (FREQ_CONTROL >> 16) & 0xff,
- RF_FREQ1_OFF, (FREQ_CONTROL >> 8) & 0xff,
- RF_FREQ0_OFF, (FREQ_CONTROL >> 0) & 0xff,
-
RF_FSCTRL1_OFF, (IF_FREQ_CONTROL << RF_FSCTRL1_FREQ_IF_SHIFT),
RF_FSCTRL0_OFF, (0 << RF_FSCTRL0_FREQOFF_SHIFT),
}
}
-void
-ao_radio_send(__xdata struct ao_telemetry *telemetry) __reentrant
+static void
+ao_radio_get(void)
{
ao_config_get();
ao_mutex_get(&ao_radio_mutex);
ao_radio_idle();
- ao_radio_done = 0;
RF_CHANNR = ao_config.radio_channel;
+ RF_FREQ2 = (uint8_t) (ao_config.radio_frequency >> 16);
+ RF_FREQ1 = (uint8_t) (ao_config.radio_frequency >> 8);
+ RF_FREQ0 = (uint8_t) (ao_config.radio_frequency);
+}
+
+#define ao_radio_put() ao_mutex_put(&ao_radio_mutex)
+
+void
+ao_radio_send(__xdata struct ao_telemetry *telemetry) __reentrant
+{
+ ao_radio_get();
+ ao_radio_done = 0;
ao_dma_set_transfer(ao_radio_dma,
telemetry,
&RFDXADDR,
RFST = RFST_STX;
__critical while (!ao_radio_done)
ao_sleep(&ao_radio_done);
- ao_mutex_put(&ao_radio_mutex);
+ ao_radio_put();
}
uint8_t
ao_radio_recv(__xdata struct ao_radio_recv *radio) __reentrant
{
- ao_config_get();
- ao_mutex_get(&ao_radio_mutex);
- ao_radio_idle();
- RF_CHANNR = ao_config.radio_channel;
+ ao_radio_get();
ao_dma_set_transfer(ao_radio_dma,
&RFDXADDR,
radio,
RFST = RFST_SRX;
__critical while (!ao_radio_dma_done)
ao_sleep(&ao_radio_dma_done);
- ao_mutex_put(&ao_radio_mutex);
+ ao_radio_put();
return (ao_radio_dma_done & AO_DMA_DONE);
}
{
uint8_t i;
uint8_t pkt_len;
- ao_mutex_get(&ao_radio_mutex);
- ao_radio_idle();
+
+ ao_radio_get();
ao_radio_rdf_running = 1;
for (i = 0; i < sizeof (rdf_setup); i += 2)
RF[rdf_setup[i]] = rdf_setup[i+1];
ao_radio_idle();
for (i = 0; i < sizeof (telemetry_setup); i += 2)
RF[telemetry_setup[i]] = telemetry_setup[i+1];
- ao_mutex_put(&ao_radio_mutex);
+ ao_radio_put();
}
void
ao_radio_abort();
}
+
/* Output carrier */
void
ao_radio_test(void)
{
- ao_config_get();
- ao_mutex_get(&ao_radio_mutex);
- ao_radio_idle();
+ ao_packet_slave_stop();
+ ao_radio_get();
printf ("Hit a character to stop..."); flush();
RFST = RFST_STX;
getchar();
ao_radio_idle();
- ao_mutex_put(&ao_radio_mutex);
+ ao_radio_put();
putchar('\n');
}