|
From: Thomas S. <th...@th...> - 2007-08-30 19:17:58
|
Does libusb-win32 support isochronous transfers? |
|
From: Lange Jan-E. <Jan...@ha...> - 2010-11-04 15:21:37
|
Hello,
I have a problem realizing isochronous transmisson with the asynchronous interface of libusb-win32. Using bulk transmission with the asynchonous interface there are no errors.
I use libusb-win32 with the Cypress FX2 and have to stream a continous datastream. Using bulk transfer, my internal fifo (inside my fpga logic) overflows sometimes. Perhaps the PC receives the USB data from the FX2 too discontinuously. Using isonchronous transfer could solve the problem because of the fixed bandwidth of this transfer.If somebody disagrees with this thought please, tell me.
The usb_submit_async() function returns: -22
I initialize the USB transmission identicaly to the bulk transfer.
At first here is the realization with bulk transfer:
/////////////////////////////////////////////////////////////////////////////////////////////
#define LEN 131072
......
Initialization
...........
printf("\nsetup async communication");
if( usb_bulk_setup_async(UsbHandler::udev, &request, 0x86) < 0)
{
printf("\nError usb_bulk_setup_async()");
}
gettimeofday(&start_tv_mem, NULL);
for(int m=0; m<=DATA; m++)
{
// ASYNCHRONOUS READING
///////////////////////////////////////////////////////////
// fx2.read(answer);
// printf("\nSubmitting request");
if(usb_submit_async(request, answer, LEN) < 0)
{
printf("\nFehler bei usb_submit_async()");
}
// printf("\nWaiting for the reqeust to get finished");
read=usb_reap_async(request, 10000);
if( read >= 0 )
{
// printf("\nread %d bytes", read);
}
else
{
printf("\nError usb_reap_async(): %i", read);
}
// printf("\nBulk Transfer Loop Test Result:\n");
for(int i = 0;i < LEN; i=i+2)
{
// printf("%02x %02x\t", (unsigned char)answer[i+1], (unsigned char)answer[i]);
// fprintf(ausgabe, "%c%c", (unsigned char)answer[i+1], (unsigned char)answer[i]);
buffer[help++]=(unsigned char)answer[i+1];
buffer[help++]=(unsigned char)answer[i];
// printf("\nbuffer(%u): %02x", help-1, buffer[help-1]);
//getche();
}
}
gettimeofday(&end_tv_mem, NULL);
usb_free_async(&request);
/////////////////////////////////////////////////////////////////////////////////////
This is with isochronous transfer:
////////////////////////////////////////////////////////////////////
void *request;
int read;
printf("\nsetup async communication");
if( usb_isochronous_setup_async(UsbHandler::udev, &request, 0x86, LEN) < 0)
{
printf("\nError usb_bulk_setup_async()");
}
gettimeofday(&start_tv_mem, NULL);
for(int m=0; m<=DATA; m++) // 1000*100 Bei m=50 gibt es Fehler 1000 entspich 1000 Kb
{
// ASYNCHRONOUS READING
///////////////////////////////////////////////////////////
// Ausgabe von Quadbuffering EP6 16-bit Breite von FD
// fx2.read(answer);
// printf("\nSubmitting request");
read = usb_submit_async(request, answer, LEN);
if(read < 0)
{
printf("\nError usb_submit_async(): %i ", read); // HERE IS THE ERROR -22
}
// printf("\nWaiting for the reqeust to get finished");
read=usb_reap_async(request, 10000);
if( read >= 0 )
{
// printf("\nread %d bytes", read);
}
else
{
printf("\nFehler bei usb_reap_async(): %i", read);
}
// printf("\nBulk Transfer Loop Test Result:\n");
for(int i = 0;i < LEN; i=i+2)
{
// printf("%02x %02x\t", (unsigned char)answer[i+1], (unsigned char)answer[i]);
// fprintf(ausgabe, "%c%c", (unsigned char)answer[i+1], (unsigned char)answer[i]); // Hex-Ausgabe
buffer[help++]=(unsigned char)answer[i+1];
buffer[help++]=(unsigned char)answer[i];
// printf("\nbuffer(%u): %02x", help-1, buffer[help-1]);
//getche();
}
}
gettimeofday(&end_tv_mem, NULL);
usb_free_async(&request);
////////////////////////////////////////////////////////////////////
Do you know this error? I didn't found in the neither in the libusb documentation nor in the libusb-win32 documentation.
Best regards
Jan
|
|
From: Xiaofan C. <xia...@gm...> - 2010-11-05 00:38:18
|
On Thu, Nov 4, 2010 at 10:47 PM, Lange Jan-Erik <Jan...@ha...> wrote: > Hello, > I have a problem realizing isochronous transmisson with the asynchronous > interface of libusb-win32. Using bulk transmission with the asynchonous > interface there are no errors. > > I use libusb-win32 with the Cypress FX2 and have to stream a continous > datastream. Using bulk transfer, my internal fifo (inside my fpga logic) > overflows sometimes. Perhaps the PC receives the USB data from the FX2 too > discontinuously. Using isonchronous transfer could solve the problem because > of the fixed bandwidth of this transfer.If somebody disagrees with this > thought please, tell me. Just want to confirm with you if this is a high speed USB device or not. If yes then libusb-win32 may not work well with high speed USB device in the case of isochronous transfer. What is the output of testlibusb-win.exe? > The usb_submit_async() function returns: -22 > > I initialize the USB transmission identicaly to the bulk transfer. > At first here is the realization with bulk transfer: > ///////////////////////////////////////////////////////////////////////////////////////////// > > #define LEN 131072 > ...... What if you reduce the LEN to be below 64KB? -- Xiaofan |
|
From: Xiaofan C. <xia...@gm...> - 2010-11-05 00:49:51
|
On Thu, Nov 4, 2010 at 10:47 PM, Lange Jan-Erik <Jan...@ha...> wrote: > I use libusb-win32 with the Cypress FX2 and have to stream a continous > datastream. Using bulk transfer, my internal fifo (inside my fpga logic) > overflows sometimes. Perhaps the PC receives the USB data from the FX2 too > discontinuously. Using isonchronous transfer could solve the problem because > of the fixed bandwidth of this transfer.If somebody disagrees with this > thought please, tell me. I think bulk transfer plus some type of flow control may help. I assume your setup is like this PC--USB FX2--FPGA--Others. If you use bulk transfer, the PC-- USB FX2 part has kind of automatic flow control (NAK). So the issue is the USB FX2 to FPGA side where you may want to try out some flow control. -- Xiaofan |
|
From: Lange Jan-E. <Jan...@ha...> - 2010-11-05 09:55:33
|
>On Thu, Nov 4, 2010 at 10:47 PM, Lange Jan-Erik ><Jan...@ha...> wrote: >> I use libusb-win32 with the Cypress FX2 and have to stream a continous >> datastream. Using bulk transfer, my internal fifo (inside my fpga logic) >> overflows sometimes. Perhaps the PC receives the USB data from the FX2 too >> discontinuously. Using isonchronous transfer could solve the problem because >> of the fixed bandwidth of this transfer.If somebody disagrees with this >> thought please, tell me. >I think bulk transfer plus some type of flow control may help. >I assume your setup is like this PC--USB FX2--FPGA--Others. >If you use bulk transfer, the PC-- USB FX2 part has kind of >automatic flow control (NAK). So the issue is the USB FX2 >to FPGA side where you may want to try out some flow control. Yes I use high-speed USB with libusb-win32. I'l try out your tips tonight. Do you mean to stop generate and send data to the FX2 with "to try out some flow control"? I already integrated logic inside the fpga, that the internal FIFO (not the slave FIFO of the FX2) doesn't put out data to the FX2, when the FX2(Slave FIFO interface) is full/busy. I think it's about my PC to get the data fast and continous enough from the FX2 to the PC. I have realized a datarate of 20MBytes/s from the fx2 to the PC with a counter inside the fpga. And the incoming data was correct. However, I only need 12MBytes/s for my target application. But this 12MBytes/s data stream must be continous enough so that the internal FIFO inside my FPGA doesn't overflows. The 20 MBytes/s datastream is fast, but 'm afraid that it is too disconintous for my application. The internal FIFO not even overflows all the time, only sometimes. Jan |
|
From: Travis <lib...@gm...> - 2010-11-05 13:59:50
|
On 11/4/2010 7:47 AM, Lange Jan-Erik wrote:
> Hello,
> I have a problem realizing isochronous transmisson with the
> asynchronous interface of libusb-win32. Using bulk transmission with
> the asynchonous interface there are no errors.
The bulk test code and iso test code both use endpoint 0x86. Are you
reprogramming this device?
> I use libusb-win32 with the Cypress FX2 and have to stream a continous
> datastream. Using bulk transfer, my internal fifo (inside my fpga
> logic) overflows sometimes. Perhaps the PC receives the USB data from
> the FX2 too discontinuously. Using isonchronous transfer could solve
> the problem because of the fixed bandwidth of this transfer.If
> somebody disagrees with this thought please, tell me.
For streaming iso data there must always be transfers pending. Your
code doesn't queue transfers. As soon as a packet arrives from your
device with no where to go, it causes an error to occur when the next
transfer is submitted.
> The usb_submit_async() function returns: -22
ERROR_INVALID_PARAMETER
Something is invalid. For example, the device is not configured, handle
is invalid, submitted ISO to a bulk endpoint, etc.
To find out exactly, you would need to use DebugView with debug builds.
> I initialize the USB transmission identicaly to the bulk transfer.
> At first here is the realization with bulk transfer:
> /////////////////////////////////////////////////////////////////////////////////////////////
>
> #define LEN 131072
This is probably to big. What's the endpoint packet size? libusb-win32
uses the USB_START_ISO_TRANSFER_ASAP transfer flag. This limits the
number of packets to 255 or less.
For streaming data, keep the transfer size small and keep them queued up.
For example:
resetep
setup 4096
setup 4096
setup 4096
submit 4096
submit 4096
submit 4096
loop
reap 4096
submit 4096
goto loop
free 4096
free 4096
free 4096
Regards,
Travis
|
|
From: Travis <lib...@gm...> - 2010-11-05 14:18:34
|
On 11/4/2010 7:47 AM, Lange Jan-Erik wrote: > > #define LEN 131072 > if( usb_isochronous_setup_async(UsbHandler::udev, &request, 0x86, > LEN) < 0) This is incorrect. The last parameter is the packet size. This should probably be the same as wMaxPacketSize. I'm not sure what would happen if a larger value were used. Regards, Travis |
|
From: Lange Jan-E. <Jan...@ha...> - 2010-11-06 14:04:23
Attachments:
lsusbFX2
|
Thank you for the tipps. I will try them at work. Yes, I reprogram the device. x86 is correct, and I setup the FX2 with isocronous settings. I queue tranfers within a while-loop. I only posted the code inside the loop. Like you can see in the lsusbFX2 file, the wMaxPacketSize of bulk and iso transfers is 512 bytes. wMaxPacketSize 0x0200 1x 512 bytes But using bulk transfer it was Ok. By the way, I must use such high values like 131072 for LEN, for reaching a such a high data rate? Is this unusual? Perhaps my programm flow is not optimal. In you example you made a pseudocode. 1. Why do you make three times setup 4096 and then submit 4096 three times in a row, before beginning with the loop? 2. Why you use the value 4096? Is this the Packet size? It is greater than 512, too. 3. I think It could be possible to improve the continous receive behavior with maintaining bulk transfer. I only have this device connected to the PC, and one FPGA device which doesn't transfer data. So the FX2 should have the whole bandwith or not? Is it possible to realize a better receive behavior with two buffers and the bulk-async-functions? Like use the time of waiting for a bulk request1 answer to transfer the content of a buffer2 into my heap. buffer2 is result of a request2. And so on.. I mean, it could improve the continous receive behavior, if you use the time of waiting for a request for transferring the buffer content of an already answered request. Is this possible? By the way, for my application isocronous transfer would not even be advantageous, because the data which will be transfered should be correct. Isocronous transfer has no CRC check. Damn, .. I HAVE a data rate of 20 -25 MBytes/s with bulk transfer but it is to discontinous:) If I could could make my internal FIFO buffer greater, I wouldn't have this problems yet, ..damn:) Do you have an idea? ________________________________________ Von: Travis [lib...@gm...] Gesendet: Freitag, 5. November 2010 15:18 An: lib...@li... Betreff: Re: [Libusb-win32-devel] isochronous transfer On 11/4/2010 7:47 AM, Lange Jan-Erik wrote: #define LEN 131072 if( usb_isochronous_setup_async(UsbHandler::udev, &request, 0x86, LEN) < 0) This is incorrect. The last parameter is the packet size. This should probably be the same as wMaxPacketSize. I'm not sure what would happen if a larger value were used. Regards, Travis |
|
From: Travis <lib...@gm...> - 2010-11-06 14:57:43
|
On 11/6/2010 7:05 AM, Lange Jan-Erik wrote: > Thank you for the tipps. I will try them at work. > > Yes, I reprogram the device. x86 is correct, and I setup the FX2 with isocronous settings. > > I queue tranfers within a while-loop. I only posted the code inside the loop. ? No. You submit transfers within a while loop. There is no queuing going on in the code you posted. A dead give away is you are only setting up 1 request; you need to allocate atleast 3. > Like you can see in the lsusbFX2 file, the wMaxPacketSize of bulk and iso transfers is 512 bytes. > wMaxPacketSize 0x0200 1x 512 bytes I don't have a lsusbFX2 file. ;) > But using bulk transfer it was Ok. By the way, I must use such high values like 131072 for LEN, for reaching a such a high data rate? Is this unusual? Perhaps my programm flow is not optimal. This is a transfer size. You are confusing it with packet sizes. A transfer is made up of one or more packets. > In you example you made a pseudocode. > > 1. Why do you make three times setup 4096 and then submit 4096 three times in a row, before beginning with the loop? I'm allocating 3 separate request contexts each with its own 4k data buffer and submitting them without waiting for any of them to complete. This primes the queue. Without this, we are not queuing any transfers. In the loop, you always reap the oldest request first. When it completes it is re-submitted thus becoming the newest request in the queue. > 2. Why you use the value 4096? Is this the Packet size? It is greater than 512, too. 4096 is the transfer size. I should not have put a 4096 after "setup", this was misleading; apologies. Since your packet size is 512, transfer sizes of 16384 should make a good starting point. > 3. I think It could be possible to improve the continous receive behavior with maintaining bulk transfer. I only have this device connected to the PC, and one FPGA device which doesn't transfer data. So the FX2 should have the whole bandwith or not? Is it possible to realize a better receive behavior with two buffers and the bulk-async-functions? Now I think you may be on the right track. The answer is yes! I believe what you are explaining here is transfer queuing. > By the way, for my application isocronous transfer would not even be advantageous, because the data which will be transfered should be correct. Isocronous transfer has no CRC check. Yes. ISO is really only good for analog like data. (video and audio) What about an interrupt endpoint? > Damn, .. I HAVE a data rate of 20 -25 MBytes/s with bulk transfer but it is to discontinous:) If I could could make my internal FIFO buffer greater, I wouldn't have this problems yet, ..damn:) > > Do you have an idea? I think your on the right track. You just need to make sure there is always transfers pending. Regards, Travis |
|
From: Xiaofan C. <xia...@gm...> - 2007-08-30 23:19:15
|
On 8/31/07, Thomas Spellman <th...@th...> wrote: > Does libusb-win32 support isochronous transfers? Yes. Search the forum and you will get some sample codes from Stephan. I have used it on testing a simple isoc device but I do not quite understand how it works right now. Regards, Xiaofan |