All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Bondarenko <anton.bondarenko.sama@gmail.com>
To: Joshua Clayton <stillcompiling@gmail.com>,
	Mark Brown <broonie@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>,
	Adrian Remonda <adrianremonda@gmail.com>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-spi@vger.kernel.org
Subject: Re: [PATCH 3/8] Documentation/spi/spidev_test.c: accept input from a file
Date: Tue, 17 Nov 2015 19:26:54 +0100	[thread overview]
Message-ID: <564B716E.5020605@gmail.com> (raw)
In-Reply-To: <d90d749776cf562bc9922aff5e97cb911a77b22b.1447773299.git.stillcompiling@gmail.com>

On 17.11.2015 16:24, Joshua Clayton wrote:
> Add input file support to facilitate testing larger data.
>
> Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
> ---
>   Documentation/spi/spidev_test.c | 42 ++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 41 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/spi/spidev_test.c b/Documentation/spi/spidev_test.c
> index 1ed9110..ef812ad 100644
> --- a/Documentation/spi/spidev_test.c
> +++ b/Documentation/spi/spidev_test.c
> @@ -19,6 +19,7 @@
>   #include <getopt.h>
>   #include <fcntl.h>
>   #include <sys/ioctl.h>
> +#include <sys/stat.h>
>   #include <linux/types.h>
>   #include <linux/spi/spidev.h>
>
> @@ -33,6 +34,7 @@ static void pabort(const char *s)
>   static const char *device = "/dev/spidev1.1";
>   static uint32_t mode;
>   static uint8_t bits = 8;
> +static char *input_file;
>   static uint32_t speed = 500000;
>   static uint16_t delay;
>   static int verbose;
> @@ -144,6 +146,7 @@ static void print_usage(const char *prog)
>   	     "  -s --speed    max speed (Hz)\n"
>   	     "  -d --delay    delay (usec)\n"
>   	     "  -b --bpw      bits per word \n"
> +	     "  -i --input    input data from a file (e.g. \"test.bin\")\n"
>   	     "  -l --loop     loopback\n"
>   	     "  -H --cpha     clock phase\n"
>   	     "  -O --cpol     clock polarity\n"
> @@ -167,6 +170,7 @@ static void parse_opts(int argc, char *argv[])
>   			{ "speed",   1, 0, 's' },
>   			{ "delay",   1, 0, 'd' },
>   			{ "bpw",     1, 0, 'b' },
> +			{ "input",   1, 0, 'i' },
>   			{ "loop",    0, 0, 'l' },
>   			{ "cpha",    0, 0, 'H' },
>   			{ "cpol",    0, 0, 'O' },
> @@ -182,7 +186,8 @@ static void parse_opts(int argc, char *argv[])
>   		};
>   		int c;
>
> -		c = getopt_long(argc, argv, "D:s:d:b:lHOLC3NR24p:v", lopts, NULL);
> +		c = getopt_long(argc, argv, "D:s:d:b:i:lHOLC3NR24p:v",
> +				lopts, NULL);
>
>   		if (c == -1)
>   			break;
> @@ -200,6 +205,9 @@ static void parse_opts(int argc, char *argv[])
>   		case 'b':
>   			bits = atoi(optarg);
>   			break;
> +		case 'i':
> +			input_file = optarg;
> +			break;
>   		case 'l':
>   			mode |= SPI_LOOP;
>   			break;
> @@ -259,6 +267,33 @@ static void transfer_escaped_string(int fd, char *str)
>   	free(tx);
>   }
>
> +static void transfer_file(int fd, char *filename)
> +{
> +	ssize_t bytes;
> +	struct stat sb;
> +	int tx_fd;
> +	uint8_t *tx;
> +
> +	if (stat(filename, &sb) == -1)
> +		pabort("can't stat input file");
> +
> +	if (sb.st_size > 4096)
> +		pabort("input file exceeds spidev's 4k limit");
This is not a true. IIRC PAGE_SIZE is the default buffer size for 
spidev, but can be changed using bufsiz module parameter.
Just 'insmod spidev bufsiz=X', where X is number of bytes.
> +
> +	tx_fd = open(filename, O_RDONLY);
> +	if (fd < 0)
> +		pabort("can't open input file");
> +
> +	tx = malloc(sb.st_size);
It would be good to check new allocations for fail.
> +	bytes = read(tx_fd, tx, sb.st_size);
> +	if (bytes != sb.st_size)
> +		pabort("failed to read input file");
> +
> +	transfer(fd, tx, sb.st_size);
> +	free(tx);
> +	close(tx_fd);
> +}
> +
>   int main(int argc, char *argv[])
>   {
>   	int ret = 0;
> @@ -307,8 +342,13 @@ int main(int argc, char *argv[])
>   	printf("bits per word: %d\n", bits);
>   	printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);
>
> +	if (input_tx && input_file)
> +		pabort("only one of -p and --input may be selected");
> +
>   	if (input_tx)
>   		transfer_escaped_string(fd, input_tx);
> +	else if (input_file)
> +		transfer_file(fd, input_file);
>   	else
>   		transfer(fd, default_tx, sizeof(default_tx));
>
>

  reply	other threads:[~2015-11-17 18:26 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-17 15:24 [PATCH 0/8] spi: Add file i/o to spidev_test Joshua Clayton
2015-11-17 15:24 ` Joshua Clayton
2015-11-17 15:24 ` [PATCH 1/8] Documentation/spi/spidev_test.c: use one rx buffer Joshua Clayton
     [not found]   ` <2f17ae29e75967b4522b080c275b907622e1d353.1447773299.git.stillcompiling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-11-17 17:41     ` Mark Brown
2015-11-17 17:41       ` Mark Brown
     [not found]       ` <20151117174156.GX31303-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-11-17 18:58         ` Joshua Clayton
2015-11-17 18:58           ` Joshua Clayton
2015-11-17 18:58           ` Joshua Clayton
2015-11-17 15:24 ` [PATCH 2/8] Documentation/spi/spidev_test.c: clean up input_tx Joshua Clayton
2015-11-17 17:43   ` Mark Brown
     [not found]     ` <20151117174333.GY31303-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-11-17 19:21       ` Joshua Clayton
2015-11-17 19:21         ` Joshua Clayton
2015-11-17 19:21         ` Joshua Clayton
2015-11-17 22:52         ` Mark Brown
2015-11-17 22:52           ` Mark Brown
2015-11-17 22:52           ` Mark Brown
2015-11-17 15:24 ` [PATCH 3/8] Documentation/spi/spidev_test.c: accept input from a file Joshua Clayton
2015-11-17 18:26   ` Anton Bondarenko [this message]
2015-11-17 18:46     ` Mark Brown
     [not found]     ` <564B716E.5020605-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-11-17 19:28       ` Joshua Clayton
2015-11-17 19:28         ` Joshua Clayton
2015-11-17 19:28         ` Joshua Clayton
     [not found] ` <cover.1447773299.git.stillcompiling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-11-17 15:24   ` [PATCH 4/8] Documentation/spi/spidev_test.c: output to " Joshua Clayton
2015-11-17 15:24     ` Joshua Clayton
2015-11-17 15:24   ` [PATCH 5/8] Documentation/spi/spidev_test.c: check error Joshua Clayton
2015-11-17 15:24     ` Joshua Clayton
2015-11-17 15:24 ` [PATCH 6/8] Documentation/spi/spidev_test.c: fix whitespace Joshua Clayton
2015-11-17 15:24 ` [PATCH 7/8] tools/Makefile: minor whitespace cleanup Joshua Clayton
     [not found]   ` <155366ac799345f42c8c342609ffa11b2df529b0.1447773299.git.stillcompiling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-11-17 18:09     ` Mark Brown
2015-11-17 18:09       ` Mark Brown
2015-11-17 19:41       ` Joshua Clayton
2015-11-17 19:41         ` Joshua Clayton
2015-11-17 15:24 ` [PATCH 8/8] spi: Move spi code from Documentation to tools Joshua Clayton
     [not found]   ` <7f1a4995f0e48b738d3aa4f4d8ddd210a0ae2b24.1447773299.git.stillcompiling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-11-17 18:11     ` Mark Brown
2015-11-17 18:11       ` Mark Brown
2015-11-17 15:37 ` [PATCH 0/8] spi: Add file i/o to spidev_test Mark Brown
2015-11-17 16:15   ` Joshua Clayton
2015-11-17 16:15     ` Joshua Clayton
2015-11-17 16:53     ` Mark Brown
2015-11-17 16:53       ` Mark Brown
2015-11-18 22:30     ` [PATCH v2 0/6] " Joshua Clayton
2015-11-18 22:30       ` Joshua Clayton
2015-11-18 22:30       ` [PATCH v2 1/6] spi: Move spi code from Documentation to tools Joshua Clayton
2015-11-18 22:30       ` [PATCH v2 2/6] spi: spidev_test: transfer_escaped_string function Joshua Clayton
     [not found]         ` <b0719c2739aabcd9894e85d82cbae21fcf83df3a.1447880230.git.stillcompiling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-11-23 14:54           ` Applied "spi: spidev_test: transfer_escaped_string function" to the spi tree Mark Brown
2015-11-18 22:30       ` [PATCH v2 3/6] spi: spidev_test: accept input from a file Joshua Clayton
     [not found]         ` <783ea7346741b23f17c73a13f03f64ac17de8c2e.1447880230.git.stillcompiling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-11-23 14:54           ` Applied "spi: spidev_test: accept input from a file" to the spi tree Mark Brown
     [not found]       ` <cover.1447880230.git.stillcompiling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-11-18 22:30         ` [PATCH v2 4/6] spi: spidev_test: output to a file Joshua Clayton
2015-11-18 22:30           ` Joshua Clayton
     [not found]           ` <9ef02d085de706dfbf7eb57370ce33f076dfd9ce.1447880230.git.stillcompiling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-11-23 14:54             ` Applied "spi: spidev_test: output to a file" to the spi tree Mark Brown
2015-11-18 22:30       ` [PATCH v2 5/6] spi: spidev_test: check error Joshua Clayton
     [not found]         ` <2bbb0374d7fd390a04ceb8d7b552f1a8d946c0f0.1447880230.git.stillcompiling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-11-23 14:54           ` Applied "spi: spidev_test: check error" to the spi tree Mark Brown
2015-11-18 22:30       ` [PATCH v2 6/6] spi: spidev_test: fix whitespace Joshua Clayton
     [not found]         ` <0365b51d6bfd3002287a1ebe382e58a2766aa2d2.1447880230.git.stillcompiling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-11-23 14:54           ` Applied "spi: spidev_test: fix whitespace" to the spi tree Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=564B716E.5020605@gmail.com \
    --to=anton.bondarenko.sama@gmail.com \
    --cc=adrianremonda@gmail.com \
    --cc=broonie@kernel.org \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=stillcompiling@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.