diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index b02a6384d27b..7ca427c27f07 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -45,6 +45,7 @@ static int transfer_size = -1; static int iterations; static int interval = 5; /* interval in seconds for showing transfer rate */ static int compare; +static int nonzero; static int do_tx = 1, do_rx = 1; static int random_input; static int input_choices; @@ -188,7 +189,7 @@ static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len) static void print_usage(const char *prog) { - printf("Usage: %s [-2348CDFHILMNORSZbcdiloprstvw]\n", prog); + printf("Usage: %s [-2348CDFHILMNORSZbcdiloprstvwz]\n", prog); puts("general device settings:\n" " -D --device device to use (default /dev/spidev1.1)\n" " -s --speed max speed (Hz)\n" @@ -212,6 +213,7 @@ static void print_usage(const char *prog) " -i --input input data from a file (e.g. \"test.bin\")\n" " -o --output output data to a file (e.g. \"results.bin\")\n" " -p send data (e.g. \"1234\\xde\\xad\")\n" + " -z --nonzero don't send 0x00 or 0xff bytes\n" " -S --size transfer the given number of random bytes\n" " -I --iter iterations\n" "additional parameters:\n" @@ -249,6 +251,7 @@ static void parse_opts(int argc, char *argv[]) { "input", 1, 0, 'i' }, { "output", 1, 0, 'o' }, { "size", 1, 0, 'S' }, + { "nonzero", 0, 0, 'z' }, { "iter", 1, 0, 'I' }, { "bpw", 1, 0, 'b' }, { "lsb", 0, 0, 'L' }, @@ -261,7 +264,7 @@ static void parse_opts(int argc, char *argv[]) }; int c; - c = getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:vS:I:", + c = getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:vS:zI:", lopts, NULL); if (c == -1) @@ -353,6 +356,9 @@ static void parse_opts(int argc, char *argv[]) random_input = 1; input_choices++; break; + case 'z': + nonzero = 1; + break; case 'I': iterations = atoi(optarg); break; @@ -455,8 +461,11 @@ static void transfer_buf(int fd, int len) tx = malloc(len); if (!tx) pabort("can't allocate tx buffer"); - for (i = 0; i < len; i++) - tx[i] = random(); + for (i = 0; i < len; i++) { + do + tx[i] = random(); + while (nonzero && (tx[i] == 0x0 || tx[i] == 0xff)); + } } if (do_rx) { @@ -493,6 +502,9 @@ int main(int argc, char *argv[]) if (iterations && transfer_size < 0) pabort("-I (--iter) is only implemented for -S (--size)"); + if (nonzero && transfer_size < 0) + pabort("-z (--nonzero) is only implemented for -S (--size)"); + if (compare && (!do_tx || !do_rx)) pabort("-c (--compare) conflicts with -t (--no-tx) or -r (--no-rx)");