hosted/remote_jtagtap: Refactored jtagtap_tdi_tdo_seq and cleaned up

This commit is contained in:
dragonmux 2022-07-22 14:29:08 +01:00 committed by Piotr Esden-Tempski
parent 8177e3c723
commit 267dabacb1
1 changed files with 32 additions and 36 deletions

View File

@ -38,8 +38,8 @@
static void jtagtap_reset(void); static void jtagtap_reset(void);
static void jtagtap_tms_seq(uint32_t MS, size_t ticks); static void jtagtap_tms_seq(uint32_t MS, size_t ticks);
static void jtagtap_tdi_tdo_seq(uint8_t *DO, bool final_tms, const uint8_t *DI, size_t ticks); static void jtagtap_tdi_tdo_seq(uint8_t *data_out, bool final_tms, const uint8_t *data_in, size_t clock_cycles);
static void jtagtap_tdi_seq(bool final_tms, const uint8_t *DI, size_t ticks); static void jtagtap_tdi_seq(bool final_tms, const uint8_t *data_in, size_t clock_cycles);
static bool jtagtap_next(bool tms, bool tdi); static bool jtagtap_next(bool tms, bool tdi);
static void jtagtap_cycle(bool tms, bool tdi, size_t clock_cycles); static void jtagtap_cycle(bool tms, bool tdi, size_t clock_cycles);
@ -116,53 +116,49 @@ static void jtagtap_tms_seq(uint32_t MS, size_t ticks)
* FIXME: Provide and test faster call and keep fallback * FIXME: Provide and test faster call and keep fallback
* for old firmware * for old firmware
*/ */
static void jtagtap_tdi_tdo_seq(uint8_t *DO, const bool final_tms, const uint8_t *DI, size_t ticks) static void jtagtap_tdi_tdo_seq(uint8_t *const data_out, const bool final_tms, const uint8_t *const data_in, const size_t clock_cycles)
{ {
uint8_t construct[REMOTE_MAX_MSG_SIZE]; if (!clock_cycles || (!data_in && !data_out))
int s;
if (!ticks || (!DI && !DO))
return; return;
while (ticks) {
int chunk; char buffer[REMOTE_MAX_MSG_SIZE];
if (ticks < 65) size_t in_offset = 0;
chunk = ticks; size_t out_offset = 0;
else { for (size_t cycle = 0; cycle < clock_cycles; ) {
size_t chunk;
if (clock_cycles - cycle <= 64)
chunk = clock_cycles - cycle;
else
chunk = 64; chunk = 64;
} cycle += chunk;
ticks -= chunk;
uint64_t di = 0; uint64_t data = 0;
int bytes = (chunk + 7) >> 3; const size_t bytes = (chunk + 7U) >> 3U;
int i = 0; if (data_in) {
if (DI) { for (size_t i = 0; i < bytes; ++i)
for (; i < bytes; i++) { data |= data_in[in_offset++] << (i * 8U);
di |= *DI << (i * 8);
DI++;
}
} }
/* PRIx64 differs with system. Use it explicit in the format string*/ /* PRIx64 differs with system. Use it explicit in the format string*/
s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, "!J%c%02x%" PRIx64 "%c", int length = snprintf(buffer, REMOTE_MAX_MSG_SIZE, "!J%c%02zx%" PRIx64 "%c",
(!ticks && final_tms) ? REMOTE_TDITDO_TMS : REMOTE_TDITDO_NOTMS, chunk, di, REMOTE_EOM); !clock_cycles && final_tms ? REMOTE_TDITDO_TMS : REMOTE_TDITDO_NOTMS, chunk, data, REMOTE_EOM);
platform_buffer_write(construct, s); platform_buffer_write((uint8_t *)buffer, length);
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); length = platform_buffer_read((uint8_t *)buffer, REMOTE_MAX_MSG_SIZE);
if ((!s) || (construct[0] == REMOTE_RESP_ERR)) { if (!length || buffer[0] == REMOTE_RESP_ERR) {
DEBUG_WARN("jtagtap_tms_seq failed, error %s\n", s ? (char *)&(construct[1]) : "unknown"); DEBUG_WARN("jtagtap_tms_seq failed, error %s\n", length ? buffer + 1 : "unknown");
exit(-1); exit(-1);
} }
if (DO) { if (data_out) {
uint64_t res = remotehston(-1, (char *)&construct[1]); const uint64_t data = remotehston(-1, buffer + 1);
for (i = bytes; i > 0; i--) { for (size_t i = 0; i < bytes; ++i)
*DO++ = res & 0xff; data_out[out_offset++] = (uint8_t)(data >> (i * 8U));
res >>= 8;
}
} }
} }
} }
static void jtagtap_tdi_seq(const bool final_tms, const uint8_t *DI, size_t ticks) static void jtagtap_tdi_seq(const bool final_tms, const uint8_t *data_in, size_t clock_cycles)
{ {
return jtagtap_tdi_tdo_seq(NULL, final_tms, DI, ticks); return jtagtap_tdi_tdo_seq(NULL, final_tms, data_in, clock_cycles);
} }
static bool jtagtap_next(const bool tms, const bool tdi) static bool jtagtap_next(const bool tms, const bool tdi)