From patchwork Tue Nov 17 15:24:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Clayton X-Patchwork-Id: 7638121 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 43296BF90C for ; Tue, 17 Nov 2015 15:27:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 62A88204D8 for ; Tue, 17 Nov 2015 15:27:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 82576200E7 for ; Tue, 17 Nov 2015 15:27:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750888AbbKQP0r (ORCPT ); Tue, 17 Nov 2015 10:26:47 -0500 Received: from mail-pa0-f65.google.com ([209.85.220.65]:32809 "EHLO mail-pa0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753893AbbKQPZY (ORCPT ); Tue, 17 Nov 2015 10:25:24 -0500 Received: by padfb7 with SMTP id fb7so1749502pad.0; Tue, 17 Nov 2015 07:25:23 -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=l0j/xsl5WQxiZKT49TZOp+6dzGDctS0YZGiOYANSDN0=; b=0ZvD664G4VKG4OBEArHRSDZLTciqlGUC/B/2IgWUo9C2OXUnMBtkUUCQ61ZWGqcWFq 2zaInhBWB0kaFN3j8d/Bln7tEe+VFNvyUhn74DygfWfH84cMBU18RK1HEEB5Lvoef+w6 mlXyQjm2jQjQ7zVs/rJJ6Igno0S91UPXnDjRt+OQX9l0YQkUBYC1Q85AvRxckJ56EPGM qspR+YE5NUABMBhqy6f5t4J03/dXzMu4nXSL2CpIhYNzToNGydjyUCFl8FSngk40wZKQ y35iu4Cdt1sQBtRP9hqRz4JE3oJTiS+K2ACRpoGwCatmQO8Anmx/fcvoD4/YPTDdIO/1 4L/Q== X-Received: by 10.68.92.194 with SMTP id co2mr63709204pbb.125.1447773923892; Tue, 17 Nov 2015 07:25:23 -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 d7sm43701843pas.31.2015.11.17.07.25.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Nov 2015 07:25:23 -0800 (PST) From: Joshua Clayton To: Mark Brown Cc: Jonathan Corbet , Adrian Remonda , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, Joshua Clayton Subject: [PATCH 4/8] Documentation/spi/spidev_test.c: output to a file Date: Tue, 17 Nov 2015 07:24:24 -0800 Message-Id: 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.4 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 --- Documentation/spi/spidev_test.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Documentation/spi/spidev_test.c b/Documentation/spi/spidev_test.c index ef812ad..273f667 100644 --- a/Documentation/spi/spidev_test.c +++ b/Documentation/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; @@ -104,6 +105,7 @@ static int unescape(char *_dst, char *_src, size_t len) static void transfer(int fd, uint8_t const *tx, size_t len) { int ret; + int out_fd; uint8_t *rx = malloc(len); struct spi_ioc_transfer tr = { .tx_buf = (unsigned long)tx, @@ -135,7 +137,22 @@ static void transfer(int fd, uint8_t const *tx, 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"); + free(rx); } @@ -147,6 +164,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 +189,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 +205,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 +227,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;