I am now trying to test a simple isochronous USB device. Under Windows,
I can use libusb-win32 to do a simple test.
http://forum.microchip.com/tm.aspx?m=270049
I understand that I still need to understand more about isochronous
transfer and improve the firmware side but I am interested to test it
under libusb Linux as well with similar code.
What is my option under Linux with libusb since the current libusb
code does not support isochronous transfer. The existing patches
do not have a similar API like libusb-win32.
Thanks in advance.
Xiaofan
---------- Forwarded message ----------
From: Xiaofan Chen <xiaofanc@xxxxxxxxx>
Date: Jul 31, 2007 9:56 AM
Subject: Understanding iIsochronous transfer with libusb-win32
To: libusb-win32-devel@xxxxxxxxxxxxxxxxxxxxx
I am in the process of writing a simple isochronous transfer firmware for
Microchip PICkit 2 (PIC18F2550). I need a host application to test it.
http://forum.microchip.com/tm.aspx?m=270049&mpage=2
Based on some of the examples Stephan posted here, I come out the
following test program and it seems to work. However, I do not quite
understand the code since I do not quite understand isochronous transfer.
Why we need three context? What is the benefit? Now three buffers
contain the same data.
I know the firmware is not that useful yet since it does not implement
double buffer.
<code>
#include <usb.h>
#define VERSION "0.1.0"
#define VENDOR_ID 0x04D8
#define PRODUCT_ID 0x0080
#define INTERFACE 0
#define BUFFER_SIZE 65
usb_dev_handle *find_pickit2_isoc();
usb_dev_handle* setup_libusb_access() {
usb_dev_handle *pickit2_isoc;
usb_set_debug(255);
usb_init();
usb_find_busses();
usb_find_devices();
if(!(pickit2_isoc = find_pickit2_isoc())) {
printf("Couldn't find the mouse, Exiting\n");
return NULL;
}
if (usb_set_configuration(pickit2_isoc, 1) < 0) {
printf("Could not set configuration 1 : %s\n");
return NULL;
}
if (usb_claim_interface(pickit2_isoc, INTERFACE) < 0) {
printf("Could not claim interface: %s\n");
return NULL;
}
return pickit2_isoc;
}
usb_dev_handle *find_pickit2_isoc()
{
struct usb_bus *bus;
struct usb_device *dev;
for (bus = usb_busses; bus; bus = bus->next) {
for (dev = bus->devices; dev; dev = dev->next) {
if (dev->descriptor.idVendor == VENDOR_ID &&
dev->descriptor.idProduct == PRODUCT_ID ) {
usb_dev_handle *handle;
printf("pickit2_isoc with Vendor Id:
%x and Product Id: %x
found.\n", VENDOR_ID, PRODUCT_ID);
if (!(handle = usb_open(dev))) {
printf("Could not open USB device\n");
return NULL;
}
return handle;
}
}
}
return NULL;
}
void test_isochronous_async(usb_dev_handle *dev)
{
unsigned char buf0[640];
unsigned char buf1[640];
unsigned char buf2[640];
int i;
/* use three contexts for this example (more can be used) */
void *context0 = NULL;
void *context1 = NULL;
void *context2 = NULL;
/* write transfer (stream) */
/*
usb_isochronous_setup_async(dev, &context0, 0x01);
usb_isochronous_setup_async(dev, &context1, 0x01);
usb_isochronous_setup_async(dev, &context2, 0x01);
usb_submit_async(context0, buf0, sizeof(buf0));
usb_submit_async(context1, buf1, sizeof(buf1));
usb_submit_async(context2, buf2, sizeof(buf2));
for(i = 0; i < 10; i++)
{
usb_reap_async(context0, 5000);
usb_submit_async(context0, buf0, sizeof(buf0));
usb_reap_async(context1, 5000);
usb_submit_async(context1, buf1, sizeof(buf1));
usb_reap_async(context2, 5000);
usb_submit_async(context2, buf2, sizeof(buf2));
}
usb_reap_async(context0, 5000);
usb_reap_async(context1, 5000);
usb_reap_async(context2, 5000);
usb_free_async(&context0);
usb_free_async(&context1);
usb_free_async(&context2);
*/
/* read transfer (stream) */
usb_isochronous_setup_async(dev, &context0, 0x81,64);
usb_isochronous_setup_async(dev, &context1, 0x81,64);
usb_isochronous_setup_async(dev, &context2, 0x81,64);
usb_submit_async(context0, buf0, sizeof(buf0));
usb_submit_async(context1, buf1, sizeof(buf1));
usb_submit_async(context2, buf2, sizeof(buf2));
for(i = 0; i < 10; i++)
{
usb_reap_async(context0, 5000);
usb_submit_async(context0, buf0, sizeof(buf0));
usb_reap_async(context1, 5000);
usb_submit_async(context1, buf1, sizeof(buf1));
usb_reap_async(context2, 5000);
usb_submit_async(context2, buf2, sizeof(buf2));
}
for(i = 0; i < 640; i++) {
printf(" %02x, %02x, %02x ", buf0[i],buf1[i],buf2[i]);
// printf(" %02x, %02x, %02x ", buf0[i]);
}
usb_reap_async(context0, 5000);
usb_reap_async(context1, 5000);
usb_reap_async(context2, 5000);
usb_free_async(&context0);
usb_free_async(&context1);
usb_free_async(&context2);
/* release interface */
usb_set_altinterface(dev, 0);
usb_release_interface(dev, 0);
}
int main(void)
{
usb_dev_handle *pickit2_isoc;
if ((pickit2_isoc = setup_libusb_access()) == NULL) {
exit(-1);
}
test_isochronous_async(pickit2_isoc);
usb_close(pickit2_isoc);
return 0;
}
<device info>
DLL version: 0.1.12.1
Driver version: 0.1.12.1
bus/device idVendor/idProduct
bus-0/\\.\libusb0-0001--0x04d8-0x0080 04D8/0080
- Manufacturer : Microchip Technology Inc.
- Product : PICDEM FS USB Demo Board (C) 2004
wTotalLength: 32
bNumInterfaces: 1
bConfigurationValue: 1
iConfiguration: 0
bmAttributes: 80h
MaxPower: 50
bInterfaceNumber: 0
bAlternateSetting: 0
bNumEndpoints: 2
bInterfaceClass: 0
bInterfaceSubClass: 0
bInterfaceProtocol: 0
iInterface: 0
bEndpointAddress: 01h
bmAttributes: 0dh
wMaxPacketSize: 64
bInterval: 1
bRefresh: 0
bSynchAddress: 0
bEndpointAddress: 81h
bmAttributes: 0dh
wMaxPacketSize: 64
bInterval: 1
bRefresh: 0
bSynchAddress: 0
Regards,
Xiaofan
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>
http://get.splunk.com/