]> www.hackdaworld.org Git - my-code/fpga.git/blob - fx2/cypress_fx2_xilprg.patch
somehow dirty still accurate fix
[my-code/fpga.git] / fx2 / cypress_fx2_xilprg.patch
1 diff -Nur xilprg-0.5/makefile xilprg-patched/makefile
2 --- xilprg-0.5/makefile 2006-08-23 07:41:20.000000000 +0200
3 +++ xilprg-patched/makefile     2007-09-04 20:59:03.000000000 +0200
4 @@ -40,6 +40,7 @@
5         $(SRC_DIR)/prgfile.cpp \\r
6         $(SRC_DIR)/chip.cpp \\r
7         $(SRC_DIR)/parport.cpp \\r
8 +       $(SRC_DIR)/onbusb.cpp \\r
9         $(SRC_DIR)/cable.cpp \\r
10         $(SRC_DIR)/digilent.cpp \\r
11         $(SRC_DIR)/xilinx.cpp\r
12 diff -Nur xilprg-0.5/src/cable.cpp xilprg-patched/src/cable.cpp
13 --- xilprg-0.5/src/cable.cpp    2006-08-23 07:38:34.000000000 +0200
14 +++ xilprg-patched/src/cable.cpp        2007-09-04 20:59:03.000000000 +0200
15 @@ -49,6 +49,7 @@
16  #include "chip.h"\r
17  #include "cmdline.h"\r
18  #include "digilent.h"\r
19 +#include "onbusb.h"\r
20  #include "parport.h"\r
21  \r
22  cable::cable()\r
23 @@ -587,6 +588,9 @@
24      if (stricmp(argv[0], "dusb") == 0)\r
25          cbl = new digilent;\r
26      else\r
27 +    if (stricmp(argv[0], "ousb") ==0)\r
28 +       cbl = new onbusb;\r
29 +    else\r
30      {\r
31          msgf(STR_INVALID_CABLE_DEF);\r
32          return NULL;\r
33 diff -Nur xilprg-0.5/src/onbusb.cpp xilprg-patched/src/onbusb.cpp
34 --- xilprg-0.5/src/onbusb.cpp   1970-01-01 01:00:00.000000000 +0100
35 +++ xilprg-patched/src/onbusb.cpp       2007-09-04 22:12:47.000000000 +0200
36 @@ -0,0 +1,124 @@
37 +/*\r
38 + * onboard usb\r
39 + *\r
40 + * author: till, hunz, koppi, hackbard\r
41 + *\r
42 + */\r
43 +\r
44 +#include "xilprg.h"\r
45 +#include "utils.h"\r
46 +#include "onbusb.h"\r
47 +\r
48 +#define GET_TDO                0x20\r
49 +\r
50 +onbusb::onbusb()\r
51 +{\r
52 +   handle=NULL;\r
53 +}\r
54 +\r
55 +onbusb::~onbusb()\r
56 +{\r
57 +}\r
58 +\r
59 +int onbusb::open()\r
60 +{\r
61 +   \r
62 +    struct usb_bus *bus; \r
63 +\r
64 +    usb_init();\r
65 +    usb_find_busses();\r
66 +    usb_find_devices();\r
67 +\r
68 +    bus=usb_get_busses();\r
69 +    while(bus) {\r
70 +       dev=bus->devices;\r
71 +       while(dev) {\r
72 +               if(dev->descriptor.idVendor==USB_VENDOR_ID &&\r
73 +                  dev->descriptor.idProduct==USB_PRODUCT_ID) {\r
74 +\r
75 +                       /* found the device */\r
76 +                       handle=usb_open(dev);\r
77 +                       if(handle==NULL)\r
78 +                               goto cleanup;\r
79 +\r
80 +                       if(usb_set_configuration(handle,1)<0)\r
81 +                               goto cleanup;\r
82 +\r
83 +                       if(usb_claim_interface(handle,0)<0)\r
84 +                               goto cleanup;\r
85 +\r
86 +                       if(usb_set_altinterface(handle,1)<0)\r
87 +                               goto cleanup;\r
88 +\r
89 +                       data = 0x10;\r
90 +\r
91 +                       reset_tap_state();\r
92 +\r
93 +                       return 0;\r
94 +               }\r
95 +               dev=dev->next;\r
96 +       }\r
97 +       bus=bus->next;\r
98 +    }\r
99 +\r
100 +    return -1;\r
101 +\r
102 +cleanup:\r
103 +\r
104 +    close();\r
105 +\r
106 +    printf("usb init failed!\n");\r
107 +\r
108 +    return -1;\r
109 +\r
110 +}\r
111 +\r
112 +int onbusb::close()\r
113 +{\r
114 +\r
115 +    usb_close(handle);\r
116 +\r
117 +    return 0;\r
118 +}\r
119 +\r
120 +int onbusb::get_description(string& desc)\r
121 +{\r
122 +    char s[256];\r
123 +    sprintf(s, "onboard usb bitbanging (till, hunz, koppi, hackbard)");\r
124 +    desc = s;\r
125 +    return 0;\r
126 +}\r
127 +\r
128 +void onbusb::set_tdi(int bit)\r
129 +{\r
130 +    if (bit) data |= 0x04; else data &= ~0x04;\r
131 +    usb_bulk_write(handle,0x01,&data,1,0);\r
132 +}\r
133 +\r
134 +void onbusb::set_tck(int bit)\r
135 +{\r
136 +    if (bit) data |= 0x10; else data &= ~0x10;\r
137 +    usb_bulk_write(handle,0x01,&data,1,0);\r
138 +}\r
139 +\r
140 +void onbusb::set_tms(int bit)\r
141 +{\r
142 +    if (bit) data |= 0x08; else data &= ~0x08;\r
143 +    usb_bulk_write(handle,0x01,&data,1,0);\r
144 +}\r
145 +\r
146 +int onbusb::get_tdo()\r
147 +{\r
148 +int i;
149 +    /* send get tdo command */\r
150 +    //data=GET_TDO;\r
151 +    //usb_bulk_write(handle,0x01,&data,1,0);\r
152 +    /* receive tdo */\r
153 +    // dirty! 1 dummy read is enough. my guess:
154 +    //  - either we have to wait that time for correct state at tdi
155 +    //  - or/and it's due to the EP1INBUF=1 (buf size?) todo: ez-usb doc!
156 +    //  - initial wrong states don't harm
157 +    for(i=0;i<1;i++) usb_bulk_read(handle,0x81,&data,1,1);
158 +    usb_bulk_read(handle,0x81,&data,1,0);\r
159 +    return data & 0x01 ? 1 : 0;\r
160 +}\r
161 diff -Nur xilprg-0.5/src/onbusb.h xilprg-patched/src/onbusb.h
162 --- xilprg-0.5/src/onbusb.h     1970-01-01 01:00:00.000000000 +0100
163 +++ xilprg-patched/src/onbusb.h 2007-09-04 20:59:03.000000000 +0200
164 @@ -0,0 +1,43 @@
165 +/*\r
166 + * onboard usb\r
167 + *\r
168 + * author: till, hunz, koppi, hackbard\r
169 + *\r
170 + */\r
171 +\r
172 +#ifndef _ONBUSB_H_INCLUDED_\r
173 +#define _ONBUSB_H_INCLUDED_\r
174 +\r
175 +#include "cable.h"\r
176 +\r
177 +#include <usb.h>\r
178 +\r
179 +class onbusb : public cable\r
180 +{\r
181 +public:\r
182 +       onbusb();\r
183 +       virtual ~onbusb();\r
184 +\r
185 +    enum\r
186 +    {\r
187 +       USB_VENDOR_ID   = 0x04b4,\r
188 +       USB_PRODUCT_ID  = 0x8613\r
189 +    };\r
190 +\r
191 +    virtual int open();\r
192 +    virtual int close();\r
193 +\r
194 +    virtual int get_description(string&);\r
195 +\r
196 +    virtual void set_tdi(int);\r
197 +    virtual void set_tck(int);\r
198 +    virtual void set_tms(int);\r
199 +    virtual int get_tdo();\r
200 +\r
201 +protected:\r
202 +    char data;\r
203 +    struct usb_device *dev;\r
204 +    usb_dev_handle *handle;\r
205 +};\r
206 +\r
207 +#endif\r
208 diff -Nur xilprg-0.5/src/strtable.cpp xilprg-patched/src/strtable.cpp
209 --- xilprg-0.5/src/strtable.cpp 2006-08-23 07:38:34.000000000 +0200
210 +++ xilprg-patched/src/strtable.cpp     2007-09-04 20:59:03.000000000 +0200
211 @@ -137,7 +137,7 @@
212      //STR_CMD_CABLE\r
213      "cable\0" \r
214      "Sets programmer cable\0"\r
215 -    "cable {xil3 [ioaddr]|dusb}\0",\r
216 +    "cable {xil3 [ioaddr]|dusb|ousb}\0",\r
217      //STR_CMD_CHIPS\r
218      "chips\0"\r
219      "Prints supported devices\0" \r