int jtag_shift(int count, unsigned bits, unsigned *out) { unsigned char buf[64]; unsigned RB = out ? UB_READBACK : 0; int n = 0; int readcount = count; int r,bit; #if TRACE_JTAG fprintf(stderr,"xfer: %08x (%d)\n", bits, count); #endif while (count-- > 0) { if (bits & 1) { buf[n++] = UB_TDI; buf[n++] = UB_TDI | UB_TCK | RB; } else { buf[n++] = 0; buf[n++] = UB_TCK | RB; } bits >>= 1; } buf[n-1] |= UB_TMS; buf[n-2] |= UB_TMS; r = usb_bulk(EP2_OUT, buf, n, 1000); if (r < 0) return r; if (!out) return 0; bits = 0; bit = 1; while (readcount > 0) { r = usb_bulk(EP1_IN, buf, 64, 1000); if (r < 0) return r; if (r < 3) continue; for (n = 2; n < r; n++) { if (buf[n] & 1) bits |= bit; bit <<= 1; readcount--; if (readcount == 0) { #if TRACE_JTAG fprintf(stderr," : %08x\n", bits); #endif *out = bits; return 0; } } } return -1; }
/******************************************************************************* 功能:在指定的USB设备上进行bulk读操作,无16KB限制 注意: 作者:宇浩然 时间:2012.04.21 参数:dev为设备指针,data为数据缓冲地址,size计划读取的字符数,timeout为时间 返回值: <0失败;其他为实际读取的字符数 *******************************************************************************/ int tf09_bulk_read(const tf09_device * dev, void *data, int size, int timeout) { if (NULL == dev) dev = tf09Device; if (NULL == dev || dev->fd <= 0 || NULL == data) return -1; return usb_bulk(dev->fd, 129, (void *)data, size, timeout); }
int jtag_move(int count, unsigned bits){ unsigned char buf[64]; int n = 0; #if TRACE_JTAG fprintf(stderr,"move: %08x (%d)\n", bits, count); #endif while (count-- > 0) { if (bits & 1) { buf[n++] = UB_TMS; buf[n++] = UB_TMS | UB_TCK; } else { buf[n++] = 0; buf[n++] = UB_TCK; } bits >>= 1; } return usb_bulk(EP2_OUT, buf, n, 1000); }