dap: Cleaned up the naming and signature of the JTAG TAP DAP functions
This commit is contained in:
parent
96cdd17974
commit
46958ba404
|
@ -444,9 +444,9 @@ unsigned int dap_write_block(ADIv5_AP_t *ap, uint32_t dest, const void *src,
|
||||||
buf[2] = sz & 0xff;
|
buf[2] = sz & 0xff;
|
||||||
buf[3] = (sz >> 8) & 0xff;
|
buf[3] = (sz >> 8) & 0xff;
|
||||||
buf[4] = SWD_AP_DRW;
|
buf[4] = SWD_AP_DRW;
|
||||||
if (align > ALIGN_HALFWORD) {
|
if (align > ALIGN_HALFWORD)
|
||||||
memcpy(&buf[5], src, len);
|
memcpy(&buf[5], src, len);
|
||||||
} else {
|
else {
|
||||||
unsigned int size = len;
|
unsigned int size = len;
|
||||||
uint32_t *p = (uint32_t *)&buf[5];
|
uint32_t *p = (uint32_t *)&buf[5];
|
||||||
while (size) {
|
while (size) {
|
||||||
|
@ -463,7 +463,7 @@ unsigned int dap_write_block(ADIv5_AP_t *ap, uint32_t dest, const void *src,
|
||||||
*p++ = tmp;
|
*p++ = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbg_dap_cmd(buf, 1023, 5 + (sz << 2));
|
dbg_dap_cmd(buf, 1023, 5 + (sz << 2U));
|
||||||
if (buf[2] > DAP_TRANSFER_FAULT) {
|
if (buf[2] > DAP_TRANSFER_FAULT) {
|
||||||
dap_line_reset();
|
dap_line_reset();
|
||||||
}
|
}
|
||||||
|
@ -655,19 +655,18 @@ void dap_write_single(ADIv5_AP_t *ap, uint32_t dest, const void *src,
|
||||||
dbg_dap_cmd(buf, sizeof(buf), p - buf);
|
dbg_dap_cmd(buf, sizeof(buf), p - buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dap_jtagtap_tdi_tdo_seq(uint8_t *DO, bool final_tms, const uint8_t *TMS,
|
void dap_jtagtap_tdi_tdo_seq(
|
||||||
const uint8_t *DI, int ticks)
|
uint8_t *data_out, bool const final_tms, const uint8_t *tms, const uint8_t *data_in, size_t ticks)
|
||||||
{
|
{
|
||||||
DEBUG_PROBE("dap_jtagtap_tdi_tdo_seq %s %d ticks\n",
|
DEBUG_PROBE("dap_jtagtap_tdi_tdo_seq %s %d ticks\n", final_tms ? "final" : "", ticks);
|
||||||
(final_tms) ? "final" : "", ticks);
|
|
||||||
uint8_t buf[64];
|
uint8_t buf[64];
|
||||||
const uint8_t *din = DI;
|
const uint8_t *din = data_in;
|
||||||
uint8_t *dout = DO;
|
uint8_t *dout = data_out;
|
||||||
if (!TMS) {
|
if (!tms) {
|
||||||
int last_byte = last_byte = (ticks - 1) >> 3;
|
int last_byte = last_byte = (ticks - 1) >> 3;
|
||||||
int last_bit = (ticks - 1) & 7;
|
int last_bit = (ticks - 1) & 7;
|
||||||
if (final_tms)
|
if (final_tms)
|
||||||
ticks --;
|
ticks--;
|
||||||
while (ticks) {
|
while (ticks) {
|
||||||
int transfers = ticks;
|
int transfers = ticks;
|
||||||
if (transfers > 64)
|
if (transfers > 64)
|
||||||
|
@ -675,8 +674,7 @@ void dap_jtagtap_tdi_tdo_seq(uint8_t *DO, bool final_tms, const uint8_t *TMS,
|
||||||
uint8_t *p = buf;
|
uint8_t *p = buf;
|
||||||
*p++ = ID_DAP_JTAG_SEQUENCE;
|
*p++ = ID_DAP_JTAG_SEQUENCE;
|
||||||
*p++ = 1;
|
*p++ = 1;
|
||||||
*p++ = ((transfers == 64) ? 0 : transfers) |
|
*p++ = ((transfers == 64) ? 0 : transfers) | ((data_out) ? DAP_JTAG_TDO_CAPTURE : 0);
|
||||||
((DO) ? DAP_JTAG_TDO_CAPTURE : 0);
|
|
||||||
int n_di_bytes = (transfers + 7) >> 3;
|
int n_di_bytes = (transfers + 7) >> 3;
|
||||||
if (din) {
|
if (din) {
|
||||||
p = memcpy(p, din, n_di_bytes);
|
p = memcpy(p, din, n_di_bytes);
|
||||||
|
@ -700,7 +698,7 @@ void dap_jtagtap_tdi_tdo_seq(uint8_t *DO, bool final_tms, const uint8_t *TMS,
|
||||||
*p++ = 1;
|
*p++ = 1;
|
||||||
*p++ = 1 | ((dout) ? DAP_JTAG_TDO_CAPTURE : 0) | DAP_JTAG_TMS;
|
*p++ = 1 | ((dout) ? DAP_JTAG_TDO_CAPTURE : 0) | DAP_JTAG_TMS;
|
||||||
if (din) {
|
if (din) {
|
||||||
*p++ = ((DI[last_byte] & (1 << last_bit)) ? 1 : 0);
|
*p++ = ((data_in[last_byte] & (1 << last_bit)) ? 1 : 0);
|
||||||
} else {
|
} else {
|
||||||
*p++ = 0;
|
*p++ = 0;
|
||||||
}
|
}
|
||||||
|
@ -709,13 +707,13 @@ void dap_jtagtap_tdi_tdo_seq(uint8_t *DO, bool final_tms, const uint8_t *TMS,
|
||||||
DEBUG_WARN("dap_jtagtap_tdi_tdo_seq failed %02x\n", buf[0]);
|
DEBUG_WARN("dap_jtagtap_tdi_tdo_seq failed %02x\n", buf[0]);
|
||||||
if (dout) {
|
if (dout) {
|
||||||
if (buf[1] & 1)
|
if (buf[1] & 1)
|
||||||
DO[last_byte] |= (1 << last_bit);
|
data_out[last_byte] |= (1 << last_bit);
|
||||||
else
|
else
|
||||||
DO[last_byte] &= ~(1 << last_bit);
|
data_out[last_byte] &= ~(1 << last_bit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while(ticks) {
|
while (ticks) {
|
||||||
uint8_t *p = buf;
|
uint8_t *p = buf;
|
||||||
int transfers = ticks;
|
int transfers = ticks;
|
||||||
if (transfers > 64)
|
if (transfers > 64)
|
||||||
|
@ -724,22 +722,22 @@ void dap_jtagtap_tdi_tdo_seq(uint8_t *DO, bool final_tms, const uint8_t *TMS,
|
||||||
*p++ = ID_DAP_JTAG_SEQUENCE;
|
*p++ = ID_DAP_JTAG_SEQUENCE;
|
||||||
*p++ = transfers;
|
*p++ = transfers;
|
||||||
for (int i = 0; i < transfers; i++) {
|
for (int i = 0; i < transfers; i++) {
|
||||||
*p++ = 1 | ((DO) ? DAP_JTAG_TDO_CAPTURE : 0) |
|
*p++ =
|
||||||
((TMS[i >> 3] & (1 << (i & 7))) ? DAP_JTAG_TMS : 0);
|
1 | ((data_out) ? DAP_JTAG_TDO_CAPTURE : 0) | ((tms[i >> 3] & (1 << (i & 7))) ? DAP_JTAG_TMS : 0);
|
||||||
if (DI)
|
if (data_in)
|
||||||
*p++ = (DI[i >> 3] & (1 << (i & 7))) ? 1 : 0;
|
*p++ = (data_in[i >> 3] & (1 << (i & 7))) ? 1 : 0;
|
||||||
else
|
else
|
||||||
*p++ = 1;
|
*p++ = 1;
|
||||||
}
|
}
|
||||||
dbg_dap_cmd(buf, sizeof(buf), p - buf);
|
dbg_dap_cmd(buf, sizeof(buf), p - buf);
|
||||||
if (buf[0] == DAP_ERROR)
|
if (buf[0] == DAP_ERROR)
|
||||||
DEBUG_WARN("dap_jtagtap_tdi_tdo_seq failed %02x\n", buf[0]);
|
DEBUG_WARN("dap_jtagtap_tdi_tdo_seq failed %02x\n", buf[0]);
|
||||||
if (DO) {
|
if (data_out) {
|
||||||
for (int i = 0; i < transfers; i++) {
|
for (int i = 0; i < transfers; i++) {
|
||||||
if (buf[i + 1])
|
if (buf[i + 1])
|
||||||
DO[i >> 3] |= (1 << (i & 7));
|
data_out[i >> 3] |= (1 << (i & 7));
|
||||||
else
|
else
|
||||||
DO[i >> 3] &= ~(1 << (i & 7));
|
data_out[i >> 3] &= ~(1 << (i & 7));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ticks -= transfers;
|
ticks -= transfers;
|
||||||
|
@ -766,32 +764,36 @@ int dap_jtag_configure(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dap_swdptap_seq_out(uint32_t MS, int ticks)
|
void dap_swdptap_seq_out(uint32_t tms_states, int clock_cycles)
|
||||||
{
|
{
|
||||||
|
/* clang-format off */
|
||||||
uint8_t buf[64] = {
|
uint8_t buf[64] = {
|
||||||
ID_DAP_SWJ_SEQUENCE,
|
ID_DAP_SWJ_SEQUENCE,
|
||||||
ticks,
|
clock_cycles,
|
||||||
(MS >> 0) & 0xff,
|
(tms_states >> 0) & 0xff,
|
||||||
(MS >> 8) & 0xff,
|
(tms_states >> 8) & 0xff,
|
||||||
(MS >> 16) & 0xff,
|
(tms_states >> 16) & 0xff,
|
||||||
(MS >> 24) & 0xff
|
(tms_states >> 24) & 0xff
|
||||||
};
|
};
|
||||||
dbg_dap_cmd(buf, 64, 2 + ((ticks +7) >> 3));
|
/* clang-format on */
|
||||||
|
dbg_dap_cmd(buf, 64, 2U + ((clock_cycles + 7U) >> 3U));
|
||||||
if (buf[0])
|
if (buf[0])
|
||||||
DEBUG_WARN("dap_swdptap_seq_out error\n");
|
DEBUG_WARN("dap_swdptap_seq_out error\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void dap_swdptap_seq_out_parity(uint32_t MS, int ticks)
|
void dap_swdptap_seq_out_parity(uint32_t tms_states, int clock_cycles)
|
||||||
{
|
{
|
||||||
|
/* clang-format off */
|
||||||
uint8_t buf[] = {
|
uint8_t buf[] = {
|
||||||
ID_DAP_SWJ_SEQUENCE,
|
ID_DAP_SWJ_SEQUENCE,
|
||||||
ticks + 1,
|
clock_cycles + 1,
|
||||||
(MS >> 0) & 0xff,
|
(tms_states >> 0) & 0xff,
|
||||||
(MS >> 8) & 0xff,
|
(tms_states >> 8) & 0xff,
|
||||||
(MS >> 16) & 0xff,
|
(tms_states >> 16) & 0xff,
|
||||||
(MS >> 24) & 0xff,
|
(tms_states >> 24) & 0xff,
|
||||||
__builtin_parity(MS) & 1
|
__builtin_parity(tms_states)
|
||||||
};
|
};
|
||||||
|
/* clang-format on */
|
||||||
dbg_dap_cmd(buf, 1, sizeof(buf));
|
dbg_dap_cmd(buf, 1, sizeof(buf));
|
||||||
if (buf[0])
|
if (buf[0])
|
||||||
DEBUG_WARN("dap_swdptap_seq_out error\n");
|
DEBUG_WARN("dap_swdptap_seq_out error\n");
|
||||||
|
|
|
@ -81,9 +81,9 @@ void dap_ap_write(ADIv5_AP_t *ap, uint16_t addr, uint32_t value);
|
||||||
void dap_read_single(ADIv5_AP_t *ap, void *dest, uint32_t src, enum align align);
|
void dap_read_single(ADIv5_AP_t *ap, void *dest, uint32_t src, enum align align);
|
||||||
void dap_write_single(ADIv5_AP_t *ap, uint32_t dest, const void *src, enum align align);
|
void dap_write_single(ADIv5_AP_t *ap, uint32_t dest, const void *src, enum align align);
|
||||||
int dbg_dap_cmd(uint8_t *data, int size, int rsize);
|
int dbg_dap_cmd(uint8_t *data, int size, int rsize);
|
||||||
void dap_jtagtap_tdi_tdo_seq(uint8_t *DO, bool final_tms, const uint8_t *TMS, const uint8_t *DI, int ticks);
|
void dap_jtagtap_tdi_tdo_seq(uint8_t *data_out, bool final_tms, const uint8_t *tms, const uint8_t *data_in, size_t clock_cycles);
|
||||||
int dap_jtag_configure(void);
|
int dap_jtag_configure(void);
|
||||||
void dap_swdptap_seq_out(uint32_t MS, int ticks);
|
void dap_swdptap_seq_out(uint32_t tms_states, int clock_cycles);
|
||||||
void dap_swdptap_seq_out_parity(uint32_t MS, int ticks);
|
void dap_swdptap_seq_out_parity(uint32_t tms_states, int clock_cycles);
|
||||||
|
|
||||||
#endif // _DAP_H_
|
#endif // _DAP_H_
|
||||||
|
|
Loading…
Reference in New Issue