|
From: Tim R. <ti...@pr...> - 2007-02-28 16:56:21
|
mohammed abuhijle wrote:
>
> I have the following code that takes more than a min to finisg:
That's right.
> /*write 40 Mbytes worth of data to the bulk endpoint*/
> /*i am calculating this by: 512 (packet size) * 2 = 1 KB, * 1000 =
> 1MB, * 40 = 40 MB*/
> for (i = 0; i < 2 * 1000 * 40 ; i++){
> ret = usb_bulk_write(cypress_dev_handle, epi,bytes, 512, 0 /*the
> timrout is ignored for bulk transfer*/);
> //printf ("i is:%d\t ret is %d\t bytes is %s\n",i, ret,bytes);
> }
Remember that USB is a "scheduled" bus. The USB host controller has to
have a frame all planned out before the frame begins. In your case, you
are sending exactly one packet down, which then gets scheduled into a
frame, and because usb_bulk_write is synchronous, you then wait until
the transfer is complete, thereby wasting the rest of the frame. That
means you cannot do any better than one packet per frame, 512k bytes per
second, which would make 40MB take 80 seconds.
The USB subsystem will happily chop up a large transfer into
packet-sized pieces as needed, and when it does so, it will pack in as
many packets as it can into a single frame. You can send megabytes to
usb_bulk_write, and get your 40MB transferred in a second or two.
--
Tim Roberts, ti...@pr...
Providenza & Boekelheide, Inc.
|