diff options
-rw-r--r-- | ao-tools/ao-load/ao-load.c | 46 | ||||
-rw-r--r-- | src/ao_config.c | 10 |
2 files changed, 43 insertions, 13 deletions
diff --git a/ao-tools/ao-load/ao-load.c b/ao-tools/ao-load/ao-load.c index f5466612..4aa91b29 100644 --- a/ao-tools/ao-load/ao-load.c +++ b/ao-tools/ao-load/ao-load.c @@ -29,14 +29,17 @@ struct sym { unsigned addr; char *name; -} serial_symbols[] = { +} ao_symbols[] = { { 0, "_ao_serial_number" }, -#define AO_SERIAL_NUMBER (serial_symbols[0].addr) +#define AO_SERIAL_NUMBER (ao_symbols[0].addr) { 0, "_ao_usb_descriptors" }, -#define AO_USB_DESCRIPTORS (serial_symbols[1].addr) +#define AO_USB_DESCRIPTORS (ao_symbols[1].addr) + { 0, "_ao_radio_cal" }, +#define AO_RADIO_CAL (ao_symbols[2].addr) }; -#define NUM_SERIAL_SYMBOLS (sizeof(serial_symbols)/sizeof(serial_symbols[0])) +#define NUM_SERIAL_SYMBOLS 2 +#define NUM_SYMBOLS 3 static int find_symbols(FILE *map) @@ -64,14 +67,14 @@ find_symbols(FILE *map) a = strtoul(colon+1, &addr_end, 16); if (a == ULONG_MAX || addr_end == addr) continue; - for (s = 0; s < NUM_SERIAL_SYMBOLS; s++) - if (!strcmp(serial_symbols[s].name, name)) { - serial_symbols[s].addr = (unsigned) a; + for (s = 0; s < NUM_SYMBOLS; s++) + if (!strcmp(ao_symbols[s].name, name)) { + ao_symbols[s].addr = (unsigned) a; ++found; break; } } - return found == NUM_SERIAL_SYMBOLS; + return found >= NUM_SERIAL_SYMBOLS; } static int @@ -93,12 +96,13 @@ rewrite(struct hex_image *image, unsigned addr, char *data, int len) static const struct option options[] = { { .name = "tty", .has_arg = 1, .val = 'T' }, { .name = "device", .has_arg = 1, .val = 'D' }, + { .name = "cal", .has_arg = 1, .val = 'c' }, { 0, 0, 0, 0}, }; static void usage(char *program) { - fprintf(stderr, "usage: %s [--tty <tty-name>] [--device <device-name>] file.ihx serial-number\n", program); + fprintf(stderr, "usage: %s [--tty <tty-name>] [--device <device-name>] [--cal <radio-cal>] file.ihx serial-number\n", program); exit(1); } @@ -125,9 +129,12 @@ main (int argc, char **argv) int string_num; char *tty = NULL; char *device = NULL; + uint32_t cal = 0; + char cal_int[4]; + char *cal_end; int c; - while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "T:D:c:", options, NULL)) != -1) { switch (c) { case 'T': tty = optarg; @@ -135,6 +142,11 @@ main (int argc, char **argv) case 'D': device = optarg; break; + case 'c': + cal = strtoul(optarg, &cal_end, 10); + if (cal_end == optarg || *cal_end != '\0') + usage(argv[0]); + break; default: usage(argv[0]); break; @@ -225,6 +237,20 @@ main (int argc, char **argv) if (!rewrite(image, usb_descriptors + 2 + image->address, serial_ucs2, serial_ucs2_len)) usage(argv[0]); + if (cal) { + cal_int[0] = cal & 0xff; + cal_int[1] = (cal >> 8) & 0xff; + cal_int[2] = (cal >> 16) & 0xff; + cal_int[3] = (cal >> 24) & 0xff; + if (!AO_RADIO_CAL) { + fprintf(stderr, "Cannot find radio calibration location in image\n"); + exit(1); + } + if (!rewrite(image, AO_RADIO_CAL, cal_int, sizeof (cal_int))) { + fprintf(stderr, "Cannot rewrite radio calibration at %04x\n", AO_RADIO_CAL); + exit(1); + } + } if (!tty) tty = cc_usbdevs_find_by_arg(device, "TIDongle"); dbg = ccdbg_open(tty); diff --git a/src/ao_config.c b/src/ao_config.c index 3609ec06..4349bca8 100644 --- a/src/ao_config.c +++ b/src/ao_config.c @@ -31,8 +31,12 @@ __xdata uint8_t ao_config_mutex; * 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. */ -#define AO_CONFIG_DEFAULT_RADIO_CAL 1186611 +const uint32_t ao_radio_cal = 1186611; static void _ao_config_put(void) @@ -57,7 +61,7 @@ _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_CONFIG_DEFAULT_RADIO_CAL; + ao_config.radio_cal = ao_radio_cal; ao_config_dirty = 1; } if (ao_config.minor < AO_CONFIG_MINOR) { @@ -71,7 +75,7 @@ _ao_config_get(void) } /* Fixups for minor version 3 */ if (ao_config.minor < 3) - ao_config.radio_cal = AO_CONFIG_DEFAULT_RADIO_CAL; + ao_config.radio_cal = ao_radio_cal; ao_config.minor = AO_CONFIG_MINOR; ao_config_dirty = 1; } |