Skip to content

Commit

Permalink
src/esp_usb_jtag.cpp: toggleClock: re-uses _tdi/_tms
Browse files Browse the repository at this point in the history
  • Loading branch information
trabucayre committed Jan 16, 2025
1 parent 4efcede commit bd8bb67
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/esp_usb_jtag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ int esp_usb_jtag::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer,
if (buffer_idx >= OUT_BUF_SZ /*buf full*/ || i == len - 1 /*last*/) {
int ret = xfer(buf, NULL, buffer_idx);
if (ret < 0) {
cerr << "writeTMS: usb bulk write failed " << ret << endl;
char mess[128];
snprintf(mess, 256, "ESP USB Jtag: writeTMS failed with error %d", ret);
printError(mess);
return -EXIT_FAILURE;
}
cerr << "tms" << endl;
Expand All @@ -479,6 +481,9 @@ int esp_usb_jtag::toggleClk(uint8_t tms, uint8_t tdi, uint32_t len)
if (len == 0)
return 0;

_tms = tms;
_tdi = tdi;

uint8_t prev_high_nibble = CMD_FLUSH << 4; // for odd length 1st command is flush = nop
uint32_t buffer_idx = 0; // reset
uint8_t is_high_nibble = 1 & ~len;
Expand All @@ -488,7 +493,7 @@ int esp_usb_jtag::toggleClk(uint8_t tms, uint8_t tdi, uint32_t len)
// 2nd (low nibble) is data
// last byte in buf will have data in both nibbles, no flush
// exec order: high-nibble-first, low-nibble-second
const uint8_t cmd = CMD_CLK(0, tdi, tms);
const uint8_t cmd = CMD_CLK(0, _tdi, _tms);
for (uint32_t i = 0; i < len; i++) {
// TODO: repeat clocking with CMD_REP
if(is_high_nibble) { // 1st (high nibble) = cmd
Expand All @@ -500,7 +505,7 @@ int esp_usb_jtag::toggleClk(uint8_t tms, uint8_t tdi, uint32_t len)
}
is_high_nibble ^= 1;

if (buffer_idx >= sizeof(buf) /*buf full*/ || i == len - 1 /*last*/) {
if (buffer_idx >= OUT_BUF_SZ /*buf full*/ || i == len - 1 /*last*/) {
int ret = xfer(buf, NULL, buffer_idx);
if (ret < 0) {
char mess[128];
Expand Down

0 comments on commit bd8bb67

Please sign in to comment.