X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fjtag%2Fadapter.c;h=af75917a32d795471aed41c4887e7202fc56055f;hp=a0432b69265c6057d71a2b1314294c641c029c80;hb=HEAD;hpb=8f725fea2502d538f69487fd21aa979611cea4f6 diff --git a/src/jtag/adapter.c b/src/jtag/adapter.c index a0432b6926..bbf1cb3d2e 100644 --- a/src/jtag/adapter.c +++ b/src/jtag/adapter.c @@ -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 * Copyright (C) 2007-2010 Øyvind Harboe @@ -18,10 +18,6 @@ #include "interfaces.h" #include -#ifdef HAVE_STRINGS_H -#include -#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",