jtag: rewrite command 'pathmove' as COMMAND_HANDLER

Change-Id: I1f8c6722021f392b1f065484b63a19964db69ad5
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7556
Tested-by: jenkins
This commit is contained in:
Antonio Borneo 2023-01-02 22:32:53 +01:00
parent 4bf994fc9c
commit 7319eb3a25
1 changed files with 20 additions and 23 deletions

View File

@ -164,40 +164,37 @@ fail:
return retval; return retval;
} }
static int jim_command_pathmove(Jim_Interp *interp, int argc, Jim_Obj * const *args) COMMAND_HANDLER(handle_jtag_command_pathmove)
{ {
tap_state_t states[8]; tap_state_t states[8];
if ((argc < 2) || ((size_t)argc > (ARRAY_SIZE(states) + 1))) { if (CMD_ARGC < 1 || CMD_ARGC > ARRAY_SIZE(states))
Jim_WrongNumArgs(interp, 1, args, "wrong arguments"); return ERROR_COMMAND_SYNTAX_ERROR;
return JIM_ERR;
}
int i; for (unsigned int i = 0; i < CMD_ARGC; i++) {
for (i = 0; i < argc-1; i++) { states[i] = tap_state_by_name(CMD_ARGV[i]);
const char *cp;
cp = Jim_GetString(args[i + 1], NULL);
states[i] = tap_state_by_name(cp);
if (states[i] < 0) { if (states[i] < 0) {
/* update the error message */ command_print(CMD, "endstate: %s invalid", CMD_ARGV[i]);
Jim_SetResultFormatted(interp, "endstate: %s invalid", cp); return ERROR_COMMAND_ARGUMENT_INVALID;
return JIM_ERR;
} }
} }
if ((jtag_add_statemove(states[0]) != ERROR_OK) || (jtag_execute_queue() != ERROR_OK)) { int retval = jtag_add_statemove(states[0]);
Jim_SetResultString(interp, "pathmove: jtag execute failed", -1); if (retval == ERROR_OK)
return JIM_ERR; retval = jtag_execute_queue();
if (retval != ERROR_OK) {
command_print(CMD, "pathmove: jtag execute failed");
return retval;
} }
jtag_add_pathmove(argc - 2, states + 1); jtag_add_pathmove(CMD_ARGC - 1, states + 1);
retval = jtag_execute_queue();
if (jtag_execute_queue() != ERROR_OK) { if (retval != ERROR_OK) {
Jim_SetResultString(interp, "pathmove: failed", -1); command_print(CMD, "pathmove: failed");
return JIM_ERR; return retval;
} }
return JIM_OK; return ERROR_OK;
} }
COMMAND_HANDLER(handle_jtag_flush_count) COMMAND_HANDLER(handle_jtag_flush_count)
@ -241,7 +238,7 @@ static const struct command_registration jtag_command_handlers_to_move[] = {
{ {
.name = "pathmove", .name = "pathmove",
.mode = COMMAND_EXEC, .mode = COMMAND_EXEC,
.jim_handler = jim_command_pathmove, .handler = handle_jtag_command_pathmove,
.usage = "start_state state1 [state2 [state3 ...]]", .usage = "start_state state1 [state2 [state3 ...]]",
.help = "Move JTAG state machine from current state " .help = "Move JTAG state machine from current state "
"(start_state) to state1, then state2, state3, etc.", "(start_state) to state1, then state2, state3, etc.",