script: open probe by sequential index, hex id still accepted
jtag_get_probes_list now prints a flat [N] index; jtag_open_probe takes that index (decimal) or, if 0x-prefixed, the raw probe id. Avoids the trap of typing "1" and hitting a non-existent (drv 0, probe 1).
This commit is contained in:
@@ -1733,16 +1733,38 @@ const char *cmd_print_probes_list_help[] = {
|
|||||||
"Displays the list of detected probes.", // Explanations
|
"Displays the list of detected probes.", // Explanations
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
|
/* Map the flat index shown by jtag_get_probes_list (0, 1, 2, ...) to the
|
||||||
|
* encoded (drv << 8 | probe) id, walking drivers/probes in the same order
|
||||||
|
* the list prints them. Returns -1 if the index is out of range. */
|
||||||
|
static int resolve_flat_probe_index(jtag_core *jc, int flat)
|
||||||
|
{
|
||||||
|
int nb_of_drivers = jtagcore_get_number_of_probes_drv(jc);
|
||||||
|
int j, i, n = 0;
|
||||||
|
|
||||||
|
for (j = 0; j < nb_of_drivers; j++)
|
||||||
|
{
|
||||||
|
int nb_of_probes = jtagcore_get_number_of_probes(jc, j);
|
||||||
|
for (i = 0; i < nb_of_probes; i++)
|
||||||
|
{
|
||||||
|
if (n == flat)
|
||||||
|
return PROBE_ID(j, i);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static int cmd_print_probes_list(script_ctx *ctx, char *line)
|
static int cmd_print_probes_list(script_ctx *ctx, char *line)
|
||||||
{
|
{
|
||||||
jtag_core *jc;
|
jtag_core *jc;
|
||||||
int i, j;
|
int i, j, flat;
|
||||||
char probe_list[64];
|
char probe_list[64];
|
||||||
int nb_of_drivers, nb_of_probes;
|
int nb_of_drivers, nb_of_probes;
|
||||||
|
|
||||||
jc = (jtag_core *)ctx->app_ctx;
|
jc = (jtag_core *)ctx->app_ctx;
|
||||||
|
|
||||||
nb_of_drivers = jtagcore_get_number_of_probes_drv(jc);
|
nb_of_drivers = jtagcore_get_number_of_probes_drv(jc);
|
||||||
|
flat = 0;
|
||||||
j = 0;
|
j = 0;
|
||||||
while (j < nb_of_drivers)
|
while (j < nb_of_drivers)
|
||||||
{
|
{
|
||||||
@@ -1751,7 +1773,10 @@ static int cmd_print_probes_list(script_ctx *ctx, char *line)
|
|||||||
while (i < nb_of_probes)
|
while (i < nb_of_probes)
|
||||||
{
|
{
|
||||||
jtagcore_get_probe_name(jc, PROBE_ID(j, i), probe_list);
|
jtagcore_get_probe_name(jc, PROBE_ID(j, i), probe_list);
|
||||||
ctx->script_printf(ctx, MSG_INFO_0, "ID 0x%.8X [drv %d, probe %d] %s\n", PROBE_ID(j, i), j, i, probe_list);
|
// [flat index] is what to pass to jtag_open_probe; the
|
||||||
|
// 0x id after it is the raw form, also accepted.
|
||||||
|
ctx->script_printf(ctx, MSG_INFO_0, " [%d] 0x%.8X %s\n", flat, PROBE_ID(j, i), probe_list);
|
||||||
|
flat++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
@@ -1761,13 +1786,15 @@ static int cmd_print_probes_list(script_ctx *ctx, char *line)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *cmd_open_probe_help[] = {
|
const char *cmd_open_probe_help[] = {
|
||||||
"<probe_id>(int)", // Arguments "1<arg>(type) ..."
|
"<probe>(int)", // Arguments "1<arg>(type) ..."
|
||||||
"The probe id as given in the 'jtag_probe_list' function.",
|
"Open a probe by its index from jtag_get_probes_list (0, 1, 2, ...).",
|
||||||
|
"A raw 0x-prefixed probe id (as printed after the index) also works.",
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
static int cmd_open_probe(script_ctx *ctx, char *line)
|
static int cmd_open_probe(script_ctx *ctx, char *line)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
int id;
|
||||||
char probe_id[64];
|
char probe_id[64];
|
||||||
jtag_core *jc;
|
jtag_core *jc;
|
||||||
|
|
||||||
@@ -1775,7 +1802,24 @@ static int cmd_open_probe(script_ctx *ctx, char *line)
|
|||||||
|
|
||||||
if (get_param(ctx, line, 1, probe_id) > 0)
|
if (get_param(ctx, line, 1, probe_id) > 0)
|
||||||
{
|
{
|
||||||
ret = jtagcore_select_and_open_probe(jc, strtoul(probe_id, NULL, 16));
|
if (probe_id[0] == '0' && (probe_id[1] == 'x' || probe_id[1] == 'X'))
|
||||||
|
{
|
||||||
|
// Raw encoded id (drv << 8 | probe).
|
||||||
|
id = (int)strtoul(probe_id, NULL, 16);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Sequential index from jtag_get_probes_list.
|
||||||
|
id = resolve_flat_probe_index(jc, (int)strtoul(probe_id, NULL, 10));
|
||||||
|
if (id < 0)
|
||||||
|
{
|
||||||
|
ctx->script_printf(ctx, MSG_ERROR,
|
||||||
|
"No probe at index %s. Run jtag_get_probes_list first.\n", probe_id);
|
||||||
|
return JTAG_CORE_BAD_PARAMETER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = jtagcore_select_and_open_probe(jc, id);
|
||||||
if (ret != JTAG_CORE_NO_ERROR)
|
if (ret != JTAG_CORE_NO_ERROR)
|
||||||
{
|
{
|
||||||
ctx->script_printf(ctx, MSG_ERROR, "Code %d !\n", ret);
|
ctx->script_printf(ctx, MSG_ERROR, "Code %d !\n", ret);
|
||||||
|
|||||||
Reference in New Issue
Block a user