jtag: linuxgpiod: drop extra parenthesis
[openocd.git] / src / jtag / adapter.c
index a0432b69265c6057d71a2b1314294c641c029c80..bbf1cb3d2e2e8c4a8f04c3fd53697058579fb048 100644 (file)
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) 2005 by Dominic Rath <Dominic.Rath@gmx.de>
  * Copyright (C) 2007-2010 Ã˜yvind Harboe <oyvind.harboe@zylin.com>
 #include "interfaces.h"
 #include <transport/transport.h>
 
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-
 /**
  * @file
  * Holds support for configuring debug adapters from TCl scripts.
@@ -98,8 +94,9 @@ static void adapter_driver_gpios_init(void)
                return;
 
        for (int i = 0; i < ADAPTER_GPIO_IDX_NUM; ++i) {
-               adapter_config.gpios[i].gpio_num = -1;
-               adapter_config.gpios[i].chip_num = -1;
+               /* Use ADAPTER_GPIO_NOT_SET as the sentinel 'unset' value. */
+               adapter_config.gpios[i].gpio_num = ADAPTER_GPIO_NOT_SET;
+               adapter_config.gpios[i].chip_num = ADAPTER_GPIO_NOT_SET;
                if (gpio_map[i].direction == ADAPTER_GPIO_DIRECTION_INPUT)
                        adapter_config.gpios[i].init_state = ADAPTER_GPIO_INIT_STATE_INPUT;
        }
@@ -136,9 +133,11 @@ int adapter_init(struct command_context *cmd_ctx)
 
        int retval;
 
-       if (adapter_config.clock_mode == CLOCK_MODE_UNSELECTED) {
+       /* If the adapter supports configurable speed but the speed is not configured,
+        * provide a hint to the user. */
+       if (adapter_driver->speed && adapter_config.clock_mode == CLOCK_MODE_UNSELECTED) {
                LOG_WARNING("An adapter speed is not selected in the init scripts."
-                       " OpenOCD will try to run the adapter at the low speed (%d kHz)",
+                       " OpenOCD will try to run the adapter at very low speed (%d kHz).",
                        DEFAULT_CLOCK_SPEED_KHZ);
                LOG_WARNING("To remove this warnings and achieve reasonable communication speed with the target,"
                    " set \"adapter speed\" or \"jtag_rclk\" in the init scripts.");
@@ -153,7 +152,7 @@ int adapter_init(struct command_context *cmd_ctx)
        adapter_config.adapter_initialized = true;
 
        if (!adapter_driver->speed) {
-               LOG_INFO("This adapter doesn't support configurable speed");
+               LOG_INFO("Note: The adapter \"%s\" doesn't support configurable speed", adapter_driver->name);
                return ERROR_OK;
        }
 
@@ -376,21 +375,18 @@ done:
        return equal;
 }
 
-static int jim_adapter_name(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
+COMMAND_HANDLER(handle_adapter_name)
 {
-       struct jim_getopt_info goi;
-       jim_getopt_setup(&goi, interp, argc-1, argv + 1);
-
        /* return the name of the interface */
        /* TCL code might need to know the exact type... */
        /* FUTURE: we allow this as a means to "set" the interface. */
-       if (goi.argc != 0) {
-               Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)");
-               return JIM_ERR;
-       }
-       const char *name = adapter_driver ? adapter_driver->name : NULL;
-       Jim_SetResultString(goi.interp, name ? name : "undefined", -1);
-       return JIM_OK;
+
+       if (CMD_ARGC != 0)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       command_print(CMD, "%s", adapter_driver ? adapter_driver->name : "undefined");
+
+       return ERROR_OK;
 }
 
 COMMAND_HANDLER(adapter_transports_command)
@@ -853,6 +849,11 @@ static COMMAND_HELPER(helper_adapter_gpio_print_config, enum adapter_gpio_config
        const char *pull = "";
        const char *init_state = "";
 
+       if (gpio_config->gpio_num == ADAPTER_GPIO_NOT_SET) {
+               command_print(CMD, "adapter gpio %s: not configured", gpio_map[gpio_idx].name);
+               return ERROR_OK;
+       }
+
        switch (gpio_map[gpio_idx].direction) {
        case ADAPTER_GPIO_DIRECTION_INPUT:
                dir = "input";
@@ -905,8 +906,8 @@ static COMMAND_HELPER(helper_adapter_gpio_print_config, enum adapter_gpio_config
                }
        }
 
-       command_print(CMD, "adapter gpio %s (%s): num %d, chip %d, active-%s%s%s%s",
-               gpio_map[gpio_idx].name, dir, gpio_config->gpio_num, gpio_config->chip_num, active_state,
+       command_print(CMD, "adapter gpio %s (%s): num %u, chip %d, active-%s%s%s%s",
+               gpio_map[gpio_idx].name, dir, gpio_config->gpio_num, (int)gpio_config->chip_num, active_state,
                drive, pull, init_state);
 
        return ERROR_OK;
@@ -947,9 +948,7 @@ COMMAND_HANDLER(adapter_gpio_config_handler)
                LOG_DEBUG("Processing %s", CMD_ARGV[i]);
 
                if (isdigit(*CMD_ARGV[i])) {
-                       int gpio_num; /* Use a meaningful output parameter for more helpful error messages */
-                       COMMAND_PARSE_NUMBER(int, CMD_ARGV[i], gpio_num);
-                       gpio_config->gpio_num = gpio_num;
+                       COMMAND_PARSE_NUMBER(uint, CMD_ARGV[i], gpio_config->gpio_num);
                        ++i;
                        continue;
                }
@@ -960,9 +959,7 @@ COMMAND_HANDLER(adapter_gpio_config_handler)
                                return ERROR_FAIL;
                        }
                        LOG_DEBUG("-chip arg is %s", CMD_ARGV[i + 1]);
-                       int chip_num; /* Use a meaningful output parameter for more helpful error messages */
-                       COMMAND_PARSE_NUMBER(int, CMD_ARGV[i + 1], chip_num);
-                       gpio_config->chip_num = chip_num;
+                       COMMAND_PARSE_NUMBER(uint, CMD_ARGV[i + 1], gpio_config->chip_num);
                        i += 2;
                        continue;
                }
@@ -1125,9 +1122,10 @@ static const struct command_registration adapter_command_handlers[] = {
        {
                .name = "name",
                .mode = COMMAND_ANY,
-               .jim_handler = jim_adapter_name,
+               .handler = handle_adapter_name,
                .help = "Returns the name of the currently "
                        "selected adapter (driver)",
+               .usage = "",
        },
        {
                .name = "srst",

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)