diff options
author | Adrian Remonda <adrianremonda@gmail.com> | 2015-03-10 16:12:30 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-03-10 16:49:21 -0400 |
commit | b78ce7ed54093e5e63d4f5d7cbdc3f7d42ebbd5c (patch) | |
tree | 1afb464cdca93e499fb4e00043e5d8de63df0e9c /Documentation/spi | |
parent | c517d838eb7d07bbe9507871fab3931deccff539 (diff) |
spi: spidev_test: Cleaned hexadecimal dump
Signed-off-by: Adrian Remonda <adrianremonda@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'Documentation/spi')
-rw-r--r-- | Documentation/spi/spidev_test.c | 35 |
1 files 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 @@ | |||
15 | #include <unistd.h> | 15 | #include <unistd.h> |
16 | #include <stdio.h> | 16 | #include <stdio.h> |
17 | #include <stdlib.h> | 17 | #include <stdlib.h> |
18 | #include <string.h> | ||
18 | #include <getopt.h> | 19 | #include <getopt.h> |
19 | #include <fcntl.h> | 20 | #include <fcntl.h> |
20 | #include <sys/ioctl.h> | 21 | #include <sys/ioctl.h> |
@@ -35,6 +36,33 @@ static uint8_t bits = 8; | |||
35 | static uint32_t speed = 500000; | 36 | static uint32_t speed = 500000; |
36 | static uint16_t delay; | 37 | static uint16_t delay; |
37 | 38 | ||
39 | static void hex_dump(const void *src, size_t length, size_t line_size, char *prefix) | ||
40 | { | ||
41 | int i = 0; | ||
42 | const unsigned char *address = src; | ||
43 | const unsigned char *line = address; | ||
44 | unsigned char c; | ||
45 | |||
46 | printf("%s | ", prefix); | ||
47 | while (length-- > 0) { | ||
48 | printf("%02X ", *address++); | ||
49 | if (!(++i % line_size) || (length == 0 && i % line_size)) { | ||
50 | if (length == 0) { | ||
51 | while (i++ % line_size) | ||
52 | printf("__ "); | ||
53 | } | ||
54 | printf(" | "); /* right close */ | ||
55 | while (line < address) { | ||
56 | c = *line++; | ||
57 | printf("%c", (c < 33 || c == 255) ? 0x2E : c); | ||
58 | } | ||
59 | printf("\n"); | ||
60 | if (length > 0) | ||
61 | printf("%s | ", prefix); | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | |||
38 | static void transfer(int fd) | 66 | static void transfer(int fd) |
39 | { | 67 | { |
40 | int ret; | 68 | int ret; |
@@ -76,12 +104,7 @@ static void transfer(int fd) | |||
76 | if (ret < 1) | 104 | if (ret < 1) |
77 | pabort("can't send spi message"); | 105 | pabort("can't send spi message"); |
78 | 106 | ||
79 | for (ret = 0; ret < ARRAY_SIZE(tx); ret++) { | 107 | hex_dump(rx, ARRAY_SIZE(rx), 32, "RX"); |
80 | if (!(ret % 6)) | ||
81 | puts(""); | ||
82 | printf("%.2X ", rx[ret]); | ||
83 | } | ||
84 | puts(""); | ||
85 | } | 108 | } |
86 | 109 | ||
87 | static void print_usage(const char *prog) | 110 | static void print_usage(const char *prog) |