Hi there,

Here's the code and output of my test. I'm trying to understand what's going 
wrong! I mean that I'm expecting the callback function "cb_xfr" from my bulk 
transfer to be called after libusb_submit_transfer is called. I'm communicating 
to a FPGA through a Cypress USB (FX2) and It's working with the synchronous API 
but not yet with the Asynchronous one??? I have put the usbmon output that I'm 
still reading and learning about it. If you see something let me know!

thx,

- KA
ps: code inspiration to do that test was from:
http://git.gnumonks.org/cgi-bin/gitweb.cgi?p=sam3u-tests.git;a=blob;f=usb-benchmark-project/host/benchmark.c



Here my test:


#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <errno.h>
#include <signal.h>

#include <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 long num_bytes = 0, num_xfer = 0;
static struct timeval tv_start;

static void cb_xfr(struct libusb_transfer *xfr)
{
        if (xfr->status != LIBUSB_TRANSFER_COMPLETED) {
                fprintf(stderr, "--> transfer status %d\n", xfr->status);
                libusb_free_transfer(xfr);
                exit(3);
        }

        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) {
                fprintf(stderr, "-->error re-submitting URB\n");
                exit(1);
        }

}

static int benchmark_in(uint8_t ep)
{
        static uint8_t buf[6] = {0x2,0xa0,0x3c,0x23,0x3,0x0};
        static struct libusb_transfer *xfr;
        int num_iso_pack = 0;

        xfr = libusb_alloc_transfer(num_iso_pack);
        if (!xfr)
                return -ENOMEM;

        libusb_fill_bulk_transfer(xfr, devh, ep, buf,
                                sizeof(buf), cb_xfr, NULL, 0);

        gettimeofday(&tv_start, NULL);
        printf("-->SUBMIT length:%d\n", sizeof(buf));
        return libusb_submit_transfer(xfr);
}

static void measure(void)
{
        struct timeval tv_stop;
        unsigned int diff_msec;

        gettimeofday(&tv_stop, NULL);

        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 => %lu 
bytes/sec\n",
                num_xfer, num_bytes, diff_msec, (num_bytes*1000)/diff_msec);
}

static void sig_hdlr(int signum)
{
        switch (signum) {
        case SIGINT:
                measure();
                exit(0);
                break;
        }
}

int main(int argc, char **argv)
{
        int rc;

        signal(SIGINT, &sig_hdlr);

        rc = libusb_init(NULL);
        if (rc < 0) {
                fprintf(stderr, "--> Error initializing libusb\n");
                exit(1);
        }

        devh = libusb_open_device_with_vid_pid(NULL, 0x09FB, 0x6001);
        if (!devh) {
                fprintf(stderr, "--> Error finding USB device\n");
                exit(1);
        }

        rc = libusb_claim_interface(devh, 1);
        if (rc < 0) {
                fprintf(stderr, "--> Error claiming interface\n");
                exit(1);
        }

        
        rc = libusb_set_interface_alt_setting(devh, 1, 0);
        if (rc < 0)
        {
                fprintf(stderr, "--> Error alt setting\n");
                exit(1);
        }

        
        unsigned char reply[2];
        rc = libusb_control_transfer(devh,
                                                                 
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN,
                                                                 0x93,
                                                                 0,
                                                                 0,
                                                                 reply,
                                                                 sizeof(reply),
                                                                 2000);
        if (rc < 0)
        {
                fprintf(stderr, "--> Error control sync\n");
                exit(1);
        }

        rc = libusb_control_transfer(devh,
                                                                 
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN,
                                                                 0x95,
                                                                 0,
                                                                 1,
                                                                 reply,
                                                                 sizeof(reply),
                                                                 2000);
        if (rc < 0)
        {
                fprintf(stderr, "--> Error control zero length packet\n");
                exit(1);
        }

        libusb_clear_halt(devh, 0x06);
        libusb_clear_halt(devh, 0x88);

        benchmark_in(0x88);

int idx = 0;
struct timeval tv = {5,0};
        while (1) {
                printf("--> handle_event: %d\n", idx);
                libusb_handle_events_timeout(NULL, &tv);
                idx++;
        }

}


Here my libusb log:


