Changeset 110 for sandbox/JamPlayerUSB/jbistub.c
- Timestamp:
- Feb 6, 2011, 10:48:27 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/JamPlayerUSB/jbistub.c
r109 r110 163 163 /******************************************************************/ 164 164 165 void usb_blaster_ buf_flush()165 void usb_blaster_wait(int count, int tms) 166 166 { 167 167 DWORD cnt; 168 int len; 169 170 if(usb_buf_pos > 0) 171 { 172 len = usb_buf_pos >> 3; 173 usb_buf[0] = len | 0x80; 174 175 usb_blaster_buf_write(usb_buf, len + 1, &cnt); 176 usb_buf_pos = 0; 168 169 BYTE buf[64]; 170 171 int i, len, extra; 172 173 printf("usb_blaster_wait (count tms) -> (%d %d)\n", count, tms); 174 fflush(stdout); 175 176 if (count <= 0) return; 177 178 memset(buf, 0, 64); 179 180 extra = (count & 7); 181 182 buf[0] = 0x0C | (tms ? 0x02 : 0); 183 usb_blaster_buf_write(buf, 1, &cnt); 184 185 while (count > 0) 186 { 187 if (count > 504) 188 { 189 len = 63; 190 count -= 504; 191 } 192 else 193 { 194 len = count >> 3; 195 count = 0; 196 } 197 198 if (len > 0) 199 { 200 buf[0] = len | 0x80; 201 usb_blaster_buf_write(buf, len + 1, &cnt); 202 } 203 } 204 for (i = 0; i < extra; i++) 205 { 206 jbi_jtag_io(tms, 0, 0); 177 207 } 178 208 } … … 180 210 /******************************************************************/ 181 211 182 void usb_blaster_buf_fill(int tdi) 183 { 184 int index, shift; 185 186 if (usb_buf_pos >= 504) usb_blaster_buf_flush(); 187 188 index = (usb_buf_pos >> 3) + 1; 189 shift = (usb_buf_pos & 7); 190 191 if (shift == 0) usb_buf[index] = 0; 192 193 usb_buf[index] |= ((tdi&0x01) << shift); 194 195 ++usb_buf_pos; 212 void usb_blaster_scan(int count, unsigned char *tdi, unsigned char *tdo) 213 { 214 DWORD cnt; 215 216 BYTE buf[64]; 217 218 unsigned char extra_bits; 219 220 int i, len, pos, extra, tdo_bit, read_tdo; 221 222 read_tdo = (tdo != NULL); 223 224 printf("usb_blaster_scan (count read) -> (%d %d)\n", count, read_tdo); 225 fflush(stdout); 226 227 if (count <= 0) return; 228 229 pos = 0; 230 extra = (count & 7); 231 232 if (extra == 0) 233 { 234 count -= 8; 235 extra = 8; 236 } 237 238 extra_bits = tdi[count >> 3]; 239 240 while (count > 0) 241 { 242 if (count > 504) 243 { 244 len = 63; 245 count -= 504; 246 } 247 else 248 { 249 len = count >> 3; 250 count = 0; 251 } 252 253 if (len > 0) 254 { 255 buf[0] = len | 0x80 | (read_tdo ? 0x40 : 0); 256 memcpy(buf + 1, tdi + pos, len); 257 usb_blaster_buf_write(buf, len + 1, &cnt); 258 if (read_tdo) 259 { 260 usb_blaster_buf_read(tdo + pos, len, &cnt); 261 } 262 pos += len; 263 } 264 } 265 for (i = 0; i < extra; i++) 266 { 267 tdo_bit = jbi_jtag_io( 268 (i == extra - 1), 269 extra_bits & (1 << (i & 7)), 270 read_tdo); 271 272 if (read_tdo) 273 { 274 if (tdo_bit) 275 { 276 tdo[pos] |= (1 << (i & 7)); 277 } 278 else 279 { 280 tdo[pos] &= ~(unsigned int) (1 << (i & 7)); 281 } 282 } 283 } 196 284 } 197 285 … … 205 293 */ 206 294 207 int jbi_jtag_io(int tms, int tdi, int read_tdo , int flag)208 { 209 BYTE buf[ 2];295 int jbi_jtag_io(int tms, int tdi, int read_tdo) 296 { 297 BYTE buf[3]; 210 298 DWORD count; 211 299 … … 219 307 } 220 308 221 if (flag == 0 || read_tdo) 222 { 223 /* 224 printf("(tms tdi read flag) -> (%d %d %d %d)\n", tms, tdi, read_tdo, flag); 225 fflush(stdout); 226 */ 227 usb_blaster_buf_flush(); 228 229 data = (tdi ? 0x10 : 0) | (tms ? 0x02 : 0); 230 231 buf[0] = data | 0x0C; 232 buf[1] = data | 0x01 | 0x0C | (read_tdo ? 0x40 : 0); 233 usb_blaster_buf_write(buf, 2, &count); 234 235 if (read_tdo) 236 { 237 usb_blaster_buf_read(buf, 1, &count); 238 tdo = buf[0]&0x01; 239 /* 240 printf("(tdo) -> (%d)\n", tdo); 241 fflush(stdout); 242 */ 243 } 244 } 245 else 246 { 247 usb_blaster_buf_fill(tdi ? 1 : 0); 309 data = (tdi ? 0x10 : 0) | (tms ? 0x02 : 0); 310 311 buf[0] = data | 0x0C | (read_tdo ? 0x40 : 0); 312 buf[1] = data | 0x0C | 0x01; 313 buf[2] = data | 0x0C; 314 usb_blaster_buf_write(buf, 3, &count); 315 316 if (read_tdo) 317 { 318 usb_blaster_buf_read(buf, 1, &count); 319 tdo = buf[0]&0x01; 248 320 } 249 321
Note:
See TracChangeset
for help on using the changeset viewer.