Skip to content

Commit 6a7bd29

Browse files
committed
dirtyJtag: writeTDI: fixed last Byte align
1 parent d654a9d commit 6a7bd29

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/dirtyJtag.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,10 @@ int DirtyJtag::writeTMS(const uint8_t *tms, uint32_t len,
214214
return len;
215215
}
216216

217-
int DirtyJtag::toggleClk(uint8_t tms, __attribute__((unused)) uint8_t tdi,
218-
uint32_t clk_len)
217+
int DirtyJtag::toggleClk(__attribute__((unused)) uint8_t tms,
218+
__attribute__((unused)) uint8_t tdi, uint32_t clk_len)
219219
{
220220
int actual_length;
221-
_tms = tms ? SIG_TMS : 0;
222221
uint8_t buf[] = {CMD_CLK,
223222
static_cast<uint8_t>(_tms | _tdi),
224223
0,
@@ -319,6 +318,18 @@ int DirtyJtag::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end)
319318
rx_ptr[rx_cnt >> 3] = (rx_ptr[rx_cnt >> 3] >> 1) |
320319
(((rx_buf[i >> 3] << (i&0x07)) & 0x80));
321320
}
321+
/* Last xfer:
322+
* if bit_to_send is not a multiple of 8bits a shift must
323+
* be applied to align rigth the last Byte
324+
*/
325+
if (bit_to_send < max_bit_transfer_length) {
326+
const uint32_t b = (bit_to_send >> 3) << 3; // floor
327+
if (b < bit_to_send) { // difference ?
328+
const uint32_t diff = bit_to_send - b;
329+
const uint8_t t = rx_ptr[(rx_cnt-1) >> 3] >> (8 - diff);
330+
rx_ptr[(rx_cnt - 1) >> 3] = t;
331+
}
332+
}
322333
}
323334

324335
real_bit_len -= bit_to_send;

0 commit comments

Comments
 (0)