dirtyJtag: writeTDI: fixed last Byte align

This commit is contained in:
Gwenhael Goavec-Merou 2026-01-02 09:52:41 +01:00
parent d654a9d6d5
commit 6a7bd29e0d
1 changed files with 14 additions and 3 deletions

View File

@ -214,11 +214,10 @@ int DirtyJtag::writeTMS(const uint8_t *tms, uint32_t len,
return len; return len;
} }
int DirtyJtag::toggleClk(uint8_t tms, __attribute__((unused)) uint8_t tdi, int DirtyJtag::toggleClk(__attribute__((unused)) uint8_t tms,
uint32_t clk_len) __attribute__((unused)) uint8_t tdi, uint32_t clk_len)
{ {
int actual_length; int actual_length;
_tms = tms ? SIG_TMS : 0;
uint8_t buf[] = {CMD_CLK, uint8_t buf[] = {CMD_CLK,
static_cast<uint8_t>(_tms | _tdi), static_cast<uint8_t>(_tms | _tdi),
0, 0,
@ -319,6 +318,18 @@ int DirtyJtag::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end)
rx_ptr[rx_cnt >> 3] = (rx_ptr[rx_cnt >> 3] >> 1) | rx_ptr[rx_cnt >> 3] = (rx_ptr[rx_cnt >> 3] >> 1) |
(((rx_buf[i >> 3] << (i&0x07)) & 0x80)); (((rx_buf[i >> 3] << (i&0x07)) & 0x80));
} }
/* Last xfer:
* if bit_to_send is not a multiple of 8bits a shift must
* be applied to align rigth the last Byte
*/
if (bit_to_send < max_bit_transfer_length) {
const uint32_t b = (bit_to_send >> 3) << 3; // floor
if (b < bit_to_send) { // difference ?
const uint32_t diff = bit_to_send - b;
const uint8_t t = rx_ptr[(rx_cnt-1) >> 3] >> (8 - diff);
rx_ptr[(rx_cnt - 1) >> 3] = t;
}
}
} }
real_bit_len -= bit_to_send; real_bit_len -= bit_to_send;