target: rewrite command 'arp_reset' as COMMAND_HANDLER 59/7559/2
authorAntonio Borneo <borneo.antonio@gmail.com>
Mon, 27 Mar 2023 09:11:46 +0000 (11:11 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 13 May 2023 08:55:55 +0000 (08:55 +0000)
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
src/target/target.c
src/target/target.h

index f2e8d531a8f797068ab787722d0a22ee4dc66a19..73fba0da7744929152d606ae9e6c330f2712b1a5 100644 (file)
@@ -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",
index ef9ba1062bace2ab478cc01a62af3902c0408dad..00bf43c58bdbe19338f5f7a0e3f12ed2ba2f95d3 100644 (file)
@@ -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 */

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)