summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-09-02 23:36:36 -0500
committerKeith Packard <keithp@keithp.com>2016-09-02 23:36:36 -0500
commit30e8f003381c30434058905f53f5a219ac5feb4f (patch)
tree0ef92b1985b72d78decbd39f879e5f056ee55027
parent3ea30c1909b3ae23918ea6d0a53d2c4065b08763 (diff)
ao-tools/ao-cal-freq: Re-open usb device each try
Instead of trying to re-use the same file descriptor, close and re-open the device each time around the loop to avoid getting stuck when calibrating TeleMega boards. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--ao-tools/ao-cal-freq/ao-cal-freq.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/ao-tools/ao-cal-freq/ao-cal-freq.c b/ao-tools/ao-cal-freq/ao-cal-freq.c
index c2982684..12c2a3ae 100644
--- a/ao-tools/ao-cal-freq/ao-cal-freq.c
+++ b/ao-tools/ao-cal-freq/ao-cal-freq.c
@@ -168,7 +168,8 @@ await_key(void)
}
int
-do_cal(struct cc_usb *usb) {
+do_cal(char *tty) {
+ struct cc_usb *usb = NULL;
struct flash *b;
char line[1024];
double measured_freq;
@@ -178,10 +179,17 @@ do_cal(struct cc_usb *usb) {
int cur_freq;
int cur_cal;
int new_cal;
-
- cc_usb_printf(usb, "E 0\n");
+ int ret = 1;
for(;;) {
+ usb = cc_usb_open(tty);
+
+ if (!usb)
+ exit(1);
+
+ cc_usb_printf(usb, "E 0\n");
+
+ cc_usb_sync(usb);
cc_usb_printf(usb, "C 1\n");
cc_usb_sync(usb);
@@ -202,7 +210,8 @@ do_cal(struct cc_usb *usb) {
if (!cur_cal_words || !cur_freq_words) {
printf("no response\n");
- return 0;
+ ret = 0;
+ break;
}
cur_cal = atoi(cur_cal_words[2]);
@@ -218,8 +227,11 @@ do_cal(struct cc_usb *usb) {
cc_usb_printf (usb, "c f %d\nc w\n", new_cal);
cc_usb_sync(usb);
+ cc_usb_close(usb);
}
- return 1;
+ if (usb)
+ cc_usb_close(usb);
+ return ret;
}
int
@@ -232,7 +244,6 @@ main (int argc, char **argv)
int i;
int c;
int tries;
- struct cc_usb *cc = NULL;
char *tty = NULL;
int success;
int verbose = 0;
@@ -270,12 +281,6 @@ main (int argc, char **argv)
if (!tty)
tty="/dev/ttyACM0";
- cc = cc_usb_open(tty);
-
- if (!cc)
- exit(1);
-
- if (!do_cal(cc))
+ if (!do_cal(tty))
ret = 1;
- done(cc, ret);
}