Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to handle USB Isochronous data Transfer?



Title: Re: How to handle USB Isochronous data Transfer?
Great, if your max packet size is 300, then every read request will be 300.  Have you seen the isoc API (IOUSBPipe.h)?  It requires a buffer, a starting frame number, a count of how many frames to read, an array of read transaction descriptors (equal to count), which is really just an array of structures that say how many bytes to read going in and how many bytes were read and if there was an error coming back, and a completion routine descriptor.

You basically just say “go at this time” and IOUSBFamily starts reading at that frame.  You want to say “go” some point in the future, obviously, and at least two frames into the future is the recommended, though one frame into the future works quite reliably, though due to the nature of the USB hardware and how it reports when “now” is, it isn’t guaranteed to work.

I like to use large counts because it means that I don’t have to be interrupted very frequently.  However, I’ve reliably used numbers as small as 2 (for a double buffering scheme, 1 doesn’t work well, though in a triple buffering scheme, it might work).  Numbers like 100 seem like a reasonable value if you don’t have time critical data, or have some other way of knowing when it’s arrived (by examining the buffer, for instance).  What number you pick is totally up to you, though I imagine there is an upper bound somewhere (I’ve never tried to find it — let us know what it is if you do).  Remember, you will have a software interrupt at this interval number of milliseconds, so try to make it as large as practical to avoid unnecessary context switches and their resulting overhead.

You usually don’t want to wait after one read completes before issuing the next read.  After all, the point of isoc is to be streaming data, and you certainly wouldn’t want to miss a millisecond of that data.  Using a double buffer technique you would queue two reads, each of say 100 frames, and have a completion routine after each 100 frames (which translates into after each Read() command) completes.  The completion routine for read queues itself, and in this way you always have one read running while another completes and queues itself, ensuring that every USB frame has a pending read request and no data is lost.

So, you queue 100 frames for start time X and 100 frames for X+100 to get the whole process started.  Then, the completion routine for the first read completes (at time X+100) and queues for X+200 then the second read completes (at time X+200) and queues for time X+300 and so on and so on until you signal it to stop queuing itself.  It’s really quite elegant in its simplicity.
--
Mark Cookson
M-Audio, a division of Avid
225 Locust St.
Hudson, WI 54016

On 2/23/05 8:28 AM, "Nakkala Sivaram Prasad" <email@hidden> wrote:

Dear all,

   Thank you Mr. Mark Cookson for your responce. Actually my device has MaxPacketSize of
300 Bytes in Alternate Setting 3 which start streaming out data when this alternate setting has been set.
>From your reply It is pretty clear that bytes per frame must be set Max Packet size of the opened Isoc Pipe.
what should be the typical number of frames that the USBIsocRead call must be active? Does this number
of frames depends on any factor or can we make the IsocRead for any number of frames? Does it required
to wait for 1msec after the USBIsocRead?

Thanks and Regards,
Sivaram Prasad


----- Original Message -----
 
From:  Mark  Cookson <mailto:email@hidden>  
 
To: Nakkala Sivaram Prasad <mailto:email@hidden>  ; usb <mailto:email@hidden>  
 
Sent: Tuesday, February 22, 2005 11:02  PM
 
Subject: Re: How to handle USB  Isochronous data Transfer?
 

For isoc reads,  you specify the maximum amount of data you want per frame, and how many frames  you want to read.  You give a buffer, and a memory descriptor for that  buffer, along with the list of frames and bytes per frame to read, and  IOUSBFamily does the rest.

If you don’t know how many bytes will come  each frame (which it sounds like you don’t), then you have to pick some upper  maximum (preferably other than 1023, but that is the maximum isoc frame size  in USB 1.1).  Remember that IOUSBFamily puts the data where it would have  gone if the full amount had been transferred in the frame before.  So, if  you ask for 1023 bytes, but only get 100, the next block of data will be put  at offset 1024 in your buffer, not 101, so you’ll have to coalesce the data  together, if that’s important, because there will be lots of gaps with garbage  in your buffer.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Usb mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/usb/email@hidden

This email sent to email@hidden

References: 
 >Re: How to handle USB Isochronous data Transfer? (From: Nakkala Sivaram Prasad <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.