Gary Carlson <gcarlson@carlson-minot.com>

Spencer Oliver <spen@spen-soft.co.uk>

- fix jlink win32/linux/darwin startup issues
- see https://lists.berlios.de/pipermail/openocd-development/2009-July/009438.html

git-svn-id: svn://svn.berlios.de/openocd/trunk@2513 b42882b7-edfa-0310-969c-e2dbd0fdcd60
__archive__
ntfreak 2009-07-13 06:36:51 +00:00
parent b1ccc35323
commit ebd46e23b3
1 changed files with 92 additions and 43 deletions

View File

@ -835,20 +835,12 @@ static int jlink_tap_execute(void)
return ERROR_OK;
}
/*****************************************************************************/
/* JLink USB low-level functions */
static jlink_jtag_t* jlink_usb_open()
static struct usb_device* find_jlink_device(void)
{
struct usb_bus *busses;
struct usb_bus *bus;
struct usb_device *dev;
jlink_jtag_t *result;
result = (jlink_jtag_t*) malloc(sizeof(jlink_jtag_t));
usb_init();
usb_find_busses();
usb_find_devices();
@ -860,19 +852,77 @@ static jlink_jtag_t* jlink_usb_open()
{
for (dev = bus->devices; dev; dev = dev->next)
{
if ((dev->descriptor.idVendor == VID) && (dev->descriptor.idProduct == PID))
if ((dev->descriptor.idVendor == VID) && (dev->descriptor.idProduct == PID)) {
return dev;
}
}
}
return NULL;
}
/*****************************************************************************/
/* JLink USB low-level functions */
static jlink_jtag_t* jlink_usb_open()
{
struct usb_device *dev;
jlink_jtag_t *result;
result = (jlink_jtag_t*) malloc(sizeof(jlink_jtag_t));
usb_init();
if ((dev = find_jlink_device()) == NULL) {
free(result);
return NULL;
}
result->usb_handle = usb_open(dev);
/*
* Some j-link dongles experience intermittent communication issues at startup to varying degrees
* depending on the host operating system. Troubleshooting this problem all the way back to libusb
* revealed that without a usb reset, the hardware can start in an uncertain state causing a litany
* of annoying problems. The next step was added to the original code to address this problem.
if (result->usb_handle)
{
/* BE ***VERY CAREFUL*** ABOUT MAKING CHANGES IN THIS AREA!!!!!!!!!!!
* The behavior of libusb is not completely consistent across Windows, Linux, and Mac OS X platforms. The actions taken
* in the following compiler conditionals may not agree with published documentation for libusb, but were found
* to be necessary through trials and tribulations. Even little tweaks can break one or more platforms, so if you do make changes
* test them carefully on all platforms before committing them!
*/
#if IS_WIN32 == 0
usb_reset(result->usb_handle);
#if IS_DARWIN == 0
int timeout = 5;
/* reopen jlink after usb_reset
* on win32 this may take a second or two to re-enumerate */
while ((dev = find_jlink_device()) == NULL)
{
usleep(1000);
timeout--;
if (!timeout) {
break;
}
}
if (dev == NULL)
{
free(result);
return NULL;
}
result->usb_handle = usb_open(dev);
#endif
#endif
if (result->usb_handle)
{
/* usb_set_configuration required under win32 */
usb_set_configuration(result->usb_handle, dev->config[0].bConfigurationValue);
usb_claim_interface(result->usb_handle, 0);
@ -900,7 +950,6 @@ static jlink_jtag_t* jlink_usb_open()
return result;
}
}
}
free(result);
return NULL;