summaryrefslogtreecommitdiff
path: root/host/opcd_test.c
diff options
context:
space:
mode:
authorlaforge <laforge@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2006-10-04 21:16:34 +0000
committerlaforge <laforge@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2006-10-04 21:16:34 +0000
commit13b60901d894ed21d4fe51ba31b06c8f70413839 (patch)
tree41ac1afc062591e1499dc2a0d5b362da1259b310 /host/opcd_test.c
parentc8667163f3ba7aa265d291c1b1a8c2c53bd0e5b8 (diff)
- add support to read the serial number
- add support for new OpenPCD firmware revisions with multiple interfaces git-svn-id: https://svn.openpcd.org:2342/trunk@263 6dc7ffe9-61d6-0310-9af1-9938baff3ed1
Diffstat (limited to 'host/opcd_test.c')
-rw-r--r--host/opcd_test.c52
1 files changed, 44 insertions, 8 deletions
diff --git a/host/opcd_test.c b/host/opcd_test.c
index 37f3094..00f986f 100644
--- a/host/opcd_test.c
+++ b/host/opcd_test.c
@@ -61,8 +61,14 @@ static void print_help(void)
"\t-w\t--reg-write\treg value\n"
"\t-r\t--reg-read\treg\n"
+ "\t-W\t--fifo-write\thex\n"
+ "\t-R\t--fifo-read\thex\n"
+
"\t-s\t--set-bits\treg\tmask\n"
- "\t-c\t--clear-bits\treg\tmask\n");
+ "\t-c\t--clear-bits\treg\tmask\n"
+
+ "\t-u\t--usb-perf\txfer_size\n"
+ );
}
@@ -79,24 +85,29 @@ static struct option opts[] = {
{ "adc-loop", 0, 0, 'A' },
{ "ssc-read", 0, 0, 'S' },
{ "loop", 0, 0, 'L' },
+ { "serial-number", 0, 0, 'n' },
{ "help", 0, 0, 'h'},
};
int main(int argc, char **argv)
{
struct opcd_handle *od;
- int c;
+ int c, outfd, retlen;
+ char *data;
static char buf[8192];
int buf_len = sizeof(buf);
print_welcome();
- od = opcd_init();
+ if (!strcmp(argv[0], "opicc_test"))
+ od = opcd_init(1);
+ else
+ od = opcd_init(0);
while (1) {
int option_index = 0;
- c = getopt_long(argc, argv, "l:r:w:R:W:s:c:h?u:aASL", opts,
+ c = getopt_long(argc, argv, "l:r:w:R:W:s:c:h?u:aASLn", opts,
&option_index);
if (c == -1)
@@ -115,7 +126,7 @@ int main(int argc, char **argv)
case 'r':
if (get_number(optarg, 0x00, OPENPCD_REG_MAX, &i) < 0)
exit(2);
- printf("reading register 0x%02x: ");
+ printf("reading register 0x%02x: ", i);
opcd_send_command(od, OPENPCD_CMD_READ_REG, i, 0, 0, NULL);
opcd_recv_reply(od, buf, buf_len);
break;
@@ -174,17 +185,42 @@ int main(int argc, char **argv)
case 'S':
opcd_send_command(od, OPENPCD_CMD_SSC_READ, 0, 1, 0, NULL);
opcd_recv_reply(od, buf, buf_len);
- /* FIXME: interpret and print ADC result */
+ /* FIXME: interpret and print SSC result */
break;
case 'L':
- while (1)
- opcd_recv_reply(od, buf, buf_len);
+ outfd = open("/tmp/opcd_samples",
+ O_CREAT|O_WRONLY|O_APPEND, 0664);
+ if (outfd < 0)
+ exit(2);
+ while (1) {
+ data = buf + sizeof(struct openpcd_hdr);
+ retlen = opcd_recv_reply(od, buf, buf_len);
+ if (retlen < 0)
+ break;
+ printf("DATA: %s\n", opcd_hexdump(data, retlen-4));
+#if 1
+ write(outfd, data, retlen-4);
+ fsync(outfd);
+#endif
+ }
+ close(outfd);
break;
case 'h':
case '?':
print_help();
exit(0);
break;
+ case 'n':
+ opcd_send_command(od, OPENPCD_CMD_GET_SERIAL, 0, 1, 4,
+ NULL);
+ retlen = opcd_recv_reply(od, buf,
+ sizeof(struct openpcd_hdr)+4);
+ if (retlen > 0) {
+ data = buf + sizeof(struct openpcd_hdr);
+ printf("SERIAL: %s\n", opcd_hexdump(data, retlen-4));
+ } else
+ printf("ERROR: %d, %s\n", retlen, usb_strerror());
+ break;
default:
fprintf(stderr, "unknown key `%c'\n", c);
print_help();
personal git repositories of Harald Welte. Your mileage may vary