From patchwork Wed Nov 18 22:30:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Clayton X-Patchwork-Id: 7653081 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EBC4CBF90C for ; Wed, 18 Nov 2015 22:32:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 27D49204AD for ; Wed, 18 Nov 2015 22:32:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3A4CA2049E for ; Wed, 18 Nov 2015 22:32:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757158AbbKRWch (ORCPT ); Wed, 18 Nov 2015 17:32:37 -0500 Received: from mail-pa0-f41.google.com ([209.85.220.41]:34447 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933559AbbKRWcB (ORCPT ); Wed, 18 Nov 2015 17:32:01 -0500 Received: by padhx2 with SMTP id hx2so58170122pad.1; Wed, 18 Nov 2015 14:32:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=3X7tCJ1OmR1AJOsSUCpST2PygxWUxv0eq1WxryiN2wU=; b=N9xaILxoAKyKeJZYxeoHFnF0YLjNUM9mepbDaJ2oVK9ZMUJC9CgUjUH1JpOcg3AXDu tf7rpCw3h46JCGJhkPF2MOBmbY0/N4K54j1j0FPtQUVkkyQzKvkcdDdUaroT0Rg9X0mM qsP9ozGc2tVul06Qlrbnm9myJhrR5JWu6vPneEykUwiGOKDKeYnRFN9wxkKSzsO5r/r8 n+7J4Mjm0goxPZnFqb0/DTpWPYCcasKI4Kng1+a15RB//dzT3/RKt9Shf144dZSQj2JO ai8ruT7W6VQpfqPOSnA7eFgFt0NUu2yhWXtiLgTe6qhMJdZrWLQfPNAUY2CtyEP/p4hU WK2g== X-Received: by 10.68.68.139 with SMTP id w11mr1659862pbt.91.1447885921287; Wed, 18 Nov 2015 14:32:01 -0800 (PST) Received: from localhost.localdomain (68-185-59-186.static.knwc.wa.charter.com. [68.185.59.186]) by smtp.gmail.com with ESMTPSA id we9sm5836249pab.3.2015.11.18.14.32.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Nov 2015 14:32:00 -0800 (PST) From: Joshua Clayton To: Mark Brown , linux-spi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Anton Bondarenko , Joshua Clayton Subject: [PATCH v2 4/6] spi: spidev_test: output to a file Date: Wed, 18 Nov 2015 14:30:40 -0800 Message-Id: <9ef02d085de706dfbf7eb57370ce33f076dfd9ce.1447880230.git.stillcompiling@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For testing of larger data transfers, output unmodified data directly to a file. Signed-off-by: Joshua Clayton --- tools/spi/spidev_test.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index 71a45a4..02fc3a4 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -35,6 +35,7 @@ static const char *device = "/dev/spidev1.1"; static uint32_t mode; static uint8_t bits = 8; static char *input_file; +static char *output_file; static uint32_t speed = 500000; static uint16_t delay; 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) { int ret; - + int out_fd; struct spi_ioc_transfer tr = { .tx_buf = (unsigned long)tx, .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) if (verbose) hex_dump(tx, len, 32, "TX"); - hex_dump(rx, len, 32, "RX"); + + 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"); } static void print_usage(const char *prog) @@ -147,6 +162,7 @@ static void print_usage(const char *prog) " -d --delay delay (usec)\n" " -b --bpw bits per word \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" " -H --cpha clock phase\n" " -O --cpol clock polarity\n" @@ -171,6 +187,7 @@ static void parse_opts(int argc, char *argv[]) { "delay", 1, 0, 'd' }, { "bpw", 1, 0, 'b' }, { "input", 1, 0, 'i' }, + { "output", 1, 0, 'o' }, { "loop", 0, 0, 'l' }, { "cpha", 0, 0, 'H' }, { "cpol", 0, 0, 'O' }, @@ -186,7 +203,7 @@ static void parse_opts(int argc, char *argv[]) }; 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); if (c == -1) @@ -208,6 +225,9 @@ static void parse_opts(int argc, char *argv[]) case 'i': input_file = optarg; break; + case 'o': + output_file = optarg; + break; case 'l': mode |= SPI_LOOP; break;