A number of fixes for the libusb handling:

. use the correct endpoint, depending on whether we are going to read
  or write
. when opening the USB device, set the configuration according to the
  config entry, and properly claim the interface
. when closing, release the interface again

With these changes, it works now with libusb-win32 as well.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@533 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
joerg_wunsch 2005-09-26 12:19:01 +00:00
parent 0599a70fd1
commit 818aafe4fc
2 changed files with 52 additions and 6 deletions

View File

@ -1,3 +1,10 @@
2005-09-26 Joerg Wunsch <j@uriah.heep.sax.de>
* jtagmkII.c (jtagmkII_paged_write): default the page size early so the
buffer will be allocated correctly.
* usb_libusb.c: fix libusb handling; now it works with libusb-win32 as
well.
2005-09-21 Joerg Wunsch <j@uriah.heep.sax.de> 2005-09-21 Joerg Wunsch <j@uriah.heep.sax.de>
* main.c(do_op): use mem->desc in place of upd->memtype to * main.c(do_op): use mem->desc in place of upd->memtype to

View File

@ -48,12 +48,15 @@ extern int verbose;
* Should we query the endpoint number and max transfer size from USB? * Should we query the endpoint number and max transfer size from USB?
* After all, the JTAG ICE mkII docs document these values. * After all, the JTAG ICE mkII docs document these values.
*/ */
#define JTAGICE_BULK_EP 2 #define JTAGICE_BULK_EP_WRITE 0x02
#define JTAGICE_BULK_EP_READ 0x82
#define JTAGICE_MAX_XFER 64 #define JTAGICE_MAX_XFER 64
static char usbbuf[JTAGICE_MAX_XFER]; static char usbbuf[JTAGICE_MAX_XFER];
static int buflen = -1, bufptr; static int buflen = -1, bufptr;
static int usb_interface;
static int usbdev_open(char * port, long baud) static int usbdev_open(char * port, long baud)
{ {
char string[256]; char string[256];
@ -99,7 +102,7 @@ static int usbdev_open(char * port, long baud)
usb_find_busses(); usb_find_busses();
usb_find_devices(); usb_find_devices();
for (bus = usb_busses; bus; bus = bus->next) for (bus = usb_get_busses(); bus; bus = bus->next)
{ {
for (dev = bus->devices; dev; dev = dev->next) for (dev = bus->devices; dev; dev = dev->next)
{ {
@ -132,7 +135,7 @@ static int usbdev_open(char * port, long baud)
if (verbose) if (verbose)
fprintf(stderr, fprintf(stderr,
"%s: usb_open(): Found JTAG ICE, serno: %s\n", "%s: usbdev_open(): Found JTAG ICE, serno: %s\n",
progname, string); progname, string);
if (serno != NULL) if (serno != NULL)
{ {
@ -153,8 +156,35 @@ static int usbdev_open(char * port, long baud)
} }
} }
if (dev->config == NULL)
{
fprintf(stderr,
"%s: usbdev_open(): USB device has no configuration\n",
progname);
goto trynext;
}
if (usb_set_configuration(udev, dev->config[0].bConfigurationValue))
{
fprintf(stderr,
"%s: usbdev_open(): error setting configuration %d: %s\n",
progname, dev->config[0].bConfigurationValue,
usb_strerror());
goto trynext;
}
usb_interface = dev->config[0].interface[0].altsetting[0].bInterfaceNumber;
if (usb_claim_interface(udev, usb_interface))
{
fprintf(stderr,
"%s: usbdev_open(): error claiming interface %d: %s\n",
progname, usb_interface, usb_strerror());
goto trynext;
}
return (int)udev; return (int)udev;
} }
trynext:
usb_close(udev); usb_close(udev);
} }
} }
@ -174,6 +204,7 @@ static void usbdev_close(int fd)
{ {
usb_dev_handle *udev = (usb_dev_handle *)fd; usb_dev_handle *udev = (usb_dev_handle *)fd;
(void)usb_release_interface(udev, usb_interface);
usb_close(udev); usb_close(udev);
} }
@ -181,8 +212,16 @@ static void usbdev_close(int fd)
static int usbdev_send(int fd, unsigned char *bp, size_t mlen) static int usbdev_send(int fd, unsigned char *bp, size_t mlen)
{ {
usb_dev_handle *udev = (usb_dev_handle *)fd; usb_dev_handle *udev = (usb_dev_handle *)fd;
size_t rv;
return usb_bulk_write(udev, JTAGICE_BULK_EP, (char *)bp, mlen, 5000) != mlen; rv = usb_bulk_write(udev, JTAGICE_BULK_EP_WRITE, (char *)bp, mlen, 5000);
if (rv != mlen)
{
fprintf(stderr, "%s: usbdev_send(): wrote %d out of %d bytes, err = %s\n",
progname, rv, mlen, usb_strerror());
return -1;
}
return 0;
} }
/* /*
@ -198,7 +237,7 @@ usb_fill_buf(usb_dev_handle *udev)
{ {
int rv; int rv;
rv = usb_bulk_read(udev, JTAGICE_BULK_EP, usbbuf, JTAGICE_MAX_XFER, 5000); rv = usb_bulk_read(udev, JTAGICE_BULK_EP_READ, usbbuf, JTAGICE_MAX_XFER, 5000);
if (rv < 0) if (rv < 0)
{ {
if (verbose > 1) if (verbose > 1)
@ -263,7 +302,7 @@ static int usbdev_drain(int fd, int display)
int rv; int rv;
do { do {
rv = usb_bulk_read(udev, JTAGICE_BULK_EP, usbbuf, JTAGICE_MAX_XFER, 100); rv = usb_bulk_read(udev, JTAGICE_BULK_EP_READ, usbbuf, JTAGICE_MAX_XFER, 100);
if (rv > 0 && verbose >= 4) if (rv > 0 && verbose >= 4)
fprintf(stderr, "%s: usbdev_drain(): flushed %d characters\n", fprintf(stderr, "%s: usbdev_drain(): flushed %d characters\n",
progname, rv); progname, rv);