Lines Matching +full:rx +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;
72 while (length-- > 0) {
92 * Unescape - process hexadecimal escape character
93 * converts shell input "\x23" -> 0x23
119 static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len)
125 .rx_buf = (unsigned long)rx,
133 if (mode & SPI_TX_OCTAL)
135 else if (mode & SPI_TX_QUAD)
137 else if (mode & SPI_TX_DUAL)
139 if (mode & SPI_RX_OCTAL)
141 else if (mode & SPI_RX_QUAD)
143 else if (mode & SPI_RX_DUAL)
145 if (!(mode & SPI_LOOP)) {
146 if (mode & (SPI_TX_OCTAL | SPI_TX_QUAD | SPI_TX_DUAL))
148 else if (mode & (SPI_RX_OCTAL | SPI_RX_QUAD | SPI_RX_DUAL))
164 ret = write(out_fd, rx, len);
172 hex_dump(rx, len, 32, "RX");
177 printf("Usage: %s [-2348CDFHILMNORSZbdilopsvw]\n", prog);
179 " -D --device device to use (default /dev/spidev1.1)\n"
180 " -s --speed max speed (Hz)\n"
181 " -d --delay delay (usec)\n"
182 " -w --word-delay word delay (usec)\n"
183 " -l --loop loopback\n"
184 "spi mode:\n"
185 " -H --cpha clock phase\n"
186 " -O --cpol clock polarity\n"
187 " -F --rx-cpha-flip flip CPHA on Rx only xfer\n"
189 " -2 --dual dual transfer\n"
190 " -4 --quad quad transfer\n"
191 " -8 --octal octal transfer\n"
192 " -3 --3wire SI/SO signals shared\n"
193 " -Z --3wire-hiz high impedance turnaround\n"
195 " -i --input input data from a file (e.g. \"test.bin\")\n"
196 " -o --output output data to a file (e.g. \"results.bin\")\n"
197 " -p Send data (e.g. \"1234\\xde\\xad\")\n"
198 " -S --size transfer size\n"
199 " -I --iter iterations\n"
201 " -b --bpw bits per word\n"
202 " -L --lsb least significant bit first\n"
203 " -C --cs-high chip select active high\n"
204 " -N --no-cs no chip select\n"
205 " -R --ready slave pulls low to pause\n"
206 " -M --mosi-idle-low leave mosi line low when idle\n"
208 " -v --verbose Verbose (show tx buffer)\n");
219 { "word-delay", 1, 0, 'w' },
223 { "rx-cpha-flip", 0, 0, 'F' },
228 { "3wire-hiz", 0, 0, 'Z' },
235 { "cs-high", 0, 0, 'C' },
236 { "no-cs", 0, 0, 'N' },
238 { "mosi-idle-low", 0, 0, 'M' },
247 if (c == -1)
273 mode |= SPI_LOOP;
276 mode |= SPI_CPHA;
279 mode |= SPI_CPOL;
282 mode |= SPI_LSB_FIRST;
285 mode |= SPI_CS_HIGH;
288 mode |= SPI_3WIRE;
291 mode |= SPI_3WIRE_HIZ;
294 mode |= SPI_RX_CPHA_FLIP;
297 mode |= SPI_MOSI_IDLE_LOW;
300 mode |= SPI_NO_CS;
306 mode |= SPI_READY;
312 mode |= SPI_TX_DUAL;
315 mode |= SPI_TX_QUAD;
318 mode |= SPI_TX_OCTAL;
330 if (mode & SPI_LOOP) {
331 if (mode & SPI_TX_DUAL)
332 mode |= SPI_RX_DUAL;
333 if (mode & SPI_TX_QUAD)
334 mode |= SPI_RX_QUAD;
335 if (mode & SPI_TX_OCTAL)
336 mode |= SPI_RX_OCTAL;
344 uint8_t *rx;
350 rx = malloc(size);
351 if (!rx)
352 pabort("can't allocate rx buffer");
355 transfer(fd, tx, rx, size);
356 free(rx);
366 uint8_t *rx;
368 if (stat(filename, &sb) == -1)
379 rx = malloc(sb.st_size);
380 if (!rx)
381 pabort("can't allocate rx buffer");
387 transfer(fd, tx, rx, sb.st_size);
388 free(rx);
401 rx_rate = ((_read_count - prev_read_count) * 8) / (interval*1000.0);
402 tx_rate = ((_write_count - prev_write_count) * 8) / (interval*1000.0);
404 printf("rate: tx %.1fkbps, rx %.1fkbps\n", rx_rate, tx_rate);
413 uint8_t *rx;
422 rx = malloc(len);
423 if (!rx)
424 pabort("can't allocate rx buffer");
426 transfer(fd, tx, rx, len);
431 if (mode & SPI_LOOP) {
432 if (memcmp(tx, rx, len)) {
435 hex_dump(rx, len, 32, "RX");
440 free(rx);
453 pabort("only one of -p and --input may be selected");
460 * spi mode
462 /* WR is make a request to assign 'mode' */
463 request = mode;
464 ret = ioctl(fd, SPI_IOC_WR_MODE32, &mode);
465 if (ret == -1)
466 pabort("can't set spi mode");
468 /* RD is read what mode the device actually is in */
469 ret = ioctl(fd, SPI_IOC_RD_MODE32, &mode);
470 if (ret == -1)
471 pabort("can't get spi mode");
472 /* Drivers can reject some mode bits without returning an error.
473 * Read the current value to identify what mode it is in, and if it
474 * differs from the requested mode, warn the user.
476 if (request != mode)
477 printf("WARNING device does not support requested mode 0x%x\n",
484 if (ret == -1)
488 if (ret == -1)
495 if (ret == -1)
499 if (ret == -1)
502 printf("spi mode: 0x%x\n", mode);
515 while (iterations-- > 0) {
521 if (current.tv_sec - last_stat.tv_sec > interval) {
526 printf("total: tx %.1fKB, rx %.1fKB\n",