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>
This commit is contained in:
parent
7af475a5b5
commit
983b27886a
|
@ -35,6 +35,7 @@ static const char *device = "/dev/spidev1.1";
|
||||||
static uint32_t mode;
|
static uint32_t mode;
|
||||||
static uint8_t bits = 8;
|
static uint8_t bits = 8;
|
||||||
static char *input_file;
|
static char *input_file;
|
||||||
|
static char *output_file;
|
||||||
static uint32_t speed = 500000;
|
static uint32_t speed = 500000;
|
||||||
static uint16_t delay;
|
static uint16_t delay;
|
||||||
static int verbose;
|
static int verbose;
|
||||||
|
@ -105,7 +106,7 @@ static int unescape(char *_dst, char *_src, size_t len)
|
||||||
static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len)
|
static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
int out_fd;
|
||||||
struct spi_ioc_transfer tr = {
|
struct spi_ioc_transfer tr = {
|
||||||
.tx_buf = (unsigned long)tx,
|
.tx_buf = (unsigned long)tx,
|
||||||
.rx_buf = (unsigned long)rx,
|
.rx_buf = (unsigned long)rx,
|
||||||
|
@ -136,6 +137,20 @@ static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len)
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
hex_dump(tx, len, 32, "TX");
|
hex_dump(tx, len, 32, "TX");
|
||||||
|
|
||||||
|
if (output_file) {
|
||||||
|
out_fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||||
|
if (out_fd < 0)
|
||||||
|
pabort("could not open output file");
|
||||||
|
|
||||||
|
ret = write(out_fd, rx, len);
|
||||||
|
if (ret != len)
|
||||||
|
pabort("not all bytes written to utput file");
|
||||||
|
|
||||||
|
close(out_fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (verbose || !output_file)
|
||||||
hex_dump(rx, len, 32, "RX");
|
hex_dump(rx, len, 32, "RX");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,6 +162,7 @@ static void print_usage(const char *prog)
|
||||||
" -d --delay delay (usec)\n"
|
" -d --delay delay (usec)\n"
|
||||||
" -b --bpw bits per word \n"
|
" -b --bpw bits per word \n"
|
||||||
" -i --input input data from a file (e.g. \"test.bin\")\n"
|
" -i --input input data from a file (e.g. \"test.bin\")\n"
|
||||||
|
" -o --output output data to a file (e.g. \"results.bin\")\n"
|
||||||
" -l --loop loopback\n"
|
" -l --loop loopback\n"
|
||||||
" -H --cpha clock phase\n"
|
" -H --cpha clock phase\n"
|
||||||
" -O --cpol clock polarity\n"
|
" -O --cpol clock polarity\n"
|
||||||
|
@ -171,6 +187,7 @@ static void parse_opts(int argc, char *argv[])
|
||||||
{ "delay", 1, 0, 'd' },
|
{ "delay", 1, 0, 'd' },
|
||||||
{ "bpw", 1, 0, 'b' },
|
{ "bpw", 1, 0, 'b' },
|
||||||
{ "input", 1, 0, 'i' },
|
{ "input", 1, 0, 'i' },
|
||||||
|
{ "output", 1, 0, 'o' },
|
||||||
{ "loop", 0, 0, 'l' },
|
{ "loop", 0, 0, 'l' },
|
||||||
{ "cpha", 0, 0, 'H' },
|
{ "cpha", 0, 0, 'H' },
|
||||||
{ "cpol", 0, 0, 'O' },
|
{ "cpol", 0, 0, 'O' },
|
||||||
|
@ -186,7 +203,7 @@ static void parse_opts(int argc, char *argv[])
|
||||||
};
|
};
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
c = getopt_long(argc, argv, "D:s:d:b:i:lHOLC3NR24p:v",
|
c = getopt_long(argc, argv, "D:s:d:b:i:o:lHOLC3NR24p:v",
|
||||||
lopts, NULL);
|
lopts, NULL);
|
||||||
|
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
|
@ -208,6 +225,9 @@ static void parse_opts(int argc, char *argv[])
|
||||||
case 'i':
|
case 'i':
|
||||||
input_file = optarg;
|
input_file = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'o':
|
||||||
|
output_file = optarg;
|
||||||
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
mode |= SPI_LOOP;
|
mode |= SPI_LOOP;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue