ao-tools: Add --wait option to ao-usbload
authorKeith Packard <keithp@keithp.com>
Mon, 26 Jan 2015 03:58:38 +0000 (19:58 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 26 Jan 2015 03:58:38 +0000 (19:58 -0800)
This waits forever for USB writes to complete, instead of timing out
after five seconds. Useful when debugging the device.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/ao-usbload/ao-usbload.c
ao-tools/lib/cc-usb.c
ao-tools/lib/cc-usb.h
src/stm/stm32l.h

index fd34fbdcfad8f21f7c0443a89fe312f4c500527e..1b217e55aae6d4fa11346379b78a551d159f18b5 100644 (file)
@@ -86,12 +86,13 @@ static const struct option options[] = {
        { .name = "cal", .has_arg = 1, .val = 'c' },
        { .name = "serial", .has_arg = 1, .val = 's' },
        { .name = "verbose", .has_arg = 1, .val = 'v' },
+       { .name = "wait", .has_arg = 0, .val = 'w' },
        { 0, 0, 0, 0},
 };
 
 static void usage(char *program)
 {
-       fprintf(stderr, "usage: %s [--raw] [--verbose=<verbose>] [--device=<device>] [-tty=<tty>] [--cal=<radio-cal>] [--serial=<serial>] file.{elf,ihx}\n", program);
+       fprintf(stderr, "usage: %s [--raw] [--verbose=<verbose>] [--device=<device>] [-tty=<tty>] [--cal=<radio-cal>] [--serial=<serial>] [--wait] file.{elf,ihx}\n", program);
        exit(1);
 }
 
@@ -145,7 +146,7 @@ main (int argc, char **argv)
        uint32_t                flash_base, flash_bound;
        int                     has_flash_size = 0;
 
-       while ((c = getopt_long(argc, argv, "rT:D:c:s:v:", options, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "wrT:D:c:s:v:", options, NULL)) != -1) {
                switch (c) {
                case 'T':
                        tty = optarg;
@@ -156,6 +157,9 @@ main (int argc, char **argv)
                case 'r':
                        raw = 1;
                        break;
+               case 'w':
+                       cc_default_timeout = -1;
+                       break;
                case 'c':
                        cal = strtoul(optarg, &cal_end, 10);
                        if (cal_end == optarg || *cal_end != '\0')
@@ -208,6 +212,10 @@ main (int argc, char **argv)
                                this_tty = cc_usbdevs_find_by_arg(device, "AltosFlash");
                        if (!this_tty)
                                this_tty = cc_usbdevs_find_by_arg(device, "TeleMega");
+                       if (!this_tty)
+                               this_tty = cc_usbdevs_find_by_arg(device, "TeleMetrum");
+                       if (!this_tty)
+                               this_tty = cc_usbdevs_find_by_arg(device, "TeleGPS");
                        if (!this_tty)
                                this_tty = getenv("ALTOS_TTY");
                        if (!this_tty)
index 38dfff04936c87e6fbed2b8df73b5286edd92987..1a4dc7a1163f7460bdf139422be70d72ed44d35c 100644 (file)
@@ -152,6 +152,8 @@ cc_usb_dbg(int indent, uint8_t *bytes, int len)
        }
 }
 
+int    cc_default_timeout = 5000;
+
 /*
  * Flush pending writes, fill pending reads
  */
@@ -227,7 +229,7 @@ _cc_usb_sync(struct cc_usb *cc, int wait_for_input, int write_timeout)
 void
 cc_usb_sync(struct cc_usb *cc)
 {
-       if (_cc_usb_sync(cc, 0, 5000) < 0) {
+       if (_cc_usb_sync(cc, 0, cc_default_timeout) < 0) {
                fprintf(stderr, "USB link timeout\n");
                exit(1);
        }
@@ -268,7 +270,7 @@ int
 cc_usb_getchar_timeout(struct cc_usb *cc, int timeout)
 {
        while (cc->in_pos == cc->in_count) {
-               if (_cc_usb_sync(cc, timeout, 5000) < 0) {
+               if (_cc_usb_sync(cc, timeout, cc_default_timeout) < 0) {
                        fprintf(stderr, "USB link timeout\n");
                        exit(1);
                }
@@ -279,7 +281,7 @@ cc_usb_getchar_timeout(struct cc_usb *cc, int timeout)
 int
 cc_usb_getchar(struct cc_usb *cc)
 {
-       return cc_usb_getchar_timeout(cc, 5000);
+       return cc_usb_getchar_timeout(cc, cc_default_timeout);
 }
 
 void
@@ -400,7 +402,7 @@ cc_usb_open_remote(struct cc_usb *cc, int freq, char *call)
                cc_usb_printf(cc, "\nc F %d\nc c %s\np\nE 0\n", freq, call);
                do {
                        cc->in_count = cc->in_pos = 0;
-                       _cc_usb_sync(cc, 100, 5000);
+                       _cc_usb_sync(cc, 100, cc_default_timeout);
                } while (cc->in_count > 0);
                cc->remote = 1;
        }
@@ -459,7 +461,7 @@ cc_usb_open(char *tty)
        cc_usb_printf(cc, "\nE 0\nm 0\n");
        do {
                cc->in_count = cc->in_pos = 0;
-               _cc_usb_sync(cc, 100, 5000);
+               _cc_usb_sync(cc, 100, cc_default_timeout);
        } while (cc->in_count > 0);
        return cc;
 }
index e08a956b25868747861597bb185ee16c0b066841..9ed198cd290c9ecad29fa2b15717fdae042bd9d4 100644 (file)
@@ -23,6 +23,8 @@
 
 struct cc_usb;
 
+extern int cc_default_timeout;
+
 struct cc_usb *
 cc_usb_open(char *tty);
 
index 799cccbd2a1848bd9510ad0aa1f62d2cea857ee3..c5c28e76a584f9d62b831b37c730aee4fdca8f6b 100644 (file)
@@ -1515,7 +1515,7 @@ extern struct stm_dbg_mcu stm_dbg_mcu;
 
 static inline uint16_t
 stm_dev_id(void) {
-       return stm_dbg_mcu.idcode & 0xfff;
+       return stm_dbgmcu.idcode & 0xfff;
 }
 
 struct stm_flash_size {