"transport select" returns Jim value

Make it scriptable, so code can be conditionalized based on
what transport is in use for the session.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
This commit is contained in:
David Brownell 2010-07-24 14:38:46 -04:00 committed by David Brownell
parent 51d9b56861
commit a463670c31
2 changed files with 31 additions and 42 deletions

View File

@ -2451,7 +2451,7 @@ version of OpenOCD.
Select which of the supported transports to use in this OpenOCD session. Select which of the supported transports to use in this OpenOCD session.
The transport must be supported by the debug adapter hardware and by the The transport must be supported by the debug adapter hardware and by the
version of OPenOCD you are using (including the adapter's driver). version of OPenOCD you are using (including the adapter's driver).
No arguments: print selected transport.. No arguments: returns name of session's selected transport.
@end deffn @end deffn
@subsection JTAG Transport @subsection JTAG Transport

View File

@ -46,6 +46,9 @@
#include "transport.h" #include "transport.h"
extern struct command_context *global_cmd_ctx;
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* /*
@ -272,39 +275,26 @@ COMMAND_HANDLER(handle_transport_list)
/** /**
* Implements the Tcl "transport select" command, choosing the * Implements the Tcl "transport select" command, choosing the
* transport to be used in this debug session from among the * transport to be used in this debug session from among the
* set supported by the debug adapter being used. * set supported by the debug adapter being used. Return value
* is scriptable (allowing "if swd then..." etc).
*/ */
COMMAND_HANDLER(handle_transport_select) static int jim_transport_select(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{ {
int retval = ERROR_OK;; switch (argc) {
case 1: /* return/display */
switch (CMD_ARGC) { if (!session) {
case 0: /* "select" */ LOG_ERROR("session's transport is not selected.");
if (session) { return JIM_ERR;
goto show;
}
LOG_ERROR("session's transport is not selected.");
return ERROR_FAIL;
case 1: /* "select FOO" */
if ((session!= NULL) && strcmp(session->name, CMD_ARGV[0]) == 0) {
/* NOP */
LOG_DEBUG("transport '%s' is already selected",
CMD_ARGV[0]);
return ERROR_OK;
} else { } else {
/* we can't change this session's transport after-the-fact */ Jim_SetResultString(interp, session->name, -1);
if (session) { return JIM_OK;
LOG_ERROR("session's transport is already selected.");
return ERROR_FAIL;
}
} }
break; break;
case 2: /* assign */
default: /* select FOO BAR */ if (session) {
/* we only select *one* transport per session */ /* can't change session's transport after-the-fact */
LOG_ERROR("may only select one transport!"); LOG_ERROR("session's transport is already selected.");
return ERROR_COMMAND_SYNTAX_ERROR; return JIM_ERR;
} }
/* Is this transport supported by our debug adapter? /* Is this transport supported by our debug adapter?
@ -315,24 +305,23 @@ COMMAND_HANDLER(handle_transport_select)
*/ */
if (!allowed_transports) { if (!allowed_transports) {
LOG_ERROR("Debug adapter doesn't support any transports?"); LOG_ERROR("Debug adapter doesn't support any transports?");
return ERROR_FAIL; return JIM_ERR;
} }
for (unsigned i = 0; allowed_transports[i]; i++) { for (unsigned i = 0; allowed_transports[i]; i++) {
if (strcmp(allowed_transports[i], CMD_ARGV[0]) == 0) if (strcmp(allowed_transports[i], argv[0]->bytes) == 0)
return transport_select(CMD_CTX, CMD_ARGV[0]); return transport_select(global_cmd_ctx, argv[0]->bytes);
} }
LOG_ERROR("Debug adapter doesn't support '%s' " LOG_ERROR("Debug adapter doesn't support '%s' "
"transport?", CMD_ARGV[0]); "transport", argv[0]->bytes);
return ERROR_FAIL; return JIM_ERR;
break;
default:
show: Jim_WrongNumArgs(interp, 1, argv, "[too many parameters]");
/* report the current transport selection */ return JIM_ERR;
command_print(CMD_CTX, "%s", session->name); }
return retval;
} }
static const struct command_registration transport_commands[] = { static const struct command_registration transport_commands[] = {
@ -354,7 +343,7 @@ static const struct command_registration transport_commands[] = {
}, },
{ {
.name = "select", .name = "select",
.handler = handle_transport_select, .jim_handler = jim_transport_select,
.mode = COMMAND_ANY, .mode = COMMAND_ANY,
.help = "Select this session's transport", .help = "Select this session's transport",
.usage = "[transport_name]", .usage = "[transport_name]",