diff options
author | (no author) <(no author)@6dc7ffe9-61d6-0310-9af1-9938baff3ed1> | 2006-08-25 12:32:11 +0000 |
---|---|---|
committer | (no author) <(no author)@6dc7ffe9-61d6-0310-9af1-9938baff3ed1> | 2006-08-25 12:32:11 +0000 |
commit | 9865031f9f7ab887b31b260b6060e1fde2b7a670 (patch) | |
tree | 1b56d558550769d617910f69c3745e72e99e8ad4 | |
parent | 767a06ec648b9242cba5bb1dddfef08137d7b7dc (diff) |
add usb benchmarking mode
git-svn-id: https://svn.openpcd.org:2342/trunk@132 6dc7ffe9-61d6-0310-9af1-9938baff3ed1
-rw-r--r-- | openpcd/opcd_test/opcd_test.c | 8 | ||||
-rw-r--r-- | openpcd/opcd_test/opcd_usb.c | 34 | ||||
-rw-r--r-- | openpcd/opcd_test/opcd_usb.h | 1 |
3 files changed, 42 insertions, 1 deletions
diff --git a/openpcd/opcd_test/opcd_test.c b/openpcd/opcd_test/opcd_test.c index 7b58aca..2aa1753 100644 --- a/openpcd/opcd_test/opcd_test.c +++ b/openpcd/opcd_test/opcd_test.c @@ -74,6 +74,7 @@ static struct option opts[] = { { "fifo-read", 1, 0, 'R' }, { "set-bits", 1, 0, 's' }, { "clear-bits", 1, 0, 'c' }, + { "usb-perf", 1, 0, 'u' }, { "help", 0, 0, 'h'}, }; @@ -91,7 +92,7 @@ int main(int argc, char **argv) while (1) { int option_index = 0; - c = getopt_long(argc, argv, "l:r:w:R:W:s:c:h?", opts, + c = getopt_long(argc, argv, "l:r:w:R:W:s:c:h?u:", opts, &option_index); if (c == -1) @@ -149,6 +150,11 @@ int main(int argc, char **argv) exit(2); opcd_send_command(od, OPENPCD_CMD_REG_BITS_CLEAR, i, j, 0, NULL); break; + case 'u': + if (get_number(optarg, 1, 255, &i) < 0) + exit(2); + opcd_usbperf(od, i); + break; case 'h': case '?': print_help(); diff --git a/openpcd/opcd_test/opcd_usb.c b/openpcd/opcd_test/opcd_usb.c index 9ac5263..00ee3d2 100644 --- a/openpcd/opcd_test/opcd_usb.c +++ b/openpcd/opcd_test/opcd_usb.c @@ -20,6 +20,8 @@ #include <unistd.h> #include <stdio.h> #include <string.h> +#include <time.h> +#include <sys/time.h> #include <sys/types.h> @@ -199,3 +201,35 @@ int opcd_send_command(struct opcd_handle *od, u_int8_t cmd, return ret; } + +int opcd_usbperf(struct opcd_handle *od, unsigned int frames) +{ + int i; + char buf[256*64]; + struct timeval tv_start, tv_stop; + unsigned int num_xfer = 0; + unsigned int diff_msec; + unsigned int transfers = 255; + + printf("starting DATA IN performance test (%u frames of 64 bytes)\n", + frames); + opcd_send_command(od, OPENPCD_CMD_USBTEST_IN, transfers, frames, 0, NULL); + gettimeofday(&tv_start, NULL); + for (i = 0; i < transfers; i++) { + int ret; + ret = ausb_bulk_read(od->hdl, OPCD_IN_EP, buf, sizeof(buf), 0); + if (ret < 0) { + fprintf(stderr, "error receiving data in transaction\n"); + return ret; + } + num_xfer += ret; + } + gettimeofday(&tv_stop, NULL); + diff_msec = (tv_stop.tv_sec - tv_start.tv_sec)*1000; + diff_msec += (tv_stop.tv_usec - tv_start.tv_usec)/1000; + + printf("%u transfers (total %u bytes) in %u miliseconds => %u bytes/sec\n", + i, num_xfer, diff_msec, (num_xfer*1000)/diff_msec); + + return 0; +} diff --git a/openpcd/opcd_test/opcd_usb.h b/openpcd/opcd_test/opcd_usb.h index 953f983..e9698f0 100644 --- a/openpcd/opcd_test/opcd_usb.h +++ b/openpcd/opcd_test/opcd_usb.h @@ -19,5 +19,6 @@ extern int opcd_recv_reply(struct opcd_handle *od, char *buf, int len); extern int opcd_send_command(struct opcd_handle *od, u_int8_t cmd, u_int8_t reg, u_int8_t val, u_int16_t len, const unsigned char *data); +extern int opcd_usbperf(struct opcd_handle *od, unsigned int frames); #endif |