target: rewrite command 'arp_waitstate' as COMMAND_HANDLER
While there, add the missing .usage field and remove the now unused function jim_target_tap_disabled(). Change-Id: I79afcc5097643fc264354c6c3957786a55f40498 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/7561 Tested-by: jenkins
This commit is contained in:
parent
22ababc12e
commit
fe6befbd80
|
@ -210,7 +210,7 @@ static const struct jim_nvp nvp_target_event[] = {
|
|||
{ .name = NULL, .value = -1 }
|
||||
};
|
||||
|
||||
static const struct jim_nvp nvp_target_state[] = {
|
||||
static const struct nvp nvp_target_state[] = {
|
||||
{ .name = "unknown", .value = TARGET_UNKNOWN },
|
||||
{ .name = "running", .value = TARGET_RUNNING },
|
||||
{ .name = "halted", .value = TARGET_HALTED },
|
||||
|
@ -264,7 +264,7 @@ const char *debug_reason_name(struct target *t)
|
|||
const char *target_state_name(struct target *t)
|
||||
{
|
||||
const char *cp;
|
||||
cp = jim_nvp_value2name_simple(nvp_target_state, t->state)->name;
|
||||
cp = nvp_value2name(nvp_target_state, t->state)->name;
|
||||
if (!cp) {
|
||||
LOG_ERROR("Invalid target state: %d", (int)(t->state));
|
||||
cp = "(*BUG*unknown*BUG*)";
|
||||
|
@ -3246,7 +3246,7 @@ int target_wait_state(struct target *target, enum target_state state, int ms)
|
|||
once = false;
|
||||
then = timeval_ms();
|
||||
LOG_DEBUG("waiting for target %s...",
|
||||
jim_nvp_value2name_simple(nvp_target_state, state)->name);
|
||||
nvp_value2name(nvp_target_state, state)->name);
|
||||
}
|
||||
|
||||
if (cur-then > 500)
|
||||
|
@ -3254,7 +3254,7 @@ int target_wait_state(struct target *target, enum target_state state, int ms)
|
|||
|
||||
if ((cur-then) > ms) {
|
||||
LOG_ERROR("timed out while waiting for target %s",
|
||||
jim_nvp_value2name_simple(nvp_target_state, state)->name);
|
||||
nvp_value2name(nvp_target_state, state)->name);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
}
|
||||
|
@ -5633,12 +5633,6 @@ static int jim_target_array2mem(Jim_Interp *interp,
|
|||
return target_array2mem(interp, target, argc - 1, argv + 1);
|
||||
}
|
||||
|
||||
static int jim_target_tap_disabled(Jim_Interp *interp)
|
||||
{
|
||||
Jim_SetResultFormatted(interp, "[TAP is disabled]");
|
||||
return JIM_ERR;
|
||||
}
|
||||
|
||||
COMMAND_HANDLER(handle_target_examine)
|
||||
{
|
||||
bool allow_defer = false;
|
||||
|
@ -5780,45 +5774,35 @@ COMMAND_HANDLER(handle_target_halt)
|
|||
return target->type->halt(target);
|
||||
}
|
||||
|
||||
static int jim_target_wait_state(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
||||
COMMAND_HANDLER(handle_target_wait_state)
|
||||
{
|
||||
struct jim_getopt_info goi;
|
||||
jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
|
||||
if (CMD_ARGC != 2)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
/* params: <name> statename timeoutmsecs */
|
||||
if (goi.argc != 2) {
|
||||
const char *cmd_name = Jim_GetString(argv[0], NULL);
|
||||
Jim_SetResultFormatted(goi.interp,
|
||||
"%s <state_name> <timeout_in_msec>", cmd_name);
|
||||
return JIM_ERR;
|
||||
const struct nvp *n = nvp_name2value(nvp_target_state, CMD_ARGV[0]);
|
||||
if (!n->name) {
|
||||
nvp_unknown_command_print(CMD, nvp_target_state, NULL, CMD_ARGV[0]);
|
||||
return ERROR_COMMAND_ARGUMENT_INVALID;
|
||||
}
|
||||
|
||||
struct jim_nvp *n;
|
||||
int e = jim_getopt_nvp(&goi, nvp_target_state, &n);
|
||||
if (e != JIM_OK) {
|
||||
jim_getopt_nvp_unknown(&goi, nvp_target_state, 1);
|
||||
return e;
|
||||
}
|
||||
jim_wide a;
|
||||
e = jim_getopt_wide(&goi, &a);
|
||||
if (e != JIM_OK)
|
||||
return e;
|
||||
struct command_context *cmd_ctx = current_command_context(interp);
|
||||
assert(cmd_ctx);
|
||||
struct target *target = get_current_target(cmd_ctx);
|
||||
if (!target->tap->enabled)
|
||||
return jim_target_tap_disabled(interp);
|
||||
int a;
|
||||
COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], a);
|
||||
|
||||
e = target_wait_state(target, n->value, a);
|
||||
if (e != ERROR_OK) {
|
||||
Jim_Obj *obj = Jim_NewIntObj(interp, e);
|
||||
Jim_SetResultFormatted(goi.interp,
|
||||
"target: %s wait %s fails (%#s) %s",
|
||||
struct target *target = get_current_target(CMD_CTX);
|
||||
if (!target->tap->enabled) {
|
||||
command_print(CMD, "[TAP is disabled]");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
int retval = target_wait_state(target, n->value, a);
|
||||
if (retval != ERROR_OK) {
|
||||
command_print(CMD,
|
||||
"target: %s wait %s fails (%d) %s",
|
||||
target_name(target), n->name,
|
||||
obj, target_strerror_safe(e));
|
||||
return JIM_ERR;
|
||||
retval, target_strerror_safe(retval));
|
||||
return retval;
|
||||
}
|
||||
return JIM_OK;
|
||||
return ERROR_OK;
|
||||
}
|
||||
/* List for human, Events defined for this target.
|
||||
* scripts/programs should use 'name cget -event NAME'
|
||||
|
@ -6059,8 +6043,9 @@ static const struct command_registration target_instance_command_handlers[] = {
|
|||
{
|
||||
.name = "arp_waitstate",
|
||||
.mode = COMMAND_EXEC,
|
||||
.jim_handler = jim_target_wait_state,
|
||||
.handler = handle_target_wait_state,
|
||||
.help = "used internally for reset processing",
|
||||
.usage = "statename timeoutmsecs",
|
||||
},
|
||||
{
|
||||
.name = "invoke-event",
|
||||
|
|
Loading…
Reference in New Issue