./benchmark 
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000107] [00003bbb] libusbx: debug [libusb_init] created default context
[ 0.001361] [00003bbb] libusbx: debug [libusb_init] libusbx v1.0.12.10532
[ 0.001563] [00003bbb] libusbx: debug [find_usbfs_path] found usbfs at 
/dev/bus/usb
[ 0.001761] [00003bbb] libusbx: debug [op_init] bulk continuation flag supported
[ 0.001887] [00003bbb] libusbx: debug [op_init] zero length packet flag 
supported
[ 0.002039] [00003bbb] libusbx: debug [op_init] found usb devices in sysfs
[ 0.002438] [00003bbb] libusbx: debug [usbi_add_pollfd] add fd 3 events 1
[ 0.002671] [00003bbb] libusbx: debug [usbi_io_init] using timerfd for timeouts
[ 0.002757] [00003bbb] libusbx: debug [usbi_add_pollfd] add fd 5 events 1
[ 0.002849] [00003bbb] libusbx: debug [libusb_get_device_list] 
[ 0.002931] [00003bbb] libusbx: debug [sysfs_scan_device] scan usb1
[ 0.003143] [00003bbb] libusbx: debug [sysfs_scan_device] bus=1 dev=1
[ 0.003238] [00003bbb] libusbx: debug [enumerate_device] busnum 1 devaddr 1 
session_id 257
[ 0.003326] [00003bbb] libusbx: debug [enumerate_device] allocating new device 
for 1/1 (session 257)
[ 0.003502] [00003bbb] libusbx: debug [sysfs_scan_device] scan usb2
[ 0.003674] [00003bbb] libusbx: debug [sysfs_scan_device] bus=2 dev=1
[ 0.004097] [00003bbb] libusbx: debug [enumerate_device] busnum 2 devaddr 1 
session_id 513
[ 0.004373] [00003bbb] libusbx: debug [enumerate_device] allocating new device 
for 2/1 (session 513)
[ 0.004530] [00003bbb] libusbx: debug [sysfs_scan_device] scan 1-1
[ 0.004706] [00003bbb] libusbx: debug [sysfs_scan_device] bus=1 dev=9
[ 0.004899] [00003bbb] libusbx: debug [enumerate_device] busnum 1 devaddr 9 
session_id 265
[ 0.004990] [00003bbb] libusbx: debug [enumerate_device] allocating new device 
for 1/9 (session 265)
[ 0.005137] [00003bbb] libusbx: debug [sysfs_scan_device] scan 2-1
[ 0.005475] [00003bbb] libusbx: debug [sysfs_scan_device] bus=2 dev=2
[ 0.005691] [00003bbb] libusbx: debug [enumerate_device] busnum 2 devaddr 2 
session_id 514
[ 0.005779] [00003bbb] libusbx: debug [enumerate_device] allocating new device 
for 2/2 (session 514)
[ 0.006155] [00003bbb] libusbx: debug [sysfs_scan_device] scan 2-2
[ 0.006595] [00003bbb] libusbx: debug [sysfs_scan_device] bus=2 dev=3
[ 0.006799] [00003bbb] libusbx: debug [enumerate_device] busnum 2 devaddr 3 
session_id 515
[ 0.006886] [00003bbb] libusbx: debug [enumerate_device] allocating new device 
for 2/3 (session 515)
[ 0.007044] [00003bbb] libusbx: debug [sysfs_scan_device] scan 2-2.1
[ 0.007217] [00003bbb] libusbx: debug [sysfs_scan_device] bus=2 dev=4
[ 0.007308] [00003bbb] libusbx: debug [enumerate_device] busnum 2 devaddr 4 
session_id 516
[ 0.007393] [00003bbb] libusbx: debug [enumerate_device] allocating new device 
for 2/4 (session 516)
[ 0.007554] [00003bbb] libusbx: debug [libusb_get_device_descriptor] 
[ 0.007633] [00003bbb] libusbx: debug [libusb_get_device_descriptor] 
[ 0.007706] [00003bbb] libusbx: debug [libusb_get_device_descriptor] 
[ 0.007931] [00003bbb] libusbx: debug [libusb_open] open 1.9
[ 0.008255] [00003bbb] libusbx: debug [op_open] opening /dev/bus/usb/001/009
[ 0.008370] [00003bbb] libusbx: debug [usbi_add_pollfd] add fd 6 events 4
[ 0.008477] [00003bbb] libusbx: debug [libusb_unref_device] destroy device 1.1
[ 0.008564] [00003bbb] libusbx: debug [libusb_unref_device] destroy device 2.1
[ 0.008649] [00003bbb] libusbx: debug [libusb_unref_device] destroy device 2.2
[ 0.008733] [00003bbb] libusbx: debug [libusb_unref_device] destroy device 2.3
[ 0.008817] [00003bbb] libusbx: debug [libusb_unref_device] destroy device 2.4
[ 0.008902] [00003bbb] libusbx: debug [libusb_claim_interface] interface 1
[ 0.009000] [00003bbb] libusbx: debug [libusb_set_interface_alt_setting] 
interface 1 altsetting 0
[ 0.069673] [00003bbb] libusbx: debug [libusb_submit_transfer] arm timerfd for 
timeout in 2000ms (first in line)
[ 0.070272] [00003bbb] libusbx: debug [libusb_handle_events_timeout_completed] 
doing our own event handling
[ 0.070433] [00003bbb] libusbx: debug [handle_events] poll() 3 fds with timeout 
in 60000ms
[ 0.070883] [00003bbb] libusbx: debug [handle_events] poll() returned 1
[ 0.071045] [00003bbb] libusbx: debug [reap_for_handle] urb type=2 status=0 
transferred=1
[ 0.071192] [00003bbb] libusbx: debug [handle_control_completion] handling 
completion status 0
[ 0.071337] [00003bbb] libusbx: debug [disarm_timerfd] 
[ 0.071436] [00003bbb] libusbx: debug [usbi_handle_transfer_completion] 
transfer 0x1a85338 has callback 0x7f633a213950
[ 0.071581] [00003bbb] libusbx: debug [ctrl_transfer_cb] actual_length=1
[ 0.071802] [00003bbb] libusbx: debug [libusb_submit_transfer] arm timerfd for 
timeout in 2000ms (first in line)
[ 0.071955] [00003bbb] libusbx: debug [libusb_handle_events_timeout_completed] 
doing our own event handling
[ 0.072101] [00003bbb] libusbx: debug [handle_events] poll() 3 fds with timeout 
in 60000ms
[ 0.073310] [00003bbb] libusbx: debug [handle_events] poll() returned 1
[ 0.073475] [00003bbb] libusbx: debug [reap_for_handle] urb type=2 status=0 
transferred=0
[ 0.073620] [00003bbb] libusbx: debug [handle_control_completion] handling 
completion status 0
[ 0.073765] [00003bbb] libusbx: debug [disarm_timerfd] 
[ 0.073864] [00003bbb] libusbx: debug [usbi_handle_transfer_completion] 
transfer 0x1a85338 has callback 0x7f633a213950
[ 0.074011] [00003bbb] libusbx: debug [ctrl_transfer_cb] actual_length=0
[ 0.074159] [00003bbb] libusbx: debug [libusb_clear_halt] endpoint 6
[ 0.076378] [00003bbb] libusbx: debug [libusb_clear_halt] endpoint 88
-->SUBMIT length:6
[ 0.078855] [00003bbb] libusbx: debug [submit_bulk_transfer] need 1 urbs for 
new transfer with length 6
--> handle_event: 0
[ 0.079206] [00003bbb] libusbx: debug [libusb_handle_events_timeout_completed] 
doing our own event handling
[ 0.079337] [00003bbb] libusbx: debug [handle_events] poll() 3 fds with timeout 
in 5000ms
[ 5.082531] [00003bbb] libusbx: debug [handle_events] poll() returned 0
--> handle_event: 1
[ 5.082636] [00003bbb] libusbx: debug [libusb_handle_events_timeout_completed] 
doing our own event handling
[ 5.082655] [00003bbb] libusbx: debug [handle_events] poll() 3 fds with timeout 
in 5000ms
^C--> 0 transfers (total 0 bytes) in 7384 miliseconds => 0 bytes/sec



Here my usbmon output:



ffff880058933c80 3954922941 S Co:1:009:0 s 01 0b 0000 0001 0000 0
ffff880058933c80 3954983094 C Co:1:009:0 0 0
ffff880058933c80 3954983478 S Ci:1:009:0 s c0 93 0000 0000 0002 2 <
ffff880058933c80 3954984665 C Ci:1:009:0 0 1 = 00
ffff880058933c80 3954985612 S Ci:1:009:0 s c0 95 0000 0001 0002 2 <
ffff880058933c80 3954987090 C Ci:1:009:0 0 0
ffff880058933c80 3954988157 S Co:1:009:0 s 02 01 0000 0006 0000 0
ffff880058933c80 3954989809 C Co:1:009:0 0 0
ffff880058933c80 3954990803 S Co:1:009:0 s 02 01 0000 0088 0000 0
ffff880058933c80 3954992269 C Co:1:009:0 0 0
ffff880058933c80 3954992935 S Bi:1:009:8 -115 6 <
ffff880058933c80 3962377183 C Bi:1:009:8 -108 0
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to