Change all the USB details (endpoint numbers, max transfer size etc.)

to a per-programmer adjustable value.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1108 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
joerg_wunsch 2012-11-26 16:24:56 +00:00
parent 8fdf4d4071
commit 3fabed6ea5
6 changed files with 96 additions and 34 deletions

View File

@ -1,3 +1,12 @@
2012-11-26 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
* jtagmkII.c: Change all the USB details (endpoint numbers,
max transfer size etc.) to a per-programmer adjustable value.
* serial.h: (Dito.)
* stk500v2.c: (Dito.)
* usbdevs.h: (Dito.)
* usb_libusb.c: (Dito.)
2012-11-20 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
* buspirate.c: Replace outdated FSF postal address by a reference to

View File

@ -1542,6 +1542,10 @@ static int jtagmkII_open(PROGRAMMER * pgm, char * port)
#if defined(HAVE_LIBUSB)
serdev = &usb_serdev;
baud = USB_DEVICE_JTAGICEMKII;
pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
#else
fprintf(stderr, "avrdude was compiled without usb support.\n");
return -1;
@ -1589,6 +1593,10 @@ static int jtagmkII_open_dw(PROGRAMMER * pgm, char * port)
#if defined(HAVE_LIBUSB)
serdev = &usb_serdev;
baud = USB_DEVICE_JTAGICEMKII;
pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
#else
fprintf(stderr, "avrdude was compiled without usb support.\n");
return -1;
@ -1636,6 +1644,10 @@ static int jtagmkII_open_pdi(PROGRAMMER * pgm, char * port)
#if defined(HAVE_LIBUSB)
serdev = &usb_serdev;
baud = USB_DEVICE_JTAGICEMKII;
pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
#else
fprintf(stderr, "avrdude was compiled without usb support.\n");
return -1;
@ -1684,6 +1696,10 @@ static int jtagmkII_dragon_open(PROGRAMMER * pgm, char * port)
#if defined(HAVE_LIBUSB)
serdev = &usb_serdev;
baud = USB_DEVICE_AVRDRAGON;
pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
#else
fprintf(stderr, "avrdude was compiled without usb support.\n");
return -1;
@ -1732,6 +1748,10 @@ static int jtagmkII_dragon_open_dw(PROGRAMMER * pgm, char * port)
#if defined(HAVE_LIBUSB)
serdev = &usb_serdev;
baud = USB_DEVICE_AVRDRAGON;
pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
#else
fprintf(stderr, "avrdude was compiled without usb support.\n");
return -1;
@ -1780,6 +1800,10 @@ static int jtagmkII_dragon_open_pdi(PROGRAMMER * pgm, char * port)
#if defined(HAVE_LIBUSB)
serdev = &usb_serdev;
baud = USB_DEVICE_AVRDRAGON;
pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
#else
fprintf(stderr, "avrdude was compiled without usb support.\n");
return -1;
@ -3411,6 +3435,10 @@ static int jtagmkII_open32(PROGRAMMER * pgm, char * port)
#if defined(HAVE_LIBUSB)
serdev = &usb_serdev;
baud = USB_DEVICE_JTAGICEMKII;
pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
#else
fprintf(stderr, "avrdude was compiled without usb support.\n");
return -1;

View File

@ -37,7 +37,10 @@ union filedescriptor
struct
{
void *handle;
int ep;
int rep; /* bulk read endpoint */
int wep; /* bulk write endpoint */
int eep; /* event read endpoint */
int max_xfer; /* max transfer size */
} usb;
};

View File

@ -1323,6 +1323,10 @@ static int stk500v2_open(PROGRAMMER * pgm, char * port)
baud = USB_DEVICE_AVRISPMKII;
PDATA(pgm)->pgmtype = PGMTYPE_AVRISP_MKII;
pgm->set_sck_period = stk500v2_set_sck_period_mk2;
pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
#else
fprintf(stderr, "avrdude was compiled without usb support.\n");
return -1;
@ -1375,6 +1379,10 @@ static int stk600_open(PROGRAMMER * pgm, char * port)
baud = USB_DEVICE_STK600;
PDATA(pgm)->pgmtype = PGMTYPE_STK600;
pgm->set_sck_period = stk600_set_sck_period;
pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
#else
fprintf(stderr, "avrdude was compiled without usb support.\n");
return -1;
@ -2819,6 +2827,10 @@ static int stk500v2_jtagmkII_open(PROGRAMMER * pgm, char * port)
#if defined(HAVE_LIBUSB)
serdev = &usb_serdev;
baud = USB_DEVICE_JTAGICEMKII;
pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
#else
fprintf(stderr, "avrdude was compiled without usb support.\n");
return -1;
@ -2911,6 +2923,10 @@ static int stk500v2_dragon_isp_open(PROGRAMMER * pgm, char * port)
#if defined(HAVE_LIBUSB)
serdev = &usb_serdev;
baud = USB_DEVICE_AVRDRAGON;
pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
#else
fprintf(stderr, "avrdude was compiled without usb support.\n");
return -1;
@ -2984,6 +3000,10 @@ static int stk500v2_dragon_hv_open(PROGRAMMER * pgm, char * port)
#if defined(HAVE_LIBUSB)
serdev = &usb_serdev;
baud = USB_DEVICE_AVRDRAGON;
pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
#else
fprintf(stderr, "avrdude was compiled without usb support.\n");
return -1;

View File

@ -52,7 +52,7 @@
# undef interface
#endif
static char usbbuf[USBDEV_MAX_XFER];
static char usbbuf[USBDEV_MAX_XFER_MKII];
static int buflen = -1, bufptr;
static int usb_interface;
@ -103,6 +103,9 @@ static int usbdev_open(char * port, long baud, union filedescriptor *fd)
}
}
if (fd->usb.max_xfer == 0)
fd->usb.max_xfer = USBDEV_MAX_XFER_MKII;
usb_init();
usb_find_busses();
@ -199,32 +202,34 @@ static int usbdev_open(char * port, long baud, union filedescriptor *fd)
}
fd->usb.handle = udev;
fd->usb.ep = -1;
/* Try finding out what our read endpoint is. */
for (i = 0; i < dev->config[0].interface[0].altsetting[0].bNumEndpoints; i++)
if (fd->usb.rep == 0)
{
/* Try finding out what our read endpoint is. */
for (i = 0; i < dev->config[0].interface[0].altsetting[0].bNumEndpoints; i++)
{
int possible_ep = dev->config[0].interface[0].altsetting[0].
endpoint[i].bEndpointAddress;
endpoint[i].bEndpointAddress;
if ((possible_ep & USB_ENDPOINT_DIR_MASK) != 0)
{
if (verbose > 1)
{
if (verbose > 1)
{
fprintf(stderr,
"%s: usbdev_open(): using read endpoint 0x%02x\n",
progname, possible_ep);
}
fd->usb.ep = possible_ep;
break;
fprintf(stderr,
"%s: usbdev_open(): using read endpoint 0x%02x\n",
progname, possible_ep);
}
fd->usb.rep = possible_ep;
break;
}
}
if (fd->usb.ep == -1)
if (fd->usb.rep == 0)
{
fprintf(stderr,
"%s: usbdev_open(): cannot find a read endpoint, using 0x%02x\n",
progname, USBDEV_BULK_EP_READ);
fd->usb.ep = USBDEV_BULK_EP_READ;
progname, USBDEV_BULK_EP_READ_MKII);
fd->usb.rep = USBDEV_BULK_EP_READ_MKII;
}
}
return 0;
}
trynext:
@ -273,8 +278,8 @@ static int usbdev_send(union filedescriptor *fd, unsigned char *bp, size_t mlen)
* 0.
*/
do {
tx_size = (mlen < USBDEV_MAX_XFER)? mlen: USBDEV_MAX_XFER;
rv = usb_bulk_write(udev, USBDEV_BULK_EP_WRITE, (char *)bp, tx_size, 100000);
tx_size = (mlen < fd->usb.max_xfer)? mlen: fd->usb.max_xfer;
rv = usb_bulk_write(udev, fd->usb.wep, (char *)bp, tx_size, 100000);
if (rv != tx_size)
{
fprintf(stderr, "%s: usbdev_send(): wrote %d out of %d bytes, err = %s\n",
@ -283,7 +288,7 @@ static int usbdev_send(union filedescriptor *fd, unsigned char *bp, size_t mlen)
}
bp += tx_size;
mlen -= tx_size;
} while (tx_size == USBDEV_MAX_XFER);
} while (tx_size == fd->usb.max_xfer);
if (verbose > 3)
{
@ -316,11 +321,11 @@ static int usbdev_send(union filedescriptor *fd, unsigned char *bp, size_t mlen)
* empty and more data are requested.
*/
static int
usb_fill_buf(usb_dev_handle *udev, int ep)
usb_fill_buf(usb_dev_handle *udev, int maxsize, int ep)
{
int rv;
rv = usb_bulk_read(udev, ep, usbbuf, USBDEV_MAX_XFER, 100000);
rv = usb_bulk_read(udev, ep, usbbuf, maxsize, 100000);
if (rv < 0)
{
if (verbose > 1)
@ -345,7 +350,7 @@ static int usbdev_recv(union filedescriptor *fd, unsigned char *buf, size_t nbyt
{
if (buflen <= bufptr)
{
if (usb_fill_buf(udev, fd->usb.ep) < 0)
if (usb_fill_buf(udev, fd->usb.max_xfer, fd->usb.rep) < 0)
return -1;
}
amnt = buflen - bufptr > nbytes? nbytes: buflen - bufptr;
@ -397,8 +402,8 @@ static int usbdev_recv_frame(union filedescriptor *fd, unsigned char *buf, size_
n = 0;
do
{
rv = usb_bulk_read(udev, fd->usb.ep, usbbuf,
USBDEV_MAX_XFER, 100000);
rv = usb_bulk_read(udev, fd->usb.rep, usbbuf,
fd->usb.max_xfer, 100000);
if (rv < 0)
{
if (verbose > 1)
@ -416,7 +421,7 @@ static int usbdev_recv_frame(union filedescriptor *fd, unsigned char *buf, size_
n += rv;
nbytes -= rv;
}
while (rv == USBDEV_MAX_XFER);
while (rv == fd->usb.max_xfer);
if (nbytes < 0)
return -1;
@ -450,7 +455,7 @@ static int usbdev_drain(union filedescriptor *fd, int display)
int rv;
do {
rv = usb_bulk_read(udev, fd->usb.ep, usbbuf, USBDEV_MAX_XFER, 100);
rv = usb_bulk_read(udev, fd->usb.rep, usbbuf, fd->usb.max_xfer, 100);
if (rv > 0 && verbose >= 4)
fprintf(stderr, "%s: usbdev_drain(): flushed %d characters\n",
progname, rv);

View File

@ -31,12 +31,9 @@
#define USB_DEVICE_STK600 0x2106
#define USB_DEVICE_AVRDRAGON 0x2107
/*
* Should we query the endpoint number and max transfer size from USB?
* After all, the JTAG ICE mkII docs document these values.
*/
#define USBDEV_BULK_EP_WRITE 0x02
#define USBDEV_BULK_EP_READ 0x82
#define USBDEV_MAX_XFER 64
/* JTAGICEmkII */
#define USBDEV_BULK_EP_WRITE_MKII 0x02
#define USBDEV_BULK_EP_READ_MKII 0x82
#define USBDEV_MAX_XFER_MKII 64
#endif /* usbdevs_h */