add (broken) isochronous support...
This commit is contained in:
parent
b497b17d2a
commit
d85f07f25c
|
@ -1,3 +1,3 @@
|
|||
|
||||
benchmark: benchmark.o
|
||||
$(CC) $(LDLAGS) -lusb-1.0 -o $@ $^
|
||||
$(CC) $(LDLAGS) -losmocore -lusb-1.0 -o $@ $^
|
||||
|
|
|
@ -7,12 +7,15 @@
|
|||
#include <signal.h>
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
|
||||
|
||||
#define EP_DATA_IN 0x82
|
||||
#define EP_ISO_IN 0x86
|
||||
|
||||
static struct libusb_device_handle *devh = NULL;
|
||||
|
||||
static unsigned int num_bytes = 0, num_xfer = 0;
|
||||
static unsigned long num_bytes = 0, num_xfer = 0;
|
||||
static struct timeval tv_start;
|
||||
|
||||
static void cb_xfr(struct libusb_transfer *xfr)
|
||||
|
@ -23,8 +26,23 @@ static void cb_xfr(struct libusb_transfer *xfr)
|
|||
exit(3);
|
||||
}
|
||||
|
||||
//printf("length:%u, actual_length:%u\n", xfr->length, xfr->actual_length);
|
||||
num_bytes += xfr->length;
|
||||
if (xfr->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) {
|
||||
int i;
|
||||
for (i = 0; i < xfr->num_iso_packets; i++) {
|
||||
struct libusb_iso_packet_descriptor *pack = &xfr->iso_packet_desc[i];
|
||||
|
||||
if (pack->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
fprintf(stderr, "Error: pack %u status %d\n", i, pack->status);
|
||||
exit(5);
|
||||
}
|
||||
|
||||
printf("pack%u length:%u, actual_length:%u\n", i, pack->length, pack->actual_length);
|
||||
}
|
||||
}
|
||||
|
||||
printf("length:%u, actual_length:%u\n", xfr->length, xfr->actual_length);
|
||||
printf("%s\n", osmo_hexdump(xfr->buffer, xfr->actual_length));
|
||||
num_bytes += xfr->actual_length;
|
||||
num_xfer++;
|
||||
|
||||
if (libusb_submit_transfer(xfr) < 0) {
|
||||
|
@ -34,16 +52,25 @@ static void cb_xfr(struct libusb_transfer *xfr)
|
|||
|
||||
}
|
||||
|
||||
static int benchmark_in(void)
|
||||
static int benchmark_in(uint8_t ep)
|
||||
{
|
||||
static uint8_t buf[2048];
|
||||
static struct libusb_transfer *xfr;
|
||||
int num_iso_pack = 0;
|
||||
|
||||
xfr = libusb_alloc_transfer(0);
|
||||
if (ep == EP_ISO_IN)
|
||||
num_iso_pack = 16;
|
||||
|
||||
xfr = libusb_alloc_transfer(num_iso_pack);
|
||||
if (!xfr)
|
||||
return -ENOMEM;
|
||||
|
||||
libusb_fill_bulk_transfer(xfr, devh, EP_DATA_IN, buf,
|
||||
if (ep == EP_ISO_IN) {
|
||||
libusb_fill_iso_transfer(xfr, devh, ep, buf,
|
||||
sizeof(buf), num_iso_pack, cb_xfr, NULL, 0);
|
||||
libusb_set_iso_packet_lengths(xfr, sizeof(buf)/num_iso_pack);
|
||||
} else
|
||||
libusb_fill_bulk_transfer(xfr, devh, ep, buf,
|
||||
sizeof(buf), cb_xfr, NULL, 0);
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
|
@ -60,7 +87,7 @@ static void measure(void)
|
|||
diff_msec = (tv_stop.tv_sec - tv_start.tv_sec)*1000;
|
||||
diff_msec += (tv_stop.tv_usec - tv_start.tv_usec)/1000;
|
||||
|
||||
printf("%u transfers (total %u bytes) in %u miliseconds => %u bytes/sec\n",
|
||||
printf("%u transfers (total %u bytes) in %u miliseconds => %lu bytes/sec\n",
|
||||
num_xfer, num_bytes, diff_msec, (num_bytes*1000)/diff_msec);
|
||||
}
|
||||
|
||||
|
@ -92,13 +119,13 @@ int main(int argc, char **argv)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
rc = libusb_claim_interface(devh, 0);
|
||||
rc = libusb_claim_interface(devh, 2);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Error claiming interface\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
benchmark_in();
|
||||
benchmark_in(EP_ISO_IN);
|
||||
|
||||
while (1) {
|
||||
libusb_handle_events(NULL);
|
||||
|
|
Loading…
Reference in New Issue