jtag: rewrite jim_jtag_tap_enabler() as COMMAND_HANDLER
[openocd.git] / src / jtag / tcl.c
index 700772ea4b17cdae96ccf64bb357b8c712c9597e..85a66aaf62971f4cf8373f067a5eaebd0565a153 100644 (file)
@@ -604,7 +604,7 @@ COMMAND_HANDLER(handle_jtag_arp_init_reset)
 static bool jtag_tap_enable(struct jtag_tap *t)
 {
        if (t->enabled)
-               return false;
+               return true;
        jtag_tap_handle_event(t, JTAG_TAP_EVENT_ENABLE);
        if (!t->enabled)
                return false;
@@ -619,7 +619,7 @@ static bool jtag_tap_enable(struct jtag_tap *t)
 static bool jtag_tap_disable(struct jtag_tap *t)
 {
        if (!t->enabled)
-               return false;
+               return true;
        jtag_tap_handle_event(t, JTAG_TAP_EVENT_DISABLE);
        if (t->enabled)
                return false;
@@ -632,42 +632,36 @@ static bool jtag_tap_disable(struct jtag_tap *t)
        return true;
 }
 
-int jim_jtag_tap_enabler(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+__COMMAND_HANDLER(handle_jtag_tap_enabler)
 {
-       struct command *c = jim_to_command(interp);
-       const char *cmd_name = c->name;
-       struct jim_getopt_info goi;
-       jim_getopt_setup(&goi, interp, argc-1, argv + 1);
-       if (goi.argc != 1) {
-               Jim_SetResultFormatted(goi.interp, "usage: %s <name>", cmd_name);
-               return JIM_ERR;
-       }
-
-       struct jtag_tap *t;
+       if (CMD_ARGC != 1)
+               return ERROR_COMMAND_SYNTAX_ERROR;
 
-       t = jtag_tap_by_jim_obj(goi.interp, goi.argv[0]);
-       if (!t)
-               return JIM_ERR;
+       struct jtag_tap *t = jtag_tap_by_string(CMD_ARGV[0]);
+       if (!t) {
+               command_print(CMD, "Tap '%s' could not be found", CMD_ARGV[0]);
+               return ERROR_COMMAND_ARGUMENT_INVALID;
+       }
 
-       if (strcasecmp(cmd_name, "tapisenabled") == 0) {
+       if (strcmp(CMD_NAME, "tapisenabled") == 0) {
                /* do nothing, just return the value */
-       } else if (strcasecmp(cmd_name, "tapenable") == 0) {
+       } else if (strcmp(CMD_NAME, "tapenable") == 0) {
                if (!jtag_tap_enable(t)) {
-                       LOG_WARNING("failed to enable tap %s", t->dotted_name);
-                       return JIM_ERR;
+                       command_print(CMD, "failed to enable tap %s", t->dotted_name);
+                       return ERROR_FAIL;
                }
-       } else if (strcasecmp(cmd_name, "tapdisable") == 0) {
+       } else if (strcmp(CMD_NAME, "tapdisable") == 0) {
                if (!jtag_tap_disable(t)) {
-                       LOG_WARNING("failed to disable tap %s", t->dotted_name);
-                       return JIM_ERR;
+                       command_print(CMD, "failed to disable tap %s", t->dotted_name);
+                       return ERROR_FAIL;
                }
        } else {
-               LOG_ERROR("command '%s' unknown", cmd_name);
-               return JIM_ERR;
+               command_print(CMD, "command '%s' unknown", CMD_NAME);
+               return ERROR_FAIL;
        }
-       bool e = t->enabled;
-       Jim_SetResult(goi.interp, Jim_NewIntObj(goi.interp, e));
-       return JIM_OK;
+
+       command_print(CMD, "%d", t->enabled ? 1 : 0);
+       return ERROR_OK;
 }
 
 int jim_jtag_configure(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -763,7 +757,7 @@ static const struct command_registration jtag_subcommand_handlers[] = {
        {
                .name = "tapisenabled",
                .mode = COMMAND_EXEC,
-               .jim_handler = jim_jtag_tap_enabler,
+               .handler = handle_jtag_tap_enabler,
                .help = "Returns a Tcl boolean (0/1) indicating whether "
                        "the TAP is enabled (1) or not (0).",
                .usage = "tap_name",
@@ -771,7 +765,7 @@ static const struct command_registration jtag_subcommand_handlers[] = {
        {
                .name = "tapenable",
                .mode = COMMAND_EXEC,
-               .jim_handler = jim_jtag_tap_enabler,
+               .handler = handle_jtag_tap_enabler,
                .help = "Try to enable the specified TAP using the "
                        "'tap-enable' TAP event.",
                .usage = "tap_name",
@@ -779,7 +773,7 @@ static const struct command_registration jtag_subcommand_handlers[] = {
        {
                .name = "tapdisable",
                .mode = COMMAND_EXEC,
-               .jim_handler = jim_jtag_tap_enabler,
+               .handler = handle_jtag_tap_enabler,
                .help = "Try to disable the specified TAP using the "
                        "'tap-disable' TAP event.",
                .usage = "tap_name",

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)