FreeCalypso > hg > fc-usbser-tools
comparison duart28/main.c @ 39:b9ecfa54fe2b
fc-duart28-conf: replace find and check-eeprom with single show command
The original design with separate find and check-eeprom commands
was driven by the assumption that we had to bump off the ftdi_sio driver
in order to read the EEPROM, while a USB device tree check could be done
non-invasively. However, now that we know that we can read the EEPROM
non-invasively too, we can simplify the tool with a single show command.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 10 Sep 2023 19:21:20 +0000 |
parents | df284688d0c8 |
children | f5847be43d35 |
comparison
equal
deleted
inserted
replaced
38:6bf063ade588 | 39:b9ecfa54fe2b |
---|---|
9 #include <strings.h> | 9 #include <strings.h> |
10 #include <usb.h> | 10 #include <usb.h> |
11 #include "../libuwrap/open_close.h" | 11 #include "../libuwrap/open_close.h" |
12 | 12 |
13 extern struct usb_device *find_duart28_usbdev(); | 13 extern struct usb_device *find_duart28_usbdev(); |
14 extern unsigned usb_presenting_pid; | |
14 | 15 |
15 oper_find() | 16 oper_show() |
16 { | |
17 struct usb_device *dev; | |
18 | |
19 dev = find_duart28_usbdev(); | |
20 if (!dev) | |
21 printf("No DUART28 adapter found\n"); | |
22 return 0; | |
23 } | |
24 | |
25 oper_check_eeprom() | |
26 { | 17 { |
27 struct usb_device *dev; | 18 struct usb_device *dev; |
28 usb_dev_handle *usbh; | 19 usb_dev_handle *usbh; |
20 int eeconf; | |
29 | 21 |
30 dev = find_duart28_usbdev(); | 22 dev = find_duart28_usbdev(); |
31 if (!dev) { | 23 if (!dev) { |
32 fprintf(stderr, "error: no DUART28 adapter found\n"); | 24 fprintf(stderr, "error: no DUART28 adapter found\n"); |
33 exit(1); | 25 exit(1); |
37 fprintf(stderr, "error: usb_open() failed\n"); | 29 fprintf(stderr, "error: usb_open() failed\n"); |
38 exit(1); | 30 exit(1); |
39 } | 31 } |
40 read_eeprom(usbh); | 32 read_eeprom(usbh); |
41 usb_close(usbh); | 33 usb_close(usbh); |
42 analyze_eeprom(); | 34 eeconf = analyze_eeprom(); |
35 if (eeconf == 'C' && usb_presenting_pid != 0x7152) | |
36 printf("Visible USB device has wrong PID for C config" | |
37 " - please replug\n"); | |
38 if (eeconf == 'S' && usb_presenting_pid != 0x6010) | |
39 printf("Visible USB device has wrong PID for S config" | |
40 " - please replug\n"); | |
43 return 0; | 41 return 0; |
44 } | 42 } |
45 | 43 |
46 oper_program(newconf) | 44 oper_program(newconf) |
47 { | 45 { |
56 } | 54 } |
57 usbh = usbwrap_open_dev(dev, 1); | 55 usbh = usbwrap_open_dev(dev, 1); |
58 read_eeprom(usbh); | 56 read_eeprom(usbh); |
59 prev = analyze_eeprom(); | 57 prev = analyze_eeprom(); |
60 if (prev == newconf) { | 58 if (prev == newconf) { |
61 printf("EEPROM is already in the right state, nothing to do\n"); | 59 printf("EEPROM is already in the right state, nothing to program\n"); |
62 usbwrap_close_dev(usbh); | 60 usbwrap_close_dev(usbh); |
61 printf("Please replug the adapter to restore normal operation\n"); | |
63 return 0; | 62 return 0; |
64 } | 63 } |
65 printf("Reprogramming to DUART28%c configuration\n", newconf); | 64 printf("Reprogramming to DUART28%c configuration\n", newconf); |
66 update_eeprom(usbh, newconf); | 65 update_eeprom(usbh, newconf); |
67 usbwrap_close_dev(usbh); | 66 usbwrap_close_dev(usbh); |
68 printf("EEPROM changed, replug the USB device to take effect\n"); | 67 printf("EEPROM changed, replug the adapter to take effect\n"); |
69 return 0; | 68 return 0; |
70 } | 69 } |
71 | 70 |
72 main(argc, argv) | 71 main(argc, argv) |
73 char **argv; | 72 char **argv; |
74 { | 73 { |
75 if (argc < 2) | 74 if (argc < 2) { |
76 return oper_find(); | 75 usage: fprintf(stderr, "usage: %s show or %s set C|S\n", |
77 if (!strcmp(argv[1], "find")) { | 76 argv[0], argv[0]); |
77 exit(1); | |
78 } | |
79 if (!strcmp(argv[1], "show")) { | |
78 if (argc != 2) { | 80 if (argc != 2) { |
79 fprintf(stderr, | 81 fprintf(stderr, |
80 "error: %s find command takes no arguments\n", | 82 "error: %s show command takes no arguments\n", |
81 argv[0]); | 83 argv[0]); |
82 exit(1); | 84 exit(1); |
83 } | 85 } |
84 return oper_find(); | 86 return oper_show(); |
85 } | |
86 if (!strcmp(argv[1], "check-eeprom")) { | |
87 if (argc != 2) { | |
88 fprintf(stderr, | |
89 "error: %s check-eeprom command takes no arguments\n", | |
90 argv[0]); | |
91 exit(1); | |
92 } | |
93 return oper_check_eeprom(); | |
94 } | 87 } |
95 if (!strcmp(argv[1], "set")) { | 88 if (!strcmp(argv[1], "set")) { |
96 if (argc != 3) { | 89 if (argc != 3) { |
97 fprintf(stderr, | 90 fprintf(stderr, |
98 "error: %s set command takes 1 argument\n", | 91 "error: %s set command takes 1 argument\n", |
105 return oper_program(toupper(argv[2][0])); | 98 return oper_program(toupper(argv[2][0])); |
106 fprintf(stderr, "error: %s set argument must be C or S\n", | 99 fprintf(stderr, "error: %s set argument must be C or S\n", |
107 argv[0]); | 100 argv[0]); |
108 exit(1); | 101 exit(1); |
109 } | 102 } |
110 fprintf(stderr, "%s error: non-understood command \"%s\"\n", argv[0], | 103 goto usage; |
111 argv[1]); | |
112 exit(1); | |
113 } | 104 } |