| 1 | /*
|
|---|
| 2 | * Copyright (c) 2017 Petr Manek
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup tmon
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /**
|
|---|
| 33 | * @file
|
|---|
| 34 | * USB transfer debugging.
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <stdio.h>
|
|---|
| 38 | #include <macros.h>
|
|---|
| 39 | #include "commands.h"
|
|---|
| 40 |
|
|---|
| 41 | #define NAME "tmon"
|
|---|
| 42 | #define INDENT " "
|
|---|
| 43 |
|
|---|
| 44 | typedef struct tmon_cmd {
|
|---|
| 45 | const char *name;
|
|---|
| 46 | const char *description;
|
|---|
| 47 | int (*action)(int, char **);
|
|---|
| 48 | } tmon_cmd_t;
|
|---|
| 49 |
|
|---|
| 50 | static tmon_cmd_t commands[] = {
|
|---|
| 51 | {
|
|---|
| 52 | .name = "list",
|
|---|
| 53 | .description = "Print a list of connected diagnostic devices.",
|
|---|
| 54 | .action = tmon_list,
|
|---|
| 55 | },
|
|---|
| 56 | {
|
|---|
| 57 | .name = "test-intr-in",
|
|---|
| 58 | .description = "Read from interrupt endpoint as fast as possible.",
|
|---|
| 59 | .action = tmon_burst_intr_in,
|
|---|
| 60 | },
|
|---|
| 61 | {
|
|---|
| 62 | .name = "test-intr-out",
|
|---|
| 63 | .description = "Write to interrupt endpoint as fast as possible.",
|
|---|
| 64 | .action = tmon_burst_intr_out,
|
|---|
| 65 | },
|
|---|
| 66 | {
|
|---|
| 67 | .name = "test-bulk-in",
|
|---|
| 68 | .description = "Read from bulk endpoint as fast as possible.",
|
|---|
| 69 | .action = tmon_burst_bulk_in,
|
|---|
| 70 | },
|
|---|
| 71 | {
|
|---|
| 72 | .name = "test-bulk-out",
|
|---|
| 73 | .description = "Write to bulk endpoint as fast as possible.",
|
|---|
| 74 | .action = tmon_burst_bulk_out,
|
|---|
| 75 | },
|
|---|
| 76 | {
|
|---|
| 77 | .name = "test-isoch-in",
|
|---|
| 78 | .description = "Read from isochronous endpoint as fast as possible.",
|
|---|
| 79 | .action = tmon_burst_isoch_in,
|
|---|
| 80 | },
|
|---|
| 81 | {
|
|---|
| 82 | .name = "test-isoch-out",
|
|---|
| 83 | .description = "Write to isochronous endpoint as fast as possible.",
|
|---|
| 84 | .action = tmon_burst_isoch_out,
|
|---|
| 85 | }
|
|---|
| 86 | };
|
|---|
| 87 |
|
|---|
| 88 | typedef struct tmon_opt {
|
|---|
| 89 | const char *long_name;
|
|---|
| 90 | char short_name;
|
|---|
| 91 | const char *description;
|
|---|
| 92 | } tmon_opt_t;
|
|---|
| 93 |
|
|---|
| 94 | static tmon_opt_t options[] = {
|
|---|
| 95 | {
|
|---|
| 96 | .long_name = "cycles",
|
|---|
| 97 | .short_name = 'n',
|
|---|
| 98 | .description = "Set the number of read/write cycles."
|
|---|
| 99 | },
|
|---|
| 100 | {
|
|---|
| 101 | .long_name = "size",
|
|---|
| 102 | .short_name = 's',
|
|---|
| 103 | .description = "Set the data size transferred in a single cycle."
|
|---|
| 104 | }
|
|---|
| 105 | };
|
|---|
| 106 |
|
|---|
| 107 | static void print_usage(char *app_name)
|
|---|
| 108 | {
|
|---|
| 109 | puts(NAME ": benchmark USB diagnostic device\n\n");
|
|---|
| 110 | printf("Usage: %s command [device] [options]\n\n", app_name);
|
|---|
| 111 |
|
|---|
| 112 | for (unsigned i = 0; i < ARRAY_SIZE(commands); ++i) {
|
|---|
| 113 | printf(INDENT "%s - %s\n", commands[i].name, commands[i].description);
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | puts("\n");
|
|---|
| 117 | for (unsigned i = 0; i < ARRAY_SIZE(options); ++i) {
|
|---|
| 118 | printf(INDENT "-%c --%s\n" INDENT INDENT "%s\n", options[i].short_name, options[i].long_name, options[i].description);
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | puts("\nIf no device is specified, the first device is used provided that it is the only one connected. Otherwise, the command fails.\n\n");
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | int main(int argc, char *argv[])
|
|---|
| 125 | {
|
|---|
| 126 | // Find a command to execute.
|
|---|
| 127 | tmon_cmd_t *cmd = NULL;
|
|---|
| 128 | for (unsigned i = 0; argc > 1 && i < ARRAY_SIZE(commands); ++i) {
|
|---|
| 129 | if (str_cmp(argv[1], commands[i].name) == 0) {
|
|---|
| 130 | cmd = commands + i;
|
|---|
| 131 | break;
|
|---|
| 132 | }
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | if (!cmd) {
|
|---|
| 136 | print_usage(argv[0]);
|
|---|
| 137 | return -1;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | return cmd->action(argc - 1, argv + 1);
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | /** @}
|
|---|
| 144 | */
|
|---|