Lines Matching +full:tx +full:- +full:output +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0-only
8 * Cross-compile with cross-gcc -I/path/to/cross-kernel/include
39 static uint32_t mode; variable
71 while (length-- > 0) { in hex_dump()
91 * Unescape - process hexadecimal escape character
92 * converts shell input "\x23" -> 0x23
118 static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len) in transfer() argument
123 .tx_buf = (unsigned long)tx, in transfer()
131 if (mode & SPI_TX_OCTAL) in transfer()
133 else if (mode & SPI_TX_QUAD) in transfer()
135 else if (mode & SPI_TX_DUAL) in transfer()
137 if (mode & SPI_RX_OCTAL) in transfer()
139 else if (mode & SPI_RX_QUAD) in transfer()
141 else if (mode & SPI_RX_DUAL) in transfer()
143 if (!(mode & SPI_LOOP)) { in transfer()
144 if (mode & (SPI_TX_OCTAL | SPI_TX_QUAD | SPI_TX_DUAL)) in transfer()
146 else if (mode & (SPI_RX_OCTAL | SPI_RX_QUAD | SPI_RX_DUAL)) in transfer()
155 hex_dump(tx, len, 32, "TX"); in transfer()
160 pabort("could not open output file"); in transfer()
164 pabort("not all bytes written to output file"); in transfer()
175 printf("Usage: %s [-DsbdlHOLC3vpNR24SI]\n", prog); in print_usage()
176 puts(" -D --device device to use (default /dev/spidev1.1)\n" in print_usage()
177 " -s --speed max speed (Hz)\n" in print_usage()
178 " -d --delay delay (usec)\n" in print_usage()
179 " -b --bpw bits per word\n" in print_usage()
180 " -i --input input data from a file (e.g. \"test.bin\")\n" in print_usage()
181 " -o --output output data to a file (e.g. \"results.bin\")\n" in print_usage()
182 " -l --loop loopback\n" in print_usage()
183 " -H --cpha clock phase\n" in print_usage()
184 " -O --cpol clock polarity\n" in print_usage()
185 " -L --lsb least significant bit first\n" in print_usage()
186 " -C --cs-high chip select active high\n" in print_usage()
187 " -3 --3wire SI/SO signals shared\n" in print_usage()
188 " -v --verbose Verbose (show tx buffer)\n" in print_usage()
189 " -p Send data (e.g. \"1234\\xde\\xad\")\n" in print_usage()
190 " -N --no-cs no chip select\n" in print_usage()
191 " -R --ready slave pulls low to pause\n" in print_usage()
192 " -2 --dual dual transfer\n" in print_usage()
193 " -4 --quad quad transfer\n" in print_usage()
194 " -8 --octal octal transfer\n" in print_usage()
195 " -S --size transfer size\n" in print_usage()
196 " -I --iter iterations\n"); in print_usage()
209 { "output", 1, 0, 'o' }, in parse_opts()
214 { "cs-high", 0, 0, 'C' }, in parse_opts()
216 { "no-cs", 0, 0, 'N' }, in parse_opts()
231 if (c == -1) in parse_opts()
254 mode |= SPI_LOOP; in parse_opts()
257 mode |= SPI_CPHA; in parse_opts()
260 mode |= SPI_CPOL; in parse_opts()
263 mode |= SPI_LSB_FIRST; in parse_opts()
266 mode |= SPI_CS_HIGH; in parse_opts()
269 mode |= SPI_3WIRE; in parse_opts()
272 mode |= SPI_NO_CS; in parse_opts()
278 mode |= SPI_READY; in parse_opts()
284 mode |= SPI_TX_DUAL; in parse_opts()
287 mode |= SPI_TX_QUAD; in parse_opts()
290 mode |= SPI_TX_OCTAL; in parse_opts()
302 if (mode & SPI_LOOP) { in parse_opts()
303 if (mode & SPI_TX_DUAL) in parse_opts()
304 mode |= SPI_RX_DUAL; in parse_opts()
305 if (mode & SPI_TX_QUAD) in parse_opts()
306 mode |= SPI_RX_QUAD; in parse_opts()
307 if (mode & SPI_TX_OCTAL) in parse_opts()
308 mode |= SPI_RX_OCTAL; in parse_opts()
315 uint8_t *tx; in transfer_escaped_string() local
318 tx = malloc(size); in transfer_escaped_string()
319 if (!tx) in transfer_escaped_string()
320 pabort("can't allocate tx buffer"); in transfer_escaped_string()
326 size = unescape((char *)tx, str, size); in transfer_escaped_string()
327 transfer(fd, tx, rx, size); in transfer_escaped_string()
329 free(tx); in transfer_escaped_string()
337 uint8_t *tx; in transfer_file() local
340 if (stat(filename, &sb) == -1) in transfer_file()
347 tx = malloc(sb.st_size); in transfer_file()
348 if (!tx) in transfer_file()
349 pabort("can't allocate tx buffer"); in transfer_file()
355 bytes = read(tx_fd, tx, sb.st_size); in transfer_file()
359 transfer(fd, tx, rx, sb.st_size); in transfer_file()
361 free(tx); in transfer_file()
373 rx_rate = ((_read_count - prev_read_count) * 8) / (interval*1000.0); in show_transfer_rate()
374 tx_rate = ((_write_count - prev_write_count) * 8) / (interval*1000.0); in show_transfer_rate()
376 printf("rate: tx %.1fkbps, rx %.1fkbps\n", rx_rate, tx_rate); in show_transfer_rate()
384 uint8_t *tx; in transfer_buf() local
388 tx = malloc(len); in transfer_buf()
389 if (!tx) in transfer_buf()
390 pabort("can't allocate tx buffer"); in transfer_buf()
392 tx[i] = random(); in transfer_buf()
398 transfer(fd, tx, rx, len); in transfer_buf()
403 if (mode & SPI_LOOP) { in transfer_buf()
404 if (memcmp(tx, rx, len)) { in transfer_buf()
406 hex_dump(tx, len, 32, "TX"); in transfer_buf()
413 free(tx); in transfer_buf()
425 pabort("only one of -p and --input may be selected"); in main()
432 * spi mode in main()
434 /* WR is make a request to assign 'mode' */ in main()
435 request = mode; in main()
436 ret = ioctl(fd, SPI_IOC_WR_MODE32, &mode); in main()
437 if (ret == -1) in main()
438 pabort("can't set spi mode"); in main()
440 /* RD is read what mode the device actually is in */ in main()
441 ret = ioctl(fd, SPI_IOC_RD_MODE32, &mode); in main()
442 if (ret == -1) in main()
443 pabort("can't get spi mode"); in main()
444 /* Drivers can reject some mode bits without returning an error. in main()
445 * Read the current value to identify what mode it is in, and if it in main()
446 * differs from the requested mode, warn the user. in main()
448 if (request != mode) in main()
449 printf("WARNING device does not support requested mode 0x%x\n", in main()
456 if (ret == -1) in main()
460 if (ret == -1) in main()
467 if (ret == -1) in main()
471 if (ret == -1) in main()
474 printf("spi mode: 0x%x\n", mode); in main()
487 while (iterations-- > 0) { in main()
493 if (current.tv_sec - last_stat.tv_sec > interval) { in main()
498 printf("total: tx %.1fKB, rx %.1fKB\n", in main()