ftdiJtagMPSSE: Fix TCK toggle for large numbers.

This commit is contained in:
Uwe Bonnes 2021-09-19 17:28:41 +02:00
parent 5101e58274
commit 9d813664d9
1 changed files with 19 additions and 12 deletions

View File

@ -168,20 +168,27 @@ int FtdiJtagMPSSE::toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len)
if (_ftdi->type == TYPE_2232H || _ftdi->type == TYPE_4232H || if (_ftdi->type == TYPE_2232H || _ftdi->type == TYPE_4232H ||
_ftdi->type == TYPE_232H) { _ftdi->type == TYPE_232H) {
uint8_t buf[] = {static_cast<uint8_t>(0x8f), 0, 0}; uint8_t buf[] = {static_cast<uint8_t>(0x8f), 0, 0};
if (clk_len > 8) { while (len) {
buf[1] = ((len / 8) ) & 0xff; unsigned int chunk = len;
buf[2] = ((len / 8) >> 8) & 0xff; if (chunk > 0x10000 * 8)
mpsse_store(buf, 3); chunk = 0x10000 * 8;
len %= 8; if (chunk > 8) {
unsigned cycles8 = chunk / 8;
len -= cycles8 * 8;
cycles8 --;
buf[1] = ((cycles8) ) & 0xff;
buf[2] = ((cycles8) >> 8) & 0xff;
mpsse_store(buf, 3);
} }
if (len && len < 9) {
if (len > 0) { buf[0] = 0x8E;
buf[0] = 0x8E; buf[1] = len - 1;
buf[1] = len - 1; mpsse_store(buf, 2);
mpsse_store(buf, 2); len = 0;
} }
ret = clk_len; }
ret = clk_len;
} else { } else {
int byteLen = (len+7)/8; int byteLen = (len+7)/8;
uint8_t buf_tms[byteLen]; uint8_t buf_tms[byteLen];