• AVR Freaks

Question regarding the generic hid

Author
hobz
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2008/03/28 08:32:48
  • Location: 0
  • Status: offline
2008/05/12 03:48:38 (permalink)
0

Question regarding the generic hid

I have downloaded the new generic hid.
It echoes any input it receives from the host.

I have read that FS USB communicates data in frames, and that a new frame begins every 1 ms.

Assuming that I run HID at full-speed, is the echo received at the host with 1 ms delay or 2 ms delay?
That is, 1 ms frame for the data to be sent from the host, and received by the device (the PIC), and another millisecond for the PIC to send data and the host to receive. Or is the data simply exchanged over 1 ms frame?

Thanks!

#1

7 Replies Related Threads

    RoDeNtJe
    Senior Member
    • Total Posts : 149
    • Reward points : 0
    • Joined: 2007/06/16 02:04:54
    • Location: Belgium
    • Status: offline
    RE: Question regarding the generic hid 2008/05/12 07:04:13 (permalink)
    0
    Hi,
     
    The echoing is as follows: the host writes some data to an interrupt OUT endpoint which is received by the receiver. You can think of an endpoint as a buffer, so there will be data in the receiver's buffer. Then the receiver reads this data and puts it in an interrupt IN endpoint. The host will poll this buffer, see that there's data in it and read the data.
     
    You can only have one interrupt transfer for a given endpoint per frame. So the first interrupt transfer (from host to device )will consist of an OUT transaction to f.i. interrupt OUT endpoint 1. This transfer consists of a token packet (from host), data packet (from host) and handshake packet (from device). The second interrupt transfer (from device to host) will consist of an IN transaction to f.i. interrupt IN endpoint 1. This transfer consists of a token packet (from host), data packet (from device) and handshake packet (from host).
     
    Assuming the PIC reads the data fast enough out of the OUT endpoint and puts it fast enough into the IN endpoint and since the above two transactions are to two different endpoints, chance is realistic that the echoed data will be received back within the same frame. You'll also have to take into account that other interrupt/isochronous transfers might need some bandwidth as well.
     
    I'm not 100% sure of this, but this is how I think it works. I hope someone can confirm this.
     
    Best regards,
    RoDeNtJe

    It's nice to be important, but it's more important to be nice !
    #2
    hobz
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2008/03/28 08:32:48
    • Location: 0
    • Status: offline
    RE: Question regarding the generic hid 2008/05/12 22:19:36 (permalink)
    0
    I only send data from the host every 40 ms, so there should be no other traffic (of iso or int at least) going on.
    It would be nice with a confirmation of how exactly this is handled.
    I mean, what if sometimes the PIC was not able to place the data in the queue within the same timeframe, then I would have to wait 2 ms at the host before receiving the echo? I can't find any information about this in either Jan Axelson's USB/HID primer, nor the USB doc it self. I have requested access to the USB-IF, but this requeres authorization from an admin, something which I have not yet obtained.
    #3
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: Question regarding the generic hid 2008/05/13 04:44:57 (permalink)
    0
    Yes it seems that it is difficult to get an account from USB-IF forum. I tried it once but failed.
     
    As for the "exact" detail, this actually depends on the host system. Take note that the polling time will depend on the endpoint descriptor of the HID interrupt endpoint.
     
     Jan's Generic HID example -- for V2.1 stack
         /* Endpoint Descriptor */
        0x07,/*sizeof(USB_EP_DSC)*/
        USB_DESCRIPTOR_ENDPOINT,    //Endpoint Descriptor
        HID_EP | _EP_IN,                   //EndpointAddress
        _INT,                       //Attributes
        0x02,0x00,                  //size
        0x0A,                        //Interval
        /* Endpoint Descriptor */
        0x07,/*sizeof(USB_EP_DSC)*/
        USB_DESCRIPTOR_ENDPOINT,    //Endpoint Descriptor
        HID_EP | _EP_OUT,                   //EndpointAddress
        _INT,                       //Attributes
        0x02,0x00,                  //size
        0x0A                        //Interval

     
    So the polling interval is not 1ms but 10ms (http://www.usbmadesimple.co.uk/ums_4.htm). However Windows will probably use 8ms instead of 10ms.
    http://msdn.microsoft.com/en-us/library/ms793357.aspx
     
    To be sure about this, you can probably try to use a software usb sniffer first. A hardware analyser will help even more but that is more expensive.
    #4
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: Question regarding the generic hid 2008/05/13 05:05:31 (permalink)
    0
    Here is the USBSoop log by clicking "Find my device" once and "Once" using Jan's HID host application.
     
     
    1 in down n/a 0.148 GET_DESCRIPTOR_FROM_DEVICE  
    1 in up n/a 0.149 CONTROL_TRANSFER 12 01 10 01 00 00 00 08 0x00000000
    2 in down n/a 0.149 GET_DESCRIPTOR_FROM_DEVICE  
    2 in up n/a 0.151 CONTROL_TRANSFER 09 02 29 00 01 01 00 c0 0x00000000
    3 in down n/a 0.151 GET_DESCRIPTOR_FROM_DEVICE  
    3 in up n/a 0.152 CONTROL_TRANSFER 09 02 29 00 01 01 00 c0 0x00000000
    4 ??? down n/a 0.152 SELECT_CONFIGURATION  
    4 ??? up n/a 0.188 SELECT_CONFIGURATION  0x00000000
    5 out down n/a 0.188 CLASS_INTERFACE - 
    5 out up n/a 0.188 CONTROL_TRANSFER - 0x00000000
    6 in down n/a 0.188 GET_DESCRIPTOR_FROM_INTERFACE  
    6 in up n/a 0.189 CONTROL_TRANSFER 06 a0 ff 09 01 a1 01 09 0x00000000
    7 ??? down n/a 0.190 BULK_OR_INTERRUPT_TRANSFER - 
    8 ??? down n/a 0.190 BULK_OR_INTERRUPT_TRANSFER - 
    7 ??? up n/a 0.197 BULK_OR_INTERRUPT_TRANSFER ff 0c 0x00000000
    9 ??? down n/a 0.197 BULK_OR_INTERRUPT_TRANSFER - 

    10 ??? down n/a 78.117 BULK_OR_INTERRUPT_TRANSFER 01 81 
    URB Header (length: 72)
    SequenceNumber: 10
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    TransferBuffer: 0x00000002 (2) length
    0000: 01 81

    10 ??? up n/a 78.120 BULK_OR_INTERRUPT_TRANSFER - 0x00000000
    URB Header (length: 72)
    SequenceNumber: 10
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    No TransferBuffer
     
    8 ??? up n/a 78.123 BULK_OR_INTERRUPT_TRANSFER 01 81 0x00000000
    URB Header (length: 72)
    SequenceNumber: 8
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    TransferBuffer: 0x00000002 (2) length
    0000: 01 81

    11 ??? down n/a 78.124 BULK_OR_INTERRUPT_TRANSFER - 
    URB Header (length: 72)
    SequenceNumber: 11
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    No TransferBuffer

     
    So it seems to me that it indeed finish in 8ms (78.117s to 78.124s) assume that it starts at 78.117ms and finishes 1ms after 78.124s (software using 1ms as the unit).
     
    USB Snoopy Pro:
    http://sourceforge.net/projects/usbsnoop/

    Attached Image(s)


      USB_Links and libusb
    #5
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: Question regarding the generic hid 2008/05/13 05:15:23 (permalink)
    0
    The following is after I tried to hit "ONCE" twice.
     
    First time: 22.843s to 22.853s
    Second time: 22.695 to 24.701s
     
    So maybe the USB Snoopy Pro software is that accuarate anyway. But you get roughly the idea.
     
    10 ??? down n/a 22.843 BULK_OR_INTERRUPT_TRANSFER 02 82 
    URB Header (length: 72)
    SequenceNumber: 10
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    TransferBuffer: 0x00000002 (2) length
    0000: 02 82

    10 ??? up n/a 22.849 BULK_OR_INTERRUPT_TRANSFER - 0x00000000
    URB Header (length: 72)
    SequenceNumber: 10
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    No TransferBuffer
     
    8 ??? up n/a 22.853 BULK_OR_INTERRUPT_TRANSFER 02 82 0x00000000
    URB Header (length: 72)
    SequenceNumber: 8
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    TransferBuffer: 0x00000002 (2) length
    0000: 02 82

    11 ??? down n/a 22.853 BULK_OR_INTERRUPT_TRANSFER - 
    URB Header (length: 72)
    SequenceNumber: 11
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    No TransferBuffer
     
    12 ??? down n/a 24.695 BULK_OR_INTERRUPT_TRANSFER 03 83 
    URB Header (length: 72)
    SequenceNumber: 12
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    TransferBuffer: 0x00000002 (2) length
    0000: 03 83

    12 ??? up n/a 24.697 BULK_OR_INTERRUPT_TRANSFER - 0x00000000
    URB Header (length: 72)
    SequenceNumber: 12
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    No TransferBuffer
     
    9 ??? up n/a 24.701 BULK_OR_INTERRUPT_TRANSFER 03 83 0x00000000
    URB Header (length: 72)
    SequenceNumber: 9
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    TransferBuffer: 0x00000002 (2) length
    0000: 03 83

    13 ??? down n/a 24.701 BULK_OR_INTERRUPT_TRANSFER - 
    URB Header (length: 72)
    SequenceNumber: 13
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    No TransferBuffer


      USB_Links and libusb
    #6
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: Question regarding the generic hid 2008/05/13 05:29:58 (permalink)
    0
    I changed the firmware endpoint descriptor to use 1ms polling time.
     
    4 times of clicking "ONCE". In this case, it seems that the result is more like 2ms than 1ms.
     
    I guess that a hardware analyzer will help beter.
     
    10 ??? down n/a 22.052 BULK_OR_INTERRUPT_TRANSFER 01 81 
    URB Header (length: 72)
    SequenceNumber: 10
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    TransferBuffer: 0x00000002 (2) length
    0000: 01 81

    8 ??? up n/a 22.053 BULK_OR_INTERRUPT_TRANSFER 01 81 0x00000000
    URB Header (length: 72)
    SequenceNumber: 8
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    TransferBuffer: 0x00000002 (2) length
    0000: 01 81

    11 ??? down n/a 22.053 BULK_OR_INTERRUPT_TRANSFER - 
    URB Header (length: 72)
    SequenceNumber: 11
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    No TransferBuffer
     
    10 ??? up n/a 22.053 BULK_OR_INTERRUPT_TRANSFER - 0x00000000
    URB Header (length: 72)
    SequenceNumber: 10
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    No TransferBuffer
     
    12 ??? down n/a 24.193 BULK_OR_INTERRUPT_TRANSFER 02 82 
    URB Header (length: 72)
    SequenceNumber: 12
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    TransferBuffer: 0x00000002 (2) length
    0000: 02 82

    9 ??? up n/a 24.195 BULK_OR_INTERRUPT_TRANSFER 02 82 0x00000000
    URB Header (length: 72)
    SequenceNumber: 9
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    TransferBuffer: 0x00000002 (2) length
    0000: 02 82

    13 ??? down n/a 24.195 BULK_OR_INTERRUPT_TRANSFER - 
    URB Header (length: 72)
    SequenceNumber: 13
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    No TransferBuffer
     
    12 ??? up n/a 24.195 BULK_OR_INTERRUPT_TRANSFER - 0x00000000
    URB Header (length: 72)
    SequenceNumber: 12
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    No TransferBuffer
     
    14 ??? down n/a 26.666 BULK_OR_INTERRUPT_TRANSFER 03 83 
    URB Header (length: 72)
    SequenceNumber: 14
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    TransferBuffer: 0x00000002 (2) length
    0000: 03 83

    11 ??? up n/a 26.668 BULK_OR_INTERRUPT_TRANSFER 03 83 0x00000000
    URB Header (length: 72)
    SequenceNumber: 11
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    TransferBuffer: 0x00000002 (2) length
    0000: 03 83

    15 ??? down n/a 26.668 BULK_OR_INTERRUPT_TRANSFER - 
    URB Header (length: 72)
    SequenceNumber: 15
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    No TransferBuffer
     
    14 ??? up n/a 26.668 BULK_OR_INTERRUPT_TRANSFER - 0x00000000
    URB Header (length: 72)
    SequenceNumber: 14
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    No TransferBuffer
     
    16 ??? down n/a 29.040 BULK_OR_INTERRUPT_TRANSFER 04 84 
    URB Header (length: 72)
    SequenceNumber: 16
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    TransferBuffer: 0x00000002 (2) length
    0000: 04 84

    13 ??? up n/a 29.041 BULK_OR_INTERRUPT_TRANSFER 04 84 0x00000000
    URB Header (length: 72)
    SequenceNumber: 13
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    TransferBuffer: 0x00000002 (2) length
    0000: 04 84

    17 ??? down n/a 29.041 BULK_OR_INTERRUPT_TRANSFER - 
    URB Header (length: 72)
    SequenceNumber: 17
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    No TransferBuffer
     
    16 ??? up n/a 29.041 BULK_OR_INTERRUPT_TRANSFER - 0x00000000
    URB Header (length: 72)
    SequenceNumber: 16
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    No TransferBuffer
     
    18 ??? down n/a 30.950 BULK_OR_INTERRUPT_TRANSFER 05 85 
    URB Header (length: 72)
    SequenceNumber: 18
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    TransferBuffer: 0x00000002 (2) length
    0000: 05 85

    15 ??? up n/a 30.952 BULK_OR_INTERRUPT_TRANSFER 05 85 0x00000000
    URB Header (length: 72)
    SequenceNumber: 15
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    TransferBuffer: 0x00000002 (2) length
    0000: 05 85

    19 ??? down n/a 30.952 BULK_OR_INTERRUPT_TRANSFER - 
    URB Header (length: 72)
    SequenceNumber: 19
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000003
    No TransferBuffer
     
    18 ??? up n/a 30.952 BULK_OR_INTERRUPT_TRANSFER - 0x00000000
    URB Header (length: 72)
    SequenceNumber: 18
    Function: 0009 (BULK_OR_INTERRUPT_TRANSFER)
    TransferFlags: 0x00000002
    No TransferBuffer


      USB_Links and libusb
    #7
    hobz
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2008/03/28 08:32:48
    • Location: 0
    • Status: offline
    RE: Question regarding the generic hid 2008/05/13 09:35:36 (permalink)
    0
    Thanks for the analysis man! Gonna have a look at the program you posted.

    Applying the knowledge you have provided, with that provided theoretically by the USB doc, I think we can conclude that the maximum time is 2 ms, but could be made available faster. Do you agree?

    P.S. I forgot to mention I set the polling time to 1 ms, but you took care of that also!
    #8
    Jump to:
    © 2020 APG vNext Commercial Version 4.5