diff options
| author | Joshua Clayton <stillcompiling@gmail.com> | 2015-11-18 17:30:40 -0500 |
|---|---|---|
| committer | Mark Brown <broonie@kernel.org> | 2015-11-23 09:54:01 -0500 |
| commit | 983b27886a3c7f6eff4e987ddba932da74703f4e (patch) | |
| tree | bb043005675308a78a890385fa874c74d0251b8c /tools/spi | |
| parent | 7af475a5b55e8e47327818e8133fe22204c1fc4d (diff) | |
spi: spidev_test: output to a file
For testing of larger data transfers, output unmodified data
directly to a file.
Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'tools/spi')
| -rw-r--r-- | tools/spi/spidev_test.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index 71a45a4d7d49..02fc3a44901b 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c | |||
| @@ -35,6 +35,7 @@ static const char *device = "/dev/spidev1.1"; | |||
| 35 | static uint32_t mode; | 35 | static uint32_t mode; |
| 36 | static uint8_t bits = 8; | 36 | static uint8_t bits = 8; |
| 37 | static char *input_file; | 37 | static char *input_file; |
| 38 | static char *output_file; | ||
| 38 | static uint32_t speed = 500000; | 39 | static uint32_t speed = 500000; |
| 39 | static uint16_t delay; | 40 | static uint16_t delay; |
| 40 | static int verbose; | 41 | static int verbose; |
| @@ -105,7 +106,7 @@ static int unescape(char *_dst, char *_src, size_t len) | |||
| 105 | static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len) | 106 | static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len) |
| 106 | { | 107 | { |
| 107 | int ret; | 108 | int ret; |
| 108 | 109 | int out_fd; | |
| 109 | struct spi_ioc_transfer tr = { | 110 | struct spi_ioc_transfer tr = { |
| 110 | .tx_buf = (unsigned long)tx, | 111 | .tx_buf = (unsigned long)tx, |
| 111 | .rx_buf = (unsigned long)rx, | 112 | .rx_buf = (unsigned long)rx, |
| @@ -136,7 +137,21 @@ static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len) | |||
| 136 | 137 | ||
| 137 | if (verbose) | 138 | if (verbose) |
| 138 | hex_dump(tx, len, 32, "TX"); | 139 | hex_dump(tx, len, 32, "TX"); |
| 139 | hex_dump(rx, len, 32, "RX"); | 140 | |
| 141 | if (output_file) { | ||
| 142 | out_fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0666); | ||
| 143 | if (out_fd < 0) | ||
| 144 | pabort("could not open output file"); | ||
| 145 | |||
| 146 | ret = write(out_fd, rx, len); | ||
| 147 | if (ret != len) | ||
| 148 | pabort("not all bytes written to utput file"); | ||
| 149 | |||
| 150 | close(out_fd); | ||
| 151 | } | ||
| 152 | |||
| 153 | if (verbose || !output_file) | ||
| 154 | hex_dump(rx, len, 32, "RX"); | ||
| 140 | } | 155 | } |
| 141 | 156 | ||
| 142 | static void print_usage(const char *prog) | 157 | static void print_usage(const char *prog) |
| @@ -147,6 +162,7 @@ static void print_usage(const char *prog) | |||
| 147 | " -d --delay delay (usec)\n" | 162 | " -d --delay delay (usec)\n" |
| 148 | " -b --bpw bits per word \n" | 163 | " -b --bpw bits per word \n" |
| 149 | " -i --input input data from a file (e.g. \"test.bin\")\n" | 164 | " -i --input input data from a file (e.g. \"test.bin\")\n" |
| 165 | " -o --output output data to a file (e.g. \"results.bin\")\n" | ||
| 150 | " -l --loop loopback\n" | 166 | " -l --loop loopback\n" |
| 151 | " -H --cpha clock phase\n" | 167 | " -H --cpha clock phase\n" |
| 152 | " -O --cpol clock polarity\n" | 168 | " -O --cpol clock polarity\n" |
| @@ -171,6 +187,7 @@ static void parse_opts(int argc, char *argv[]) | |||
| 171 | { "delay", 1, 0, 'd' }, | 187 | { "delay", 1, 0, 'd' }, |
| 172 | { "bpw", 1, 0, 'b' }, | 188 | { "bpw", 1, 0, 'b' }, |
| 173 | { "input", 1, 0, 'i' }, | 189 | { "input", 1, 0, 'i' }, |
| 190 | { "output", 1, 0, 'o' }, | ||
| 174 | { "loop", 0, 0, 'l' }, | 191 | { "loop", 0, 0, 'l' }, |
| 175 | { "cpha", 0, 0, 'H' }, | 192 | { "cpha", 0, 0, 'H' }, |
| 176 | { "cpol", 0, 0, 'O' }, | 193 | { "cpol", 0, 0, 'O' }, |
| @@ -186,7 +203,7 @@ static void parse_opts(int argc, char *argv[]) | |||
| 186 | }; | 203 | }; |
| 187 | int c; | 204 | int c; |
| 188 | 205 | ||
| 189 | c = getopt_long(argc, argv, "D:s:d:b:i:lHOLC3NR24p:v", | 206 | c = getopt_long(argc, argv, "D:s:d:b:i:o:lHOLC3NR24p:v", |
| 190 | lopts, NULL); | 207 | lopts, NULL); |
| 191 | 208 | ||
| 192 | if (c == -1) | 209 | if (c == -1) |
| @@ -208,6 +225,9 @@ static void parse_opts(int argc, char *argv[]) | |||
| 208 | case 'i': | 225 | case 'i': |
| 209 | input_file = optarg; | 226 | input_file = optarg; |
| 210 | break; | 227 | break; |
| 228 | case 'o': | ||
| 229 | output_file = optarg; | ||
| 230 | break; | ||
| 211 | case 'l': | 231 | case 'l': |
| 212 | mode |= SPI_LOOP; | 232 | mode |= SPI_LOOP; |
| 213 | break; | 233 | break; |
