From patchwork Sat Mar 7 17:56:34 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: 5959901 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E4E709F380 for ; Sat, 7 Mar 2015 17:57:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0140720035 for ; Sat, 7 Mar 2015 17:57:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0ACC82015A for ; Sat, 7 Mar 2015 17:57:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752044AbbCGR5Q (ORCPT ); Sat, 7 Mar 2015 12:57:16 -0500 Received: from mail-wg0-f47.google.com ([74.125.82.47]:41968 "EHLO mail-wg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751729AbbCGR5N (ORCPT ); Sat, 7 Mar 2015 12:57:13 -0500 Received: by wghl2 with SMTP id l2so22609418wgh.8; Sat, 07 Mar 2015 09:57:11 -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; bh=XU4qRU2/l8fJWAdZ9thkw2cZV0Dg2xGCgn8tutsghgw=; b=n9OFWe5ShVEKDCiukfd1r/o6p+W3U1z0tgeW4VLWDoiQpMv3xLwJNDCivDyc99JdrF f6ArIyFBhgwKGAwI+5fglmRaIsUtLXNJd3ILPbMtV0H4u5iEuOEDYtGaVXERBb+iHO12 aWBUd/mJmlh1uot16/S7NQu5yhGpLQRA+ByeWycHKdT7orD5wHsYNILl4+TaYkT5VhIG 8mBaaMmkfa33j+bHpUUosEbz/q4+Y8PYBwj11fJMLk3y8kAcT8MTMxZKjp7ucLZhaOoA z43U6N6zWFgadLyS/XQK10miQ+fgw4gAamxfLdrh3w/qzvVFTqZw43UN+jBGoKcw0RER +HBw== X-Received: by 10.180.105.40 with SMTP id gj8mr89215600wib.67.1425751031647; Sat, 07 Mar 2015 09:57:11 -0800 (PST) Received: from debian.fh-joanneum.at (fh.fh-joanneum.at. [91.229.57.240]) by mx.google.com with ESMTPSA id lj13sm7559769wic.9.2015.03.07.09.57.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Mar 2015 09:57:10 -0800 (PST) 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: [PATCH 3/4] Added input buffer from the terminal. Date: Sat, 7 Mar 2015 12:56:34 -0500 Message-Id: <1425750995-18176-4-git-send-email-adrianremonda@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1425750995-18176-3-git-send-email-adrianremonda@gmail.com> References: <1425750995-18176-1-git-send-email-adrianremonda@gmail.com> <1425750995-18176-2-git-send-email-adrianremonda@gmail.com> <1425750995-18176-3-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 Now it is possible to send string and hexadecimal data as an input parameter modified: Documentation/spi/spidev_test.c Signed-off-by: Adrian Remonda --- Documentation/spi/spidev_test.c | 76 ++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/Documentation/spi/spidev_test.c b/Documentation/spi/spidev_test.c index a247b3dbf65a..5660cd5fd18f 100644 --- a/Documentation/spi/spidev_test.c +++ b/Documentation/spi/spidev_test.c @@ -37,6 +37,18 @@ static uint32_t speed = 500000; static uint16_t delay; static int verbose; +uint8_t default_tx[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x95, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xF0, 0x0D, +}; + +uint8_t default_rx[ARRAY_SIZE(default_tx)] = {0, }; +char *input_tx; + static void hexDump(const void *src, size_t length, size_t bLine, char *prefix) { int i = 0; @@ -64,23 +76,38 @@ static void hexDump(const void *src, size_t length, size_t bLine, char *prefix) } } -static void transfer(int fd) +/* + * Unescape - process hexadecimal escape character + * converts shell input "\x23" -> 0x23 + */ +int unespcape(char *dst, char *src, size_t len) +{ + int ret = 0; + char *pSrc = src; + char *pDst = dst; + unsigned int ch; + + while (*pSrc) { + if (*pSrc == '\\' && *(pSrc+1) == 'x') { + sscanf(pSrc + 2, "%2x", &ch); + pSrc += 4; + *pDst++ = (unsigned char)ch; + } else { + *pDst++ = *pSrc++; + } + ret++; + } + return ret; +} + +static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len) { int ret; - uint8_t tx[] = { - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x40, 0x00, 0x00, 0x00, 0x00, 0x95, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD, - 0xF0, 0x0D, - }; - uint8_t rx[ARRAY_SIZE(tx)] = {0, }; + struct spi_ioc_transfer tr = { .tx_buf = (unsigned long)tx, .rx_buf = (unsigned long)rx, - .len = ARRAY_SIZE(tx), + .len = len, .delay_usecs = delay, .speed_hz = speed, .bits_per_word = bits, @@ -106,8 +133,8 @@ static void transfer(int fd) pabort("can't send spi message"); if (verbose) - hexDump(tx, ARRAY_SIZE(tx), 32, "TX"); - hexDump(rx, ARRAY_SIZE(rx), 32, "RX"); + hexDump(tx, len, 32, "TX"); + hexDump(rx, len, 32, "RX"); } static void print_usage(const char *prog) @@ -124,6 +151,7 @@ static void print_usage(const char *prog) " -C --cs-high chip select active high\n" " -3 --3wire SI/SO signals shared\n" " -v --verbose Verbose (show tx buffer)\n" + " -p Send data (e.g. \"1234\\xde\\xad\")\n" " -N --no-cs no chip select\n" " -R --ready slave pulls low to pause\n" " -2 --dual dual transfer\n" @@ -154,7 +182,7 @@ static void parse_opts(int argc, char *argv[]) }; int c; - c = getopt_long(argc, argv, "D:s:d:b:lHOLC3NR24:v", lopts, NULL); + c = getopt_long(argc, argv, "D:s:d:b:lHOLC3NR24p:v", lopts, NULL); if (c == -1) break; @@ -199,6 +227,9 @@ static void parse_opts(int argc, char *argv[]) case 'R': mode |= SPI_READY; break; + case 'p': + input_tx = optarg; + break; case '2': mode |= SPI_TX_DUAL; break; @@ -222,6 +253,9 @@ int main(int argc, char *argv[]) { int ret = 0; int fd; + uint8_t *tx; + uint8_t *rx; + int size; parse_opts(argc, argv); @@ -266,7 +300,17 @@ int main(int argc, char *argv[]) printf("bits per word: %d\n", bits); printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000); - transfer(fd); + if (input_tx) { + size = strlen(input_tx+1); + tx = (uint8_t *)malloc(size); + rx = (uint8_t *)malloc(size); + size = unespcape((char *)tx, input_tx, size); + transfer(fd, tx, rx, size); + free(rx); + free(tx); + } else { + transfer(fd, default_tx, default_rx, sizeof(default_tx)); + } close(fd);