aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Borneo <borneo.antonio@gmail.com>2023-03-27 11:11:46 +0200
committerAntonio Borneo <borneo.antonio@gmail.com>2023-05-13 08:55:55 +0000
commit85b5c518062f4d77f73cb5f00620ccebd2d7847a (patch)
treeeb603677ed3dade3d55d0d21e0d7e62ecfa1df6a
parentb931286ab440f4677a9ac983a64b55055d20c438 (diff)
downloadriscv-openocd-85b5c518062f4d77f73cb5f00620ccebd2d7847a.zip
riscv-openocd-85b5c518062f4d77f73cb5f00620ccebd2d7847a.tar.gz
riscv-openocd-85b5c518062f4d77f73cb5f00620ccebd2d7847a.tar.bz2
target: rewrite command 'arp_reset' as COMMAND_HANDLER
While there, add the missing .usage field and move in target.c the enum nvp_assert. Change-Id: Ia4f2f962887b5a35faeaa4eae128fa2865569b24 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/7559 Tested-by: jenkins
-rw-r--r--src/target/target.c58
-rw-r--r--src/target/target.h5
2 files changed, 26 insertions, 37 deletions
diff --git a/src/target/target.c b/src/target/target.c
index f2e8d53..73fba0d 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -157,7 +157,12 @@ static LIST_HEAD(target_trace_callback_list);
static const int polling_interval = TARGET_DEFAULT_POLLING_INTERVAL;
static LIST_HEAD(empty_smp_targets);
-static const struct jim_nvp nvp_assert[] = {
+enum nvp_assert {
+ NVP_DEASSERT,
+ NVP_ASSERT,
+};
+
+static const struct nvp nvp_assert[] = {
{ .name = "assert", NVP_ASSERT },
{ .name = "deassert", NVP_DEASSERT },
{ .name = "T", NVP_ASSERT },
@@ -5770,40 +5775,30 @@ COMMAND_HANDLER(handle_target_poll)
return target->type->poll(target);
}
-static int jim_target_reset(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+COMMAND_HANDLER(handle_target_reset)
{
- struct jim_getopt_info goi;
- jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
+ if (CMD_ARGC != 2)
+ return ERROR_COMMAND_SYNTAX_ERROR;
- if (goi.argc != 2) {
- Jim_WrongNumArgs(interp, 0, argv,
- "([tT]|[fF]|assert|deassert) BOOL");
- return JIM_ERR;
+ const struct nvp *n = nvp_name2value(nvp_assert, CMD_ARGV[0]);
+ if (!n->name) {
+ nvp_unknown_command_print(CMD, nvp_assert, NULL, CMD_ARGV[0]);
+ return ERROR_COMMAND_ARGUMENT_INVALID;
}
- struct jim_nvp *n;
- int e = jim_getopt_nvp(&goi, nvp_assert, &n);
- if (e != JIM_OK) {
- jim_getopt_nvp_unknown(&goi, nvp_assert, 1);
- return e;
- }
/* the halt or not param */
- jim_wide a;
- e = jim_getopt_wide(&goi, &a);
- if (e != JIM_OK)
- return e;
+ int a;
+ COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], a);
- 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);
+ struct target *target = get_current_target(CMD_CTX);
+ if (!target->tap->enabled) {
+ command_print(CMD, "[TAP is disabled]");
+ return ERROR_FAIL;
+ }
if (!target->type->assert_reset || !target->type->deassert_reset) {
- Jim_SetResultFormatted(interp,
- "No target-specific reset for %s",
- target_name(target));
- return JIM_ERR;
+ command_print(CMD, "No target-specific reset for %s", target_name(target));
+ return ERROR_FAIL;
}
if (target->defer_examine)
@@ -5816,10 +5811,8 @@ static int jim_target_reset(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
/* do the assert */
if (n->value == NVP_ASSERT)
- e = target->type->assert_reset(target);
- else
- e = target->type->deassert_reset(target);
- return (e == ERROR_OK) ? JIM_OK : JIM_ERR;
+ return target->type->assert_reset(target);
+ return target->type->deassert_reset(target);
}
COMMAND_HANDLER(handle_target_halt)
@@ -6101,8 +6094,9 @@ static const struct command_registration target_instance_command_handlers[] = {
{
.name = "arp_reset",
.mode = COMMAND_EXEC,
- .jim_handler = jim_target_reset,
+ .handler = handle_target_reset,
.help = "used internally for reset processing",
+ .usage = "'assert'|'deassert' halt",
},
{
.name = "arp_halt",
diff --git a/src/target/target.h b/src/target/target.h
index ef9ba10..00bf43c 100644
--- a/src/target/target.h
+++ b/src/target/target.h
@@ -57,11 +57,6 @@ enum target_state {
TARGET_DEBUG_RUNNING = 4,
};
-enum nvp_assert {
- NVP_DEASSERT,
- NVP_ASSERT,
-};
-
enum target_reset_mode {
RESET_UNKNOWN = 0,
RESET_RUN = 1, /* reset and let target run */