1 /* JTAG low-level I/O to DLC9(10?) cables
2 
3 Using I2C addresses above 0x80 in the USRP/XGUFF framework
4 
5 Copyright (C) 2005-2011 Uwe Bonnes 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 #ifndef IOXPC_H
23 #define IOXPC_H
24 
25 #include <usb.h>
26 
27 #include "iobase.h"
28 
29 #define XPC_VENDOR 0x03fd
30 #define XPC_DEVICE 0x0008
31 
32 #define XPC_INTERNAL 1
33 
34 #define XPC_PROG    (1<<3)
35 #define XPC_TCK     (1<<2)
36 #define XPC_TMS     (1<<1)
37 #define XPC_TDI     (1<<0)
38 #define XPC_TDO     (1<<0)
39 
40 /*
41  * send max 4096 bytes to CPLD
42  * this is equal to 8192 TDI plus 8192 TDO bits
43  */
44 #define CPLD_MAX_BYTES (1<<12)
45 
46 /*
47  * Buffer has to hold 8192 bits for write, each 2 bytes hold 4 bits for write, so this has to be 4096
48  * Buffer has to hold 8192 bits for read, each byte holds 8 bits for read, so this has to be 1024
49  * Therefore, buffer size -> CPLD_MAX_BYTES
50  */
51 typedef struct
52 {
53         int in_bits;
54         int out_bits;
55         int out_done;
56         unsigned char *out;
57         unsigned char buf[CPLD_MAX_BYTES];
58 }
59 xpc_ext_transfer_state_t;
60 
61 
62 class IOXPC : public IOBase
63 {
64  protected:
65   int bptr, calls_rd, calls_wr, call_ctrl;
66   int subtype;
67   unsigned long long hid;
68   FILE *fp_dbg;
69 
70  public:
71   IOXPC();
72   int Init(struct cable_t *cable, char const *serial, unsigned int freq);
73   ~IOXPC();
74 
75   void txrx_block(const unsigned char *tdi, unsigned char *tdo, int length, bool last);
76   void tx_tms(unsigned char *pat, int length, int force);
77 
78  private:
79   struct usb_dev_handle *xpcu;
80   /// String representation of last error
81   const char *error_str;
82   int xpcu_output_enable(struct usb_dev_handle *xpcu, int enable);
83   int xpcu_request_28(struct usb_dev_handle *xpcu, int value);
84   int xpcu_write_gpio(struct usb_dev_handle *xpcu, unsigned char bits);
85   int xpcu_read_gpio(struct usb_dev_handle *xpcu, unsigned char *bits);
86   int xpcu_read_cpld_version(struct usb_dev_handle *xpcu, unsigned char *buf);
87   int xpcu_read_hid(struct usb_dev_handle *xpcu);
88   int xpcu_read_firmware_version(struct usb_dev_handle *xpcu, unsigned char *buf);
89   int xpcu_select_gpio(struct usb_dev_handle *xpcu, int int_or_ext );
90   int xpcu_shift(struct usb_dev_handle *xpcu, int reqno, int bits, int in_len, unsigned char *in, int out_len, unsigned char *out );
91   void xpcu_add_bit_for_ext_transfer( xpc_ext_transfer_state_t *xts, bool in, bool tms, bool is_real );
92   int xpcu_do_ext_transfer( xpc_ext_transfer_state_t *xts );
93 
94   int xpc_usb_open_desc(int vendor, int product, const char* description, unsigned long long int serial);
95   bool xpc_close_interface (struct usb_dev_handle *udh);
96 };
97 
98 #endif // IOXPC_H
99