summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
3e67022)
it now takes 5 seconds to program a xc3s400, which is the same time it
takes to program this chip with a parallel cable.
#include "usb-driver.h"
#include "jtagkey.h"
#include "usb-driver.h"
#include "jtagkey.h"
static struct ftdi_context ftdic;
static struct ftdi_context ftdic;
+static unsigned int usb_maxlen = 0;
int jtagkey_init(unsigned short vid, unsigned short pid) {
int ret = 0;
int jtagkey_init(unsigned short vid, unsigned short pid) {
int ret = 0;
-#if 0
- if ((ret = ftdi_write_data_set_chunksize(&ftdic, 1)) != 0) {
- fprintf(stderr, "unable to set write chunksize: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
+
+ if ((ret = ftdi_write_data_get_chunksize(&ftdic, &usb_maxlen)) != 0) {
+ fprintf(stderr, "unable to get write chunksize: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
if ((ret = ftdi_set_latency_timer(&ftdic, 1)) != 0) {
fprintf(stderr, "unable to set latency timer: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
if ((ret = ftdi_set_latency_timer(&ftdic, 1)) != 0) {
fprintf(stderr, "unable to set latency timer: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
c = 0x00;
ftdi_write_data(&ftdic, &c, 1);
c = 0x00;
ftdi_write_data(&ftdic, &c, 1);
- if ((ret = ftdi_set_bitmode(&ftdic, JTAGKEY_TCK|JTAGKEY_TDI|JTAGKEY_TMS|JTAGKEY_OEn, BITMODE_SYNCBB)) != 0) {
+ if ((ret = ftdi_set_bitmode(&ftdic, JTAGKEY_TCK|JTAGKEY_TDI|JTAGKEY_TMS|JTAGKEY_OEn, BITMODE_BITBANG)) != 0) {
fprintf(stderr, "unable to enable bitbang mode: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
return ret;
}
fprintf(stderr, "unable to enable bitbang mode: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
return ret;
}
/* Write combining */
if ((writepos-writebuf > sizeof(writebuf)-num) || (nread && writepos-writebuf)) {
/* Write combining */
if ((writepos-writebuf > sizeof(writebuf)-num) || (nread && writepos-writebuf)) {
+ unsigned char *pos = writebuf;
+ int len;
DPRINTF("writing %d bytes due to %d following reads in %d chunks or full buffer\n", writepos-writebuf, nread, num);
DPRINTF("writing %d bytes due to %d following reads in %d chunks or full buffer\n", writepos-writebuf, nread, num);
- ftdi_write_data(&ftdic, writebuf, writepos-writebuf);
+ len = writepos-pos;
+
+ while (pos < writepos) {
+ if (len > usb_maxlen)
+ len = usb_maxlen;
- i = 0;
- while (i < writepos-writebuf) {
- i += ftdi_read_data(&ftdic, readbuf, sizeof(readbuf));
+ DPRINTF("combined write of %d/%d\n",len,writepos-pos);
+ ftdi_write_data(&ftdic, pos, len);
+ pos += len;
DPRINTF("read %d/%d bytes\n", i, writepos-writebuf);
writepos = writebuf;
}
DPRINTF("read %d/%d bytes\n", i, writepos-writebuf);
writepos = writebuf;
}
if (nread)
{
DPRINTF("writing %d bytes\n", writepos-writebuf);
if (nread)
{
DPRINTF("writing %d bytes\n", writepos-writebuf);
- ftdi_write_data(&ftdic, writebuf, writepos-writebuf);
- DPRINTF("reading %d bytes\n", writepos-writebuf);
-
- i = 0;
- while (i < writepos-writebuf) {
- i += ftdi_read_data(&ftdic, readbuf, sizeof(readbuf));
+ for (i=0; i<writepos-writebuf; i++) {
+ ftdi_write_data(&ftdic, writebuf+i, 1);
+ ftdi_read_pins(&ftdic, readbuf+i);
- DPRINTF("read %d bytes\n", i);
#ifdef DEBUG
DPRINTF("write: ");
#ifdef DEBUG
DPRINTF("write: ");