-/* 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.
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;
}
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.");
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;
}
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)
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";
}
}
- 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;
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;
}
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;
}
{
.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",