1 /* JTAG GNU/Linux FTDI FT2232 low-level I/O 2 3 Copyright (C) 2006 Dmitry Teytelman 4 Additions (C) 2005-2011 Uwe Bonnes 5 bon@elektron.ikp.physik.tu-darmstadt.de 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 20 21 22 23 #ifndef IOFTDI_H 24 #define IOFTDI_H 25 26 #include <ftdi.h> 27 #include <usb.h> 28 #if defined (__WIN32__) 29 #include <windows.h> 30 #endif 31 32 #ifdef USE_FTD2XX 33 #include <ftd2xx.h> 34 #endif 35 36 #include "iobase.h" 37 #include "cabledb.h" 38 39 #define VENDOR_FTDI 0x0403 40 #define DEVICE_DEF 0x6010 41 42 #define TX_BUF (4096) 43 44 class IOFtdi : public IOBase 45 { 46 protected: 47 #ifdef USE_FTD2XX 48 FT_HANDLE ftd2xx_handle; 49 #endif 50 struct ftdi_context *ftdi_handle; 51 unsigned char usbuf[TX_BUF]; 52 int buflen; 53 bool use_ftd2xx; 54 struct cable_t *cable; 55 unsigned int bptr; 56 int calls_rd, calls_wr, subtype, retries; 57 FILE *fp_dbg; 58 59 public: 60 IOFtdi(bool use_ftd2xx); 61 ~IOFtdi(); 62 int Init(struct cable_t *cable, const char * serial, unsigned int freq); 63 void settype(int subtype); 64 void txrx_block(const unsigned char *tdi, unsigned char *tdo, int length, bool last); 65 void tx_tms(unsigned char *pat, int length, int force); 66 void flush(void); 67 68 private: 69 void deinit(void); 70 void mpsse_add_cmd(unsigned char const *buf, int len); 71 void mpsse_send(void); 72 unsigned int readusb(unsigned char * rbuf, unsigned long len); 73 }; 74 75 76 #endif // IOFTDI_H 77