Allow radio calibration to be set from ao-load
[fw/altos] / src / ao_config.c
index e82aa0159b2a068c8f7cf1df2ae4d67c6ceab4b5..4349bca856ac3a18e97aba1fe62f0939f3dc251d 100644 (file)
@@ -24,9 +24,19 @@ __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     "KD7SQG"
+#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
+ *
+ * This value is stored in a const variable so that
+ * ao-load can change it during programming for
+ * devices that have no eeprom for config data.
+ */
+const uint32_t ao_radio_cal = 1186611;
 
 static void
 _ao_config_put(void)
@@ -51,17 +61,21 @@ _ao_config_get(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_cal = ao_radio_cal;
                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_cal = ao_radio_cal;
                ao_config.minor = AO_CONFIG_MINOR;
                ao_config_dirty = 1;
        }
@@ -245,6 +259,26 @@ ao_config_apogee_delay_set(void) __reentrant
        ao_config_apogee_delay_show();
 }
 
+void
+ao_config_radio_cal_show(void) __reentrant
+{
+       printf("Radio cal: %ld\n", ao_config.radio_cal);
+}
+
+void
+ao_config_radio_cal_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_cal = ao_cmd_lex_u32;
+       ao_config_dirty = 1;
+       ao_mutex_put(&ao_config_mutex);
+       ao_config_radio_cal_show();
+}
+
 struct ao_config_var {
        char            cmd;
        void            (*set)(void) __reentrant;
@@ -264,14 +298,16 @@ ao_config_write(void) __reentrant;
 __code struct ao_config_var ao_config_vars[] = {
        { 'm',  ao_config_main_deploy_set,      ao_config_main_deploy_show,
                "m <meters>  Set height above launch for main deploy (in meters)" },
-       { 'a',  ao_config_accel_calibrate_set,  ao_config_accel_calibrate_show,
-               "a <+g> <-g> Set accelerometer calibration (0 for auto)" },
+       { 'd',  ao_config_apogee_delay_set,     ao_config_apogee_delay_show,
+               "d <delay>   Set apogee igniter delay (in seconds)" },
        { 'r',  ao_config_radio_channel_set,    ao_config_radio_channel_show,
                "r <channel> Set radio channel (freq = 434.550 + channel * .1)" },
        { '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,
-               "d <delay>   Set apogee igniter delay (in seconds)" },
+       { 'a',  ao_config_accel_calibrate_set,  ao_config_accel_calibrate_show,
+               "a <+g> <-g> Set accelerometer calibration (0 for auto)" },
+       { 'f',  ao_config_radio_cal_set,        ao_config_radio_cal_show,
+               "f <cal>     Set radio calibration value (cal = rf/(xtal/2^16))" },
        { 's',  ao_config_show,                 ao_config_show,
                "s           Show current config values" },
        { 'w',  ao_config_write,                ao_config_write,