|
|
@ -276,8 +276,7 @@ static int libztex_configureFpgaHS(struct libztex_device *ztex, const char* firm |
|
|
|
struct libztex_fpgastate state; |
|
|
|
struct libztex_fpgastate state; |
|
|
|
const int transactionBytes = 65536; |
|
|
|
const int transactionBytes = 65536; |
|
|
|
unsigned char buf[transactionBytes], settings[2]; |
|
|
|
unsigned char buf[transactionBytes], settings[2]; |
|
|
|
int tries, cnt, buf_p, i; |
|
|
|
int tries, cnt, err, i; |
|
|
|
ssize_t pos = 0; |
|
|
|
|
|
|
|
FILE *fp; |
|
|
|
FILE *fp; |
|
|
|
|
|
|
|
|
|
|
|
if (!libztex_checkCapability(ztex, CAPABILITY_HS_FPGA)) |
|
|
|
if (!libztex_checkCapability(ztex, CAPABILITY_HS_FPGA)) |
|
|
@ -302,52 +301,25 @@ static int libztex_configureFpgaHS(struct libztex_device *ztex, const char* firm |
|
|
|
return -2; |
|
|
|
return -2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
while (pos < transactionBytes && !feof(fp)) { |
|
|
|
libusb_control_transfer(ztex->hndl, 0x40, 0x34, 0, 0, NULL, 0, 1000); |
|
|
|
buf[pos++] = getc(fp); |
|
|
|
// 0x34 - initHSFPGAConfiguration
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (feof(fp)) |
|
|
|
do |
|
|
|
pos--; |
|
|
|
{ |
|
|
|
|
|
|
|
int length = fread(buf,1,transactionBytes,fp); |
|
|
|
|
|
|
|
|
|
|
|
if (bs != 0 && bs != 1) |
|
|
|
if (bs != 0 && bs != 1) |
|
|
|
bs = libztex_detectBitstreamBitOrder(buf, transactionBytes < pos? transactionBytes: pos); |
|
|
|
bs = libztex_detectBitstreamBitOrder(buf, length); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bs == 1) |
|
|
|
if (bs == 1) |
|
|
|
libztex_swapBits(buf, pos); |
|
|
|
libztex_swapBits(buf, length); |
|
|
|
|
|
|
|
|
|
|
|
libusb_control_transfer(ztex->hndl, 0x40, 0x34, 0, 0, NULL, 0, 1000); |
|
|
|
err = libusb_bulk_transfer(ztex->hndl, settings[0], buf, length, &cnt, 1000); |
|
|
|
// 0x34 - initHSFPGAConfiguration
|
|
|
|
if (cnt != length) |
|
|
|
|
|
|
|
applog(LOG_ERR, "%s: cnt != length", ztex->repr); |
|
|
|
buf_p = pos; |
|
|
|
if (err != 0) |
|
|
|
while (1) { |
|
|
|
|
|
|
|
i = 0; |
|
|
|
|
|
|
|
while (i < buf_p) { |
|
|
|
|
|
|
|
if (libusb_bulk_transfer(ztex->hndl, |
|
|
|
|
|
|
|
settings[0], |
|
|
|
|
|
|
|
&buf[i], |
|
|
|
|
|
|
|
buf_p - i, |
|
|
|
|
|
|
|
&cnt, 1000) != 0) { |
|
|
|
|
|
|
|
applog(LOG_ERR, "%s: Failed send hs fpga data", ztex->repr); |
|
|
|
applog(LOG_ERR, "%s: Failed send hs fpga data", ztex->repr); |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
usleep(500); |
|
|
|
|
|
|
|
i += cnt; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (i < buf_p || buf_p < transactionBytes) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
buf_p = 0; |
|
|
|
|
|
|
|
while (buf_p < transactionBytes && !feof(fp)) { |
|
|
|
|
|
|
|
buf[buf_p++] = getc(fp); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (feof(fp)) |
|
|
|
|
|
|
|
buf_p--; |
|
|
|
|
|
|
|
pos += buf_p; |
|
|
|
|
|
|
|
if (buf_p == 0) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
if (bs == 1) |
|
|
|
|
|
|
|
libztex_swapBits(buf, buf_p); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
while (!feof(fp)); |
|
|
|
|
|
|
|
|
|
|
|
libusb_control_transfer(ztex->hndl, 0x40, 0x35, 0, 0, NULL, 0, 1000); |
|
|
|
libusb_control_transfer(ztex->hndl, 0x40, 0x35, 0, 0, NULL, 0, 1000); |
|
|
|
// 0x35 - finishHSFPGAConfiguration
|
|
|
|
// 0x35 - finishHSFPGAConfiguration
|
|
|
|