[prev in list] [next in list] [prev in thread] [next in thread]
List: openocd-development
Subject: [PATCH]: 58df793c46 target: rewrite command 'arp_waitstate' as COMMAND_HANDLER
From: gerrit () openocd ! org
Date: 2023-03-27 12:56:10
Message-ID: 20230327125610.3F14F2CF () openocd ! org
[Download RAW message or body]
This is an automated email from Gerrit.
"Antonio Borneo <borneo.antonio@gmail.com>" just uploaded a new patch set to Gerrit, \
which you can find at https://review.openocd.org/c/openocd/+/7561
-- gerrit
commit 58df793c463a034d10dcb3589dbd82b973c446dc
Author: Antonio Borneo <borneo.antonio@gmail.com>
Date: Mon Mar 27 12:03:13 2023 +0200
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>
diff --git a/src/target/target.c b/src/target/target.c
index c7e5bbce82..d6b579a3a0 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -248,7 +248,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 },
@@ -302,7 +302,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*)";
@@ -3284,7 +3284,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)
@@ -3292,7 +3292,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;
}
}
@@ -5671,12 +5671,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;
@@ -5818,45 +5812,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;
+ int a;
+ COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], a);
+
+ struct target *target = get_current_target(CMD_CTX);
+ if (!target->tap->enabled) {
+ command_print(CMD, "[TAP is disabled]");
+ return ERROR_FAIL;
}
- 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);
- 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",
+ 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'
@@ -6097,8 +6081,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",
--
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic