• AVR Freaks

USb Host and Isochronous Transfers

Author
Aussie Susan
Super Member
  • Total Posts : 3559
  • Reward points : 0
  • Joined: 2008/08/18 22:20:40
  • Location: Melbourne, Australia
  • Status: offline
2011/02/20 19:36:34 (permalink)
0

USb Host and Isochronous Transfers

I've been trying to get the USB Host software to send audio to a set of Logitech headphones. I have (heavily) modified the Audio V1 Host software to that it will work in this environment, but I finally found the stumbling block that has kept me puzzled for some weeks now.

The problem was that I wanted to send packets to the headphones at 8000SPS (which the headphones can respond to) which meant sending a 8 sample (actually 16 samples as the signal was stereo; 32 bytes as the samples were in PCM) packet every millisecond (again in accordance with the headphones capabilities). However I could not get the sound out of the headphones correctly - rather I got a 1KHz "buzz" regardless of the combination of samples and packet frequencies (I noted that my Windows XP box sent 80 samples every 10 mSec etc).

I finally tracked it down to the following line within the _USB_SetBDT function in the USB_HOST.C file:

        if (pCurrentEndpoint->bmAttributes.bfTransferType == USB_TRANSFER_TYPE_ISOCHRONOUS)
        {
            // Isochronous transfers are always the same size, though the device may choose to send less.
            currentPacketSize = pCurrentEndpoint->wMaxPacketSize;
        }
        else


(This is about line 5105 in the V2010-10-19 library distribution)

As you can see, and is reflected in the comment, the packet size sent to the device is ALWAYS the maximum packet size, regardless of the actual number of bytes in the isochronous packet.

When I changed this to send the maximum packet size in an "IN" request (device to host) where this would make sense to me and to use the actual packet size on an "OUT" request (host to device) then suddenly I get the sound coming through clearly in the headphones.

My question is: "why is this so" (to quote a person who is famous in Australia)? If there any reason why the maximum packet size should be used in an OUT request? If so, how should the packet be constructed to make sure that the device only processes the correct bytes?

Is there something ELSE that need to be done when sending audio isochronous packets as opposed to non-audio isochronous packets?

Alternatively, is this a "bug" that needs to be reported to Microchip?

Thanks

Susan
#1

2 Replies Related Threads

    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    Re:USb Host and Isochronous Transfers 2011/02/21 04:26:09 (permalink)
    0
    You are right. It's a bug of the host stack.

    _USB_SetBDT() is called from both of case TSTATE_ISOCHRONOUS_READ and case TSTATE_ISOCHRONOUS_WRITE in _USB_FindNextToken() - bus scheduler. ie. this routine is used for both of Isoc IN/OUT.

     
    C:\Microchip Solutions v2010-10-19\Microchip\USB\usb_host.c

    void _USB_SetBDT( BYTE token )
    {
        ...
        ...
        // Determine how much data we'll transfer in this packet.
        if (token == USB_TOKEN_SETUP)
        {
            ...
            ...
        }
        else
        {
            if (pCurrentEndpoint->bmAttributes.bfTransferType == USB_TRANSFER_TYPE_ISOCHRONOUS)
            {
    /*                  // <---------- these lines are revised as follows
                // Isochronous transfers are always the same size, though the device may choose to send less.
                currentPacketSize = pCurrentEndpoint->wMaxPacketSize;
    */
                        // -------------- fix start from here ------------
                if (token == USB_TOKEN_IN)
                {
                    // For Isochronous IN transactions, host allows up to wMaxPacketSize, though the device may choose to send less.
                    currentPacketSize = pCurrentEndpoint->wMaxPacketSize;
                } else {
                    // For Isochronous OUT transaction, put the size specified by the caller of this routine
                    currentPacketSize = pCurrentEndpoint->dataCount;
                }
                        // -------------- to here ------------

            }
            else
            ...
            ...


    Tsuneo
    post edited by chinzei - 2011/02/21 04:28:34
    #2
    Aussie Susan
    Super Member
    • Total Posts : 3559
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re:USb Host and Isochronous Transfers 2011/02/21 18:37:21 (permalink)
    0
    Tsuneo,

    Almost exactly the code I ended up using.

    Thanks for the "sanity check" that I was not doing something wrong.

    Susan
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5