jtagtap: Cleaned up and fixed the signatures for the JTAG TAP implementation functions

This commit is contained in:
dragonmux 2022-07-16 01:45:26 +01:00 committed by Piotr Esden-Tempski
parent 46958ba404
commit d1c24b4fec
8 changed files with 83 additions and 85 deletions

View File

@ -22,6 +22,8 @@
#define __JTAGTAP_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
typedef struct jtag_proc_s {
/* Note: Signal names are as for the device under test. */
@ -36,8 +38,8 @@ typedef struct jtag_proc_s {
* - Caputure the value on TDO
* - Release TCK.
*/
uint8_t (*jtagtap_next)(const uint8_t tms, const uint8_t tdi);
void (*jtagtap_tms_seq)(uint32_t tms_states, int clock_cycles);
bool (*jtagtap_next)(const bool tms, const bool tdi);
void (*jtagtap_tms_seq)(uint32_t tms_states, size_t clock_cycles);
/*
* Shift out a sequence on MS and DI, capture data to DO.
@ -45,8 +47,8 @@ typedef struct jtag_proc_s {
* - DO may be NULL to ignore captured data.
* - DO may be point to the same address as DI.
*/
void (*jtagtap_tdi_tdo_seq)(uint8_t *data_out, const uint8_t final_tms, const uint8_t *data_in, int clock_cycles);
void (*jtagtap_tdi_seq)(const uint8_t final_tms, const uint8_t *data_in, int clock_cycles);
void (*jtagtap_tdi_tdo_seq)(uint8_t *data_out, const bool final_tms, const uint8_t *data_in, size_t clock_cycles);
void (*jtagtap_tdi_seq)(const bool final_tms, const uint8_t *data_in, size_t clock_cycles);
} jtag_proc_t;
extern jtag_proc_t jtag_proc;

View File

@ -29,10 +29,10 @@
jtag_proc_t jtag_proc;
static void jtagtap_reset(void);
static void jtagtap_tms_seq(uint32_t tms_states, int ticks);
static void jtagtap_tdi_tdo_seq(uint8_t *data_out, uint8_t final_tms, const uint8_t *data_in, int ticks);
static void jtagtap_tdi_seq(uint8_t final_tms, const uint8_t *data_in, int ticks);
static uint8_t jtagtap_next(uint8_t tms, uint8_t tdi);
static void jtagtap_tms_seq(uint32_t tms_states, size_t ticks);
static void jtagtap_tdi_tdo_seq(uint8_t *data_out, bool final_tms, const uint8_t *data_in, size_t ticks);
static void jtagtap_tdi_seq(bool final_tms, const uint8_t *data_in, size_t ticks);
static bool jtagtap_next(bool tms, bool tdi);
int jtagtap_init()
{
@ -66,7 +66,7 @@ static void jtagtap_reset(void)
jtagtap_soft_reset();
}
static uint8_t jtagtap_next(const uint8_t tms, const uint8_t tdi)
static bool jtagtap_next(const bool tms, const bool tdi)
{
register volatile int32_t cnt;
@ -113,7 +113,7 @@ static void jtagtap_tms_seq_no_delay(uint32_t tms_states, size_t ticks)
}
}
static void jtagtap_tms_seq(uint32_t tms_states, int ticks)
static void jtagtap_tms_seq(uint32_t tms_states, size_t ticks)
{
gpio_set(TDI_PORT, TDI_PIN);
if (swd_delay_cnt)
@ -179,7 +179,7 @@ static void jtagtap_tdi_tdo_seq_no_delay(const uint8_t *data_in, uint8_t *data_o
data_out[byte] = value;
}
static void jtagtap_tdi_tdo_seq(uint8_t *data_out, const uint8_t final_tms, const uint8_t *data_in, int ticks)
static void jtagtap_tdi_tdo_seq(uint8_t *data_out, const bool final_tms, const uint8_t *data_in, size_t ticks)
{
gpio_clear(TDI_PORT, TDI_PIN);
if (swd_delay_cnt)
@ -232,7 +232,7 @@ static void jtagtap_tdi_seq_no_delay(const uint8_t *data_in, const bool final_tm
}
}
static void jtagtap_tdi_seq(const uint8_t final_tms, const uint8_t *data_in, int ticks)
static void jtagtap_tdi_seq(const bool final_tms, const uint8_t *data_in, size_t ticks)
{
if (swd_delay_cnt)
jtagtap_tdi_seq_swd_delay(data_in, final_tms, ticks);

View File

@ -442,32 +442,34 @@ static void cmsis_dap_jtagtap_reset(void)
/* Is there a way to know if TRST is available?*/
}
static void cmsis_dap_jtagtap_tms_seq(uint32_t MS, int ticks)
static void cmsis_dap_jtagtap_tms_seq(const uint32_t tms_states, const size_t ticks)
{
uint8_t TMS[4] = {MS & 0xff, (MS >> 8) & 0xff, (MS >> 16) & 0xff,
(MS >> 24) & 0xff};
dap_jtagtap_tdi_tdo_seq(NULL, false, TMS, NULL, ticks);
DEBUG_PROBE("tms_seq DI %08x %d\n", MS, ticks);
const uint8_t tms[4] = {
(uint8_t)tms_states, (uint8_t)(tms_states >> 8U), (uint8_t)(tms_states >> 16U), (uint8_t)(tms_states >> 24U)};
dap_jtagtap_tdi_tdo_seq(NULL, false, tms, NULL, ticks);
DEBUG_PROBE("tms_seq data_in %08x %zu\n", tms_states, ticks);
}
static void cmsis_dap_jtagtap_tdi_tdo_seq(uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int ticks)
static void cmsis_dap_jtagtap_tdi_tdo_seq(uint8_t *const data_out, const bool final_tms, const uint8_t *const data_in, const size_t ticks)
{
dap_jtagtap_tdi_tdo_seq(DO, (final_tms), NULL, DI, ticks);
DEBUG_PROBE("jtagtap_tdi_tdo_seq %d, %02x-> %02x\n", ticks, DI[0], (DO)? DO[0] : 0);
dap_jtagtap_tdi_tdo_seq(data_out, final_tms, NULL, data_in, ticks);
DEBUG_PROBE("jtagtap_tdi_tdo_seq %zu, %02x-> %02x\n", ticks, data_in[0], data_out ? data_out[0] : 0);
}
static void cmsis_dap_jtagtap_tdi_seq(const uint8_t final_tms, const uint8_t *DI, int ticks)
static void cmsis_dap_jtagtap_tdi_seq(const bool final_tms, const uint8_t *const data_in, const size_t ticks)
{
dap_jtagtap_tdi_tdo_seq(NULL, (final_tms), NULL, DI, ticks);
DEBUG_PROBE("jtagtap_tdi_seq %d, %02x\n", ticks, DI[0]);
dap_jtagtap_tdi_tdo_seq(NULL, final_tms, NULL, data_in, ticks);
DEBUG_PROBE("jtagtap_tdi_seq %zu, %02x\n", ticks, data_in[0]);
}
static uint8_t cmsis_dap_jtagtap_next(uint8_t dTMS, uint8_t dTDI)
static bool cmsis_dap_jtagtap_next(const bool tms, const bool tdi)
{
uint8_t tdo[1];
dap_jtagtap_tdi_tdo_seq(tdo, false, &dTMS, &dTDI, 1);
DEBUG_PROBE("next tms %02x tdi %02x tdo %02x\n", dTMS, dTDI, tdo[0]);
return (tdo[0] & 1);
const uint8_t tms_byte = tms ? 1 : 0;
const uint8_t tdi_byte = tdi ? 1 : 0;
uint8_t tdo = 0;
dap_jtagtap_tdi_tdo_seq(&tdo, false, &tms_byte, &tdi_byte, 1);
DEBUG_PROBE("next tms %02x tdi %02x tdo %02x\n", tms, tdi, tdo);
return tdo;
}
int cmsis_dap_jtagtap_init(jtag_proc_t *jtag_proc)
@ -479,11 +481,11 @@ int cmsis_dap_jtagtap_init(jtag_proc_t *jtag_proc)
dap_disconnect();
dap_connect(true);
dap_reset_link(true);
jtag_proc->jtagtap_reset = cmsis_dap_jtagtap_reset;
jtag_proc->jtagtap_next = cmsis_dap_jtagtap_next;
jtag_proc->jtagtap_tms_seq = cmsis_dap_jtagtap_tms_seq;
jtag_proc->jtagtap_reset = cmsis_dap_jtagtap_reset;
jtag_proc->jtagtap_next = cmsis_dap_jtagtap_next;
jtag_proc->jtagtap_tms_seq = cmsis_dap_jtagtap_tms_seq;
jtag_proc->jtagtap_tdi_tdo_seq = cmsis_dap_jtagtap_tdi_tdo_seq;
jtag_proc->jtagtap_tdi_seq = cmsis_dap_jtagtap_tdi_seq;
jtag_proc->jtagtap_tdi_seq = cmsis_dap_jtagtap_tdi_seq;
return 0;
}

View File

@ -628,8 +628,7 @@ int libftdi_buffer_read(uint8_t *data, int size)
return size;
}
void libftdi_jtagtap_tdi_tdo_seq(
uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int ticks)
void libftdi_jtagtap_tdi_tdo_seq(uint8_t *DO, const bool final_tms, const uint8_t *DI, size_t ticks)
{
int rsize, rticks;

View File

@ -109,8 +109,8 @@ void libftdi_buffer_flush(void) { }
int libftdi_buffer_write(const uint8_t *data, int size) { return size; }
int libftdi_buffer_read(uint8_t *data, int size) { return size; }
const char *libftdi_target_voltage(void) { return "ERROR"; }
void libftdi_jtagtap_tdi_tdo_seq(
uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int ticks) { }
void libftdi_jtagtap_tdi_tdo_seq(uint8_t *const data_out, const bool final_tms,
const uint8_t *const data_in, const size_t ticks) { }
bool libftdi_swd_possible(bool *do_mpsse, bool *direct_bb_swd) { return false; }
void libftdi_max_frequency_set(uint32_t freq) { }
uint32_t libftdi_max_frequency_get(void) { return 0; }
@ -131,8 +131,7 @@ void libftdi_buffer_flush(void);
int libftdi_buffer_write(const uint8_t *data, int size);
int libftdi_buffer_read(uint8_t *data, int size);
const char *libftdi_target_voltage(void);
void libftdi_jtagtap_tdi_tdo_seq(
uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int ticks);
void libftdi_jtagtap_tdi_tdo_seq(uint8_t *data_out, bool final_tms, const uint8_t *data_in, size_t ticks);
bool libftdi_swd_possible(bool *do_mpsse, bool *direct_bb_swd);
void libftdi_max_frequency_set(uint32_t freq);
uint32_t libftdi_max_frequency_get(void);

View File

@ -35,9 +35,9 @@ static void jtagtap_reset(void)
jtagtap_soft_reset();
}
static void jtagtap_tms_seq(uint32_t MS, int ticks)
static void jtagtap_tms_seq(uint32_t tms_states, size_t ticks)
{
DEBUG_PROBE("jtagtap_tms_seq 0x%08" PRIx32 ", ticks %d\n", MS, ticks);
DEBUG_PROBE("jtagtap_tms_seq 0x%08" PRIx32 ", ticks %d\n", tms_states, ticks);
int len = (ticks + 7) / 8;
uint8_t cmd[12];
cmd[0] = CMD_HW_JTAG3;
@ -46,10 +46,10 @@ static void jtagtap_tms_seq(uint32_t MS, int ticks)
cmd[3] = 0;
uint8_t *tms = cmd + 4;
for (int i = 0; i < len; i++) {
*tms = MS & 0xff;
*tms = tms_states & 0xff;
*(tms + len) = *tms;
tms++;
MS >>= 8;
tms_states >>= 8;
}
uint8_t res[4];
send_recv(info.usb_link, cmd, 4 + 2 * len, res, len);
@ -58,17 +58,17 @@ static void jtagtap_tms_seq(uint32_t MS, int ticks)
raise_exception(EXCEPTION_ERROR, "tagtap_tms_seq failed");
}
static void jtagtap_tdi_tdo_seq(uint8_t *DO, const uint8_t final_tms,
const uint8_t *DI, int ticks)
static void jtagtap_tdi_tdo_seq(uint8_t *data_out, const bool final_tms,
const uint8_t *data_in, size_t ticks)
{
if (!ticks)
return;
int len = (ticks + 7) / 8;
if (cl_debuglevel & BMP_DEBUG_PROBE) {
DEBUG_PROBE("jtagtap_tdi_tdo %s, ticks %d, DI: ",
DEBUG_PROBE("jtagtap_tdi_tdo %s, ticks %d, data_in: ",
(final_tms) ? "Final TMS" : "", ticks);
for (int i = 0; i < len; i++) {
DEBUG_PROBE("%02x", DI[i]);
DEBUG_PROBE("%02x", data_in[i]);
}
DEBUG_PROBE("\n");
}
@ -83,11 +83,11 @@ static void jtagtap_tdi_tdo_seq(uint8_t *DO, const uint8_t final_tms,
if (final_tms)
cmd[4 + (ticks - 1) / 8] |= (1 << ((ticks - 1) % 8));
uint8_t *tdi = tms;
if (DI)
if (data_in)
for (int i = 0; i < len; i++)
*tdi++ = DI[i];
if (DO)
send_recv(info.usb_link, cmd, 4 + 2 * len, DO, len);
*tdi++ = data_in[i];
if (data_out)
send_recv(info.usb_link, cmd, 4 + 2 * len, data_out, len);
else
send_recv(info.usb_link, cmd, 4 + 2 * len, cmd, len);
uint8_t res[1];
@ -96,12 +96,12 @@ static void jtagtap_tdi_tdo_seq(uint8_t *DO, const uint8_t final_tms,
raise_exception(EXCEPTION_ERROR, "jtagtap_tdi_tdi failed");
}
static void jtagtap_tdi_seq(const uint8_t final_tms, const uint8_t *DI,
int ticks)
static void jtagtap_tdi_seq(const bool final_tms, const uint8_t *data_in,
size_t ticks)
{
if (cl_debuglevel & BMP_DEBUG_PROBE) {
DEBUG_PROBE("jtagtap_tdi_seq %s:", (final_tms)? "final_tms" : "");
const uint8_t *p = DI;
const uint8_t *p = data_in;
unsigned int i = (ticks & 7) & ~7 ;
if (i > 16)
i = 16;
@ -111,19 +111,19 @@ static void jtagtap_tdi_seq(const uint8_t final_tms, const uint8_t *DI,
DEBUG_PROBE(" ...");
DEBUG_PROBE("\n");
}
return jtagtap_tdi_tdo_seq(NULL, final_tms, DI, ticks);
return jtagtap_tdi_tdo_seq(NULL, final_tms, data_in, ticks);
}
static uint8_t jtagtap_next(uint8_t dTMS, uint8_t dTDI)
static bool jtagtap_next(bool tms, bool tdi)
{
DEBUG_PROBE("jtagtap_next TMS 0x%02x, TDI %02x\n", dTMS, dTDI);
DEBUG_PROBE("jtagtap_next TMS 0x%02x, TDI %02x\n", tms, tdi);
uint8_t cmd[6];
cmd[0] = CMD_HW_JTAG3;
cmd[1] = 0;
cmd[2] = 1;
cmd[3] = 0;
cmd[4] = (dTMS) ? 0xff : 0;
cmd[5] = (dTDI) ? 0xff : 0;
cmd[4] = tms ? 0xff : 0;
cmd[5] = tdi ? 0xff : 0;
uint8_t ret[1];
send_recv(info.usb_link, cmd, 6, ret, 1);
uint8_t res[1];

View File

@ -33,10 +33,9 @@ extern cable_desc_t *active_cable;
extern struct ftdi_context *ftdic;
static void jtagtap_reset(void);
static void jtagtap_tms_seq(uint32_t MS, int ticks);
static void jtagtap_tdi_seq(
const uint8_t final_tms, const uint8_t *DI, int ticks);
static uint8_t jtagtap_next(uint8_t dTMS, uint8_t dTDI);
static void jtagtap_tms_seq(uint32_t tms_states, size_t ticks);
static void jtagtap_tdi_seq(bool final_tms, const uint8_t *DI, size_t ticks);
static bool jtagtap_next(bool dTMS, bool dTDI);
int libftdi_jtagtap_init(jtag_proc_t *jtag_proc)
{
@ -95,26 +94,28 @@ static void jtagtap_reset(void)
jtagtap_soft_reset();
}
static void jtagtap_tms_seq(uint32_t MS, int ticks)
static void jtagtap_tms_seq(uint32_t tms_states, size_t ticks)
{
uint8_t tmp[3] = {
MPSSE_WRITE_TMS | MPSSE_LSB | MPSSE_BITMODE | MPSSE_WRITE_NEG, 0, 0};
while(ticks >= 0) {
tmp[1] = ticks<7?ticks-1:6;
tmp[2] = 0x80 | (MS & 0x7F);
uint8_t tmp[3] = {MPSSE_WRITE_TMS | MPSSE_LSB | MPSSE_BITMODE | MPSSE_WRITE_NEG, 0, 0};
while (ticks > 0) {
tmp[1] = ticks < 7 ? ticks - 1 : 6;
tmp[2] = 0x80 | (tms_states & 0x7F);
libftdi_buffer_write(tmp, 3);
MS >>= 7; ticks -= 7;
tms_states >>= 7;
if (ticks < 7)
ticks = 0;
else
ticks -= 7;
}
}
static void jtagtap_tdi_seq(
const uint8_t final_tms, const uint8_t *DI, int ticks)
static void jtagtap_tdi_seq(const bool final_tms, const uint8_t *DI, size_t ticks)
{
return libftdi_jtagtap_tdi_tdo_seq(NULL, final_tms, DI, ticks);
}
static uint8_t jtagtap_next(uint8_t dTMS, uint8_t dTDI)
static bool jtagtap_next(bool dTMS, bool dTDI)
{
uint8_t ret;
uint8_t tmp[3] = {MPSSE_WRITE_TMS | MPSSE_DO_READ | MPSSE_LSB |

View File

@ -36,12 +36,10 @@
#include "bmp_remote.h"
static void jtagtap_reset(void);
static void jtagtap_tms_seq(uint32_t MS, int ticks);
static void jtagtap_tdi_tdo_seq(
uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int ticks);
static void jtagtap_tdi_seq(
const uint8_t final_tms, const uint8_t *DI, int ticks);
static uint8_t jtagtap_next(uint8_t dTMS, uint8_t dTDI);
static void jtagtap_tms_seq(uint32_t MS, size_t ticks);
static void jtagtap_tdi_tdo_seq(uint8_t *DO, bool final_tms, const uint8_t *DI, size_t ticks);
static void jtagtap_tdi_seq(bool final_tms, const uint8_t *DI, size_t ticks);
static bool jtagtap_next(bool dTMS, bool dTDI);
int remote_jtagtap_init(jtag_proc_t *jtag_proc)
{
@ -87,7 +85,7 @@ static void jtagtap_reset(void)
}
}
static void jtagtap_tms_seq(uint32_t MS, int ticks)
static void jtagtap_tms_seq(uint32_t MS, size_t ticks)
{
uint8_t construct[REMOTE_MAX_MSG_SIZE];
int s;
@ -110,8 +108,7 @@ static void jtagtap_tms_seq(uint32_t MS, int ticks)
* FIXME: Provide and test faster call and keep fallback
* for old firmware
*/
static void jtagtap_tdi_tdo_seq(
uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int ticks)
static void jtagtap_tdi_tdo_seq(uint8_t *DO, const bool final_tms, const uint8_t *DI, size_t ticks)
{
uint8_t construct[REMOTE_MAX_MSG_SIZE];
int s;
@ -159,14 +156,12 @@ static void jtagtap_tdi_tdo_seq(
}
}
static void jtagtap_tdi_seq(
const uint8_t final_tms, const uint8_t *DI, int ticks)
static void jtagtap_tdi_seq(const bool final_tms, const uint8_t *DI, size_t ticks)
{
return jtagtap_tdi_tdo_seq(NULL, final_tms, DI, ticks);
}
static uint8_t jtagtap_next(uint8_t dTMS, uint8_t dTDI)
static bool jtagtap_next(bool dTMS, bool dTDI)
{
uint8_t construct[REMOTE_MAX_MSG_SIZE];
int s;