Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit 82a0581

Browse files
committed
hosted/jlink: Rewrite jtagtap_cycles using plain for-loops and bitmasking
1 parent 774a1b9 commit 82a0581

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/platforms/hosted/jlink_jtag.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,19 @@ static bool jlink_jtag_next(bool tms, bool tdi)
123123

124124
static void jlink_jtag_cycle(const bool tms, const bool tdi, const size_t clock_cycles)
125125
{
126-
uint8_t tms_buf[8] = {0};
127-
uint8_t tdi_buf[8] = {0};
128-
if (clock_cycles > 64U)
126+
uint8_t tms_buf[512] = {0};
127+
uint8_t tdi_buf[512] = {0};
128+
if (clock_cycles > 4096U)
129129
return;
130-
const uint64_t all_ones = clock_cycles == 64U ? UINT64_MAX : (UINT64_C(1) << clock_cycles) - 1U;
131-
const uint64_t tms_pattern = tms ? all_ones : 0U;
132-
const uint64_t tdi_pattern = tdi ? all_ones : 0U;
133-
memcpy(tms_buf, &tms_pattern, 8);
134-
memcpy(tdi_buf, &tdi_pattern, 8);
130+
const size_t clock_bytes = clock_cycles >> 3U;
131+
memset(tms_buf, tms ? 0xffU : 0U, clock_bytes);
132+
memset(tdi_buf, tdi ? 0xffU : 0U, clock_bytes);
133+
const size_t clock_bits = clock_cycles & 7U;
134+
if (clock_bits) {
135+
const uint8_t ones = (1U << clock_bits) - 1U;
136+
tms_buf[clock_bytes] = tms ? ones : 0U;
137+
tdi_buf[clock_bytes] = tdi ? ones : 0U;
138+
}
135139
DEBUG_PROBE("jtagtap_cycle tms=%u tdi=%u, clock cycles: %zu\n", tms, tdi, clock_cycles);
136140
const bool result = jlink_transfer(clock_cycles, tms_buf, tdi_buf, NULL);
137141
if (!result)

0 commit comments

Comments
 (0)