X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/usb-driver/blobdiff_plain/0a060ead2d6293cc1e4227918d52258b71f9e716..913cbbf6e4397c7f02c50488ea1fbb6b3ee0430b:/jtagkey.c diff --git a/jtagkey.c b/jtagkey.c index 19011fa..04bd0cd 100644 --- a/jtagkey.c +++ b/jtagkey.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "usb-driver.h" #include "config.h" #include "jtagkey.h" @@ -31,7 +32,7 @@ static int jtagkey_latency(int latency) { return ret; } -static int jtagkey_init(unsigned short vid, unsigned short pid) { +static int jtagkey_init(unsigned short vid, unsigned short pid, unsigned short iface) { int ret = 0; unsigned char c; @@ -40,6 +41,11 @@ static int jtagkey_init(unsigned short vid, unsigned short pid) { return ret; } + if ((ret = ftdi_set_interface(&ftdic, iface)) != 0) { + fprintf(stderr, "unable to set interface: %d (%s)\n", ret, ftdi_get_error_string(&ftdic)); + return ret; + } + if ((ret = ftdi_usb_open(&ftdic, vid, pid)) != 0) { fprintf(stderr, "unable to open ftdi device: %d (%s)\n", ret, ftdi_get_error_string(&ftdic)); return ret; @@ -50,11 +56,6 @@ static int jtagkey_init(unsigned short vid, unsigned short pid) { return ret; } - if ((ret = ftdi_set_interface(&ftdic, INTERFACE_A)) != 0) { - fprintf(stderr, "unable to set interface: %d (%s)\n", ret, ftdi_get_error_string(&ftdic)); - return ret; - } - if ((ret = ftdi_write_data_set_chunksize(&ftdic, USBBUFSIZE)) != 0) { fprintf(stderr, "unable to set write chunksize: %d (%s)\n", ret, ftdi_get_error_string(&ftdic)); return ret; @@ -92,7 +93,7 @@ static int jtagkey_init(unsigned short vid, unsigned short pid) { int jtagkey_open(int num) { int ret; - ret = jtagkey_init(config_usb_vid(num), config_usb_pid(num)); + ret = jtagkey_init(config_usb_vid(num), config_usb_pid(num), config_usb_iface(num)); if (ret >= 0) ret = 0xff; @@ -108,7 +109,8 @@ void jtagkey_close(int handle) { } } -void jtagkey_state(unsigned char data) { +#ifdef DEBUG +static void jtagkey_state(unsigned char data) { fprintf(stderr,"Pins high: "); if (data & JTAGKEY_TCK) @@ -128,6 +130,7 @@ void jtagkey_state(unsigned char data) { fprintf(stderr,"\n"); } +#endif struct jtagkey_reader_arg { int num; @@ -172,7 +175,7 @@ int jtagkey_transfer(WD_TRANSFER *tr, int fd, unsigned int request, int ppbase, 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 %zd bytes due to %d following reads in %d chunks or full buffer\n", writepos-writebuf, nread, num); jtagkey_latency(BULK_LATENCY); targ.num = writepos-pos; @@ -185,7 +188,7 @@ int jtagkey_transfer(WD_TRANSFER *tr, int fd, unsigned int request, int ppbase, if (len > USBBUFSIZE) len = USBBUFSIZE; - DPRINTF("combined write of %d/%d\n",len,writepos-pos); + DPRINTF("combined write of %d/%zd\n",len,writepos-pos); ftdi_write_data(&ftdic, pos, len); pos += len; } @@ -209,7 +212,7 @@ int jtagkey_transfer(WD_TRANSFER *tr, int fd, unsigned int request, int ppbase, DPRINTF("write byte: %d\n", val); if (tr[i].cmdTrans == 13) - tapmon(val & PP_TCK, val & PP_TMS); + jtagmon(val & PP_TCK, val & PP_TMS, val & PP_TDI); #endif /* Pad writebuf for read-commands in stream */ @@ -276,7 +279,7 @@ int jtagkey_transfer(WD_TRANSFER *tr, int fd, unsigned int request, int ppbase, if (nread) { - DPRINTF("writing %d bytes\n", writepos-writebuf); + DPRINTF("writing %zd bytes\n", writepos-writebuf); *writepos = last_data; writepos++; @@ -290,10 +293,8 @@ int jtagkey_transfer(WD_TRANSFER *tr, int fd, unsigned int request, int ppbase, pthread_join(reader_thread, NULL); #ifdef DEBUG - DPRINTF("write: "); - hexdump(writebuf, writepos-writebuf); - DPRINTF("read: "); - hexdump(readbuf, i); + hexdump(writebuf, writepos-writebuf, "->"); + hexdump(readbuf, i, "<-"); #endif writepos = writebuf;