Menu

#79 usb_interrupt_write occasionally sends the same data twice

v1.2.x
closed
nobody
None
5
2018-08-31
2012-03-15
No

I can reproduce this easily if I call usb_interrupt_write in a tight loop. I'm sending 13 byte packets with an incrementing sequence number and crc32. My USB sniffer sees two of them go out. If I sleep 4ms between calls to usb_interrupt_write, it can send thousands of packets correctly without sending duplicate data. I've attached a USB trace from TotalPhase

This packet appears twice on OUT
07 00 06 00 09 93 F4 FD
06 B6 27 E5 A6

The USB device is setup to echo every packet it receives.

I'm reading and writing the usb device from different threads. Here is the code for the writer thread (to try to illustrate that it's unlikely/impossible that I'm sending the same packet twice.)

unsigned writer( void * udev_void )
{
struct usb_dev_handle udev = (struct usb_dev_handle)udev_void;

RingBuffer_t tx;
uint8_t tx_data[256];

DWORD    last_update = timeGetTime();
uint16_t tx_sequence_number = 0;
uint16_t sent_since_last_update = 0;
Sleep(1000); // wait for the reader thread to get started
while(1)
{
    RingBuffer_InitBuffer(&tx,tx_data,sizeof(tx_data));

    write_ude_message( &tx, tx_sequence_number, MESSAGE_ID_ECHO_REQUEST, (const uint8_t*)&g_time, sizeof(g_time) );

    while ( RingBuffer_GetCount(&tx) )
    {
        int ret = usb_interrupt_write(
            udev,
            4, //epWrite,
            (char*)tx.Out,
            RingBuffer_GetCount(&tx),
            1000);
        if ( ret > 0 )
        {
            RingBuffer_Remove_Array(&tx,0,ret);
        }
    }

    tx_sequence_number++;
    sent_since_last_update++;
    DWORD elapsed = timeGetTime() - last_update;
    if ( elapsed > 2000 )
    {
        printf("%i sent (%i)\n", sent_since_last_update, tx_sequence_number );
        last_update = timeGetTime();
        sent_since_last_update = 0;
    }
    //Sleep(1);
}
return 0;

}

Discussion

  • Vince Harron

    Vince Harron - 2012-03-15

    USB trace

     
  • Vince Harron

    Vince Harron - 2012-03-15

    version 1.2.6

     
  • Xiaofan Chen

    Xiaofan Chen - 2012-06-01

    Please use the mailing list to post more details. Thanks. testlibusb-win.exe output should be helpful. DebugView debug log using the debug version of the driver should help as well.

     
  • Xiaofan Chen

    Xiaofan Chen - 2018-08-31

    Closing old entry. Please use libusb-win32 mailing list for future discussions.

     
  • Xiaofan Chen

    Xiaofan Chen - 2018-08-31
    • status: open --> closed
    • Group: --> v1.2.x
     

Log in to post a comment.