$ diff spidev_test.c.orig spidev_test.c 24a25 > #include 44a46,47 > static uint8_t word_delay; > static uint16_t pause_us; 128a132 > .word_delay_usecs = word_delay, 175c179 < printf("Usage: %s [-2348CDFHILMNORSZbdilopsv]\n", prog); --- > printf("Usage: %s [-2348CDFHILMNORSZbdwPilopsv]\n", prog); 179a184,185 > " -w --word_delay word_delay (usec)\n" > " -P --pause pause (usec)\n" 215a222,223 > { "word_delay", 1, 0, 'w' }, > { "pause", 1, 0, 'P' }, 240c248 < c = getopt_long(argc, argv, "D:s:d:b:i:o:lHOLC3ZFMNR248p:vS:I:", --- > c = getopt_long(argc, argv, "D:s:d:w:P:b:i:o:lHOLC3ZFMNR248p:vS:I:", 255a264,269 > case 'w': > word_delay = atoi(optarg); > break; > case 'P': > pause_us = atoi(optarg); > break; 403c417 < static void transfer_buf(int fd, int len) --- > static void transfer_buf(int fd, int len, uint8_t *tx_buf, uint8_t *rx_buf) 409,413c423,431 < tx = malloc(len); < if (!tx) < pabort("can't allocate tx buffer"); < for (i = 0; i < len; i++) < tx[i] = random(); --- > if (tx_buf) > tx = tx_buf; > else { > tx = malloc(len); > if (!tx) > pabort("can't allocate tx buffer"); > for (i = 0; i < len; i++) > tx[i] = random(); > } 415,417c433,439 < rx = malloc(len); < if (!rx) < pabort("can't allocate rx buffer"); --- > if (rx_buf) > rx = rx_buf; > else { > rx = malloc(len); > if (!rx) > pabort("can't allocate rx buffer"); > } 418a441,448 > if (tx_buf) { > char mp[5]; > if (len >= sizeof mp - 1) { > snprintf(mp, sizeof mp, "%04d", iterations % 1000); > memcpy(tx_buf + len - 4, mp, sizeof mp - 1); > } > } > 433,434c463,466 < free(rx); < free(tx); --- > if (!rx_buf) > free(rx); > if (!tx_buf) > free(tx); 497a530,532 > printf("delay: %u usecs\n", delay); > printf("word_delay: %u usecs\n", word_delay); > printf("pause: %u usecs\n", pause_us); 505c540,542 < --- > uint8_t *tx_buf = 0; > uint8_t *rx_buf = 0; > 507a545,557 > if (iterations) { > int i; > > rx_buf = malloc(transfer_size); > assert(rx_buf); > tx_buf = malloc(transfer_size); > assert(tx_buf); > > for (i = 0; i < transfer_size; i++) { > tx_buf[i] = '0' + (i % 10); > } > } > 511c561 < transfer_buf(fd, transfer_size); --- > transfer_buf(fd, transfer_size, tx_buf, rx_buf); 517a568,570 > > if (pause_us) > usleep(pause_us); 520a574,578 > > if (tx_buf) > free(tx_buf); > if (rx_buf) > free(rx_buf); $