From 5876c7674b6de8b7e9e329d9065c4657244e2ecb Mon Sep 17 00:00:00 2001 From: dragonmux Date: Fri, 22 Jul 2022 14:33:34 +0100 Subject: [PATCH] hosted/remote_jtagtap: Refactored jtagtap_tms_seq and cleaned up --- src/platforms/hosted/remote_jtagtap.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/platforms/hosted/remote_jtagtap.c b/src/platforms/hosted/remote_jtagtap.c index cdb7a65..fa51cb4 100644 --- a/src/platforms/hosted/remote_jtagtap.c +++ b/src/platforms/hosted/remote_jtagtap.c @@ -37,7 +37,7 @@ #include "bmp_remote.h" static void jtagtap_reset(void); -static void jtagtap_tms_seq(uint32_t MS, size_t ticks); +static void jtagtap_tms_seq(uint32_t tms_states, 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 *data_in, size_t clock_cycles); static bool jtagtap_next(bool tms, bool tdi); @@ -95,22 +95,20 @@ static void jtagtap_reset(void) } } -static void jtagtap_tms_seq(uint32_t MS, size_t ticks) +static void jtagtap_tms_seq(uint32_t tms_states, size_t clock_cycles) { - uint8_t construct[REMOTE_MAX_MSG_SIZE]; - int s; + char buffer[REMOTE_MAX_MSG_SIZE]; + int length = snprintf(buffer, REMOTE_MAX_MSG_SIZE, REMOTE_JTAG_TMS_STR, clock_cycles, tms_states); + platform_buffer_write((uint8_t *)buffer, length); - s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, REMOTE_JTAG_TMS_STR, ticks, MS); - platform_buffer_write(construct, s); - - s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); - if ((!s) || (construct[0] == REMOTE_RESP_ERR)) { - DEBUG_WARN("jtagtap_tms_seq failed, error %s\n", s ? (char *)&(construct[1]) : "unknown"); + length = platform_buffer_read((uint8_t *)buffer, REMOTE_MAX_MSG_SIZE); + if (!length || buffer[0] == REMOTE_RESP_ERR) { + DEBUG_WARN("jtagtap_tms_seq failed, error %s\n", length ? buffer + 1 : "unknown"); exit(-1); } } -/* At least up to v1.7.1-233, remote handles only up to 32 ticks in one +/* At least up to v1.7.1-233, remote handles only up to 32 clock cycles in one * call. Break up large calls. * * FIXME: Provide and test faster call and keep fallback