On Mon, Jul 11, 2011 at 3:17 AM, simon qian <simonqian.open...@gmail.com> wrote:
> Hi,
> Attachment is the versaloon driver update, please commit if no problem.
>
> In vsllink_usb_open, I remove call to jtag_usb_open, because jtag_usb_open
> will only check PID and VID to identify a device. There is 2 devices in the
> recent Versaloon, one is Versaloon programmer/debugger, the other is a
> CDC COM port. IAD is used to implement the 2 devices. So these devices
> share the same PID and VID, and there is chances that openocd find the
> wrong device.

You are right. I think jtag_usb_open should probably be extended to be
able to match individual interface and even things like serial number or
manufacturer string. In that case, OpenOCD can be used with more
than one device with the same VID/PID.

I like your find_usb_device help function. Maybe others can
use the same function as well.

+static usb_dev_handle* find_usb_device(uint16_t VID, uint16_t PID,
+               uint8_t interface, int8_t serialindex, char *serialstring,
+               int8_t productindex, char *productstring)
+{
+       usb_dev_handle *dev_handle = NULL;
+       struct usb_bus *busses;
+       struct usb_bus *bus;
+       struct usb_device *dev;
+
+       usb_init();
+       usb_find_busses();
+       usb_find_devices();
+       busses = usb_get_busses();
+
+       for (bus = busses; bus; bus = bus->next)
+       {
+               for (dev = bus->devices; dev; dev = dev->next)
+               {
+                       if ((dev->descriptor.idVendor == VID)
+                               && (dev->descriptor.idProduct == PID))
+                       {
+                               dev_handle = usb_open(dev);
+                               if (NULL == dev_handle)
+                               {
+                                       LOG_ERROR("failed to open %04X:%04X, 
%s", VID, PID,
+                                                               usb_strerror());
+                                       continue;
+                               }
+                               
+                               // check description string
+                               if (((productstring != NULL) && (productindex 
>= 0)
+                                               && 
!usb_check_string(dev_handle, productindex,
+                                                                               
                productstring, NULL, 0))
+                                       || ((serialstring != NULL) && 
(serialindex >= 0)
+                                               && 
!usb_check_string(dev_handle, serialindex,
+                                                                               
                serialstring, NULL, 0)))
+                               {
+                                       usb_close(dev_handle);
+                                       dev_handle = NULL;
+                                       continue;
+                               }
+                               
+                               if (usb_claim_interface(dev_handle, interface) 
!= 0)
+                               {
+                                       
LOG_ERROR(ERRMSG_FAILURE_OPERATION_MESSAGE,
+                                                               "claim 
interface", usb_strerror());
+                                       usb_close(dev_handle);
+                                       dev_handle = NULL;
+                                       continue;
+                               }
+                               
+                               if (dev_handle != NULL)
+                               {
+                                       return dev_handle;
+                               }
+                       }
+               }
+       }
+       
+       return dev_handle;
+}
+


-- 
Xiaofan
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to