From patchwork Tue Mar 10 20:12:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: adrianremonda@gmail.com X-Patchwork-Id: 5980451 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 8D588BF6C3 for ; Tue, 10 Mar 2015 20:14:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BCCBA20251 for ; Tue, 10 Mar 2015 20:14:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D5E2F2024D for ; Tue, 10 Mar 2015 20:14:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753294AbbCJUMq (ORCPT ); Tue, 10 Mar 2015 16:12:46 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:35801 "EHLO mail-wi0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752772AbbCJUMn (ORCPT ); Tue, 10 Mar 2015 16:12:43 -0400 Received: by wibbs8 with SMTP id bs8so33337387wib.0; Tue, 10 Mar 2015 13:12:41 -0700 (PDT) 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; bh=lsPgJmS9OPU4bFv/YGEzgVNoufX7SKbDn4/LII8TYo4=; b=fGBCIvB9jDAAJWTuCs/oQrxbFC59tKx+9WzQwk5nTae2e741JX1ha3b4KzPvp90nyF yvSgOSWT+t7NyLGURhhxHuE5SGIYoqnPNRro1j9hn4M97zEMFMj+XrRWl35nwzMrSEVW YoJtK/0aBKT9teoeYHWpYRctH5+HAm0QDqQRcPUfxMR0K1fdvNxzNYsFpUvvowmMOn3p 2E6+dzw+0kd+RL9uRqmM8ro06dx/4vh90c5u1KzJR16o0wDMtav0XFPcVOAEf6/nlKp0 8sUsD4bOH7dLW2qgIvkF6zD1kx3RZORtJPUksXvm1OX8CQN6uQhHXgspA/RBcjvE/3hG lIDA== X-Received: by 10.180.19.9 with SMTP id a9mr73440719wie.85.1426018361470; Tue, 10 Mar 2015 13:12:41 -0700 (PDT) Received: from debian.fh-joanneum.at (fh.fh-joanneum.at. [91.229.57.240]) by mx.google.com with ESMTPSA id b4sm21758630wic.2.2015.03.10.13.12.39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Mar 2015 13:12:40 -0700 (PDT) From: Adrian Remonda Cc: adrianremonda@gmail.com, broonie@kernel.org, corbet@lwn.net, linux-spi@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCHv2 1/4] Cleaned hexadecimal dump Date: Tue, 10 Mar 2015 16:12:30 -0400 Message-Id: <1426018353-13442-2-git-send-email-adrianremonda@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1426018353-13442-1-git-send-email-adrianremonda@gmail.com> References: <1426018353-13442-1-git-send-email-adrianremonda@gmail.com> To: unlisted-recipients:; (no To-header on input) Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 v2: Fixed coding style and removed unnecessary castings As noted by Geert Uytterhoeven and Mark Brown modified: Documentation/spi/spidev_test.c Signed-off-by: Adrian Remonda --- Documentation/spi/spidev_test.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/Documentation/spi/spidev_test.c b/Documentation/spi/spidev_test.c index 3a2f9d59edab..9cb09184a3d6 100644 --- a/Documentation/spi/spidev_test.c +++ b/Documentation/spi/spidev_test.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,33 @@ static uint8_t bits = 8; static uint32_t speed = 500000; static uint16_t delay; +static void hex_dump(const void *src, size_t length, size_t line_size, char *prefix) +{ + int i = 0; + const unsigned char *address = src; + const unsigned char *line = address; + unsigned char c; + + printf("%s | ", prefix); + while (length-- > 0) { + printf("%02X ", *address++); + if (!(++i % line_size) || (length == 0 && i % line_size)) { + if (length == 0) { + while (i++ % line_size) + printf("__ "); + } + printf(" | "); /* right close */ + while (line < address) { + c = *line++; + printf("%c", (c < 33 || c == 255) ? 0x2E : c); + } + printf("\n"); + if (length > 0) + printf("%s | ", prefix); + } + } +} + static void transfer(int fd) { int ret; @@ -76,12 +104,7 @@ static void transfer(int fd) if (ret < 1) pabort("can't send spi message"); - for (ret = 0; ret < ARRAY_SIZE(tx); ret++) { - if (!(ret % 6)) - puts(""); - printf("%.2X ", rx[ret]); - } - puts(""); + hex_dump(rx, ARRAY_SIZE(rx), 32, "RX"); } static void print_usage(const char *prog)