From b542c103767836b846d278b51ff682f73fc4c618 Mon Sep 17 00:00:00 2001 From: Tomek CEDRO Date: Fri, 9 Sep 2011 22:18:56 +0000 Subject: transport/swd: Introduced swd_tcl.c, a TCL interface for SWD. Commands are registered at transport select. Available commands are 'newdap' currently pointing to jtag_newtap, 'loglevel' that can show/set/inherit loglevel for easier log analysis during development. --- src/transport/swd_tcl.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/transport/swd_tcl.c (limited to 'src/transport/swd_tcl.c') diff --git a/src/transport/swd_tcl.c b/src/transport/swd_tcl.c new file mode 100644 index 00000000..9fdc4d08 --- /dev/null +++ b/src/transport/swd_tcl.c @@ -0,0 +1,120 @@ +/* + * $Id$ + * + * TCL Interface for SWD Transport. + * + * Copyright (C) 2011 Tomasz Boleslaw CEDRO + * cederom@tlen.pl, http://www.tomek.cedro.info + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of the Tomasz Boleslaw CEDRO nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE.* + * + * Written by Tomasz Boleslaw CEDRO , 2010-2011; + * + */ + +/** \file swd_tcl.c TCL Interface for SWD Transport. + * This file contains TCL interface and functions to work with SWD transport. + */ + +#include + +//we need to use this until we get rid of global pointers +extern struct jtag_interface *jtag_interface; + +COMMAND_HANDLER(handle_swd_loglevel) +{ + int loglevel; + swd_ctx_t *swdctx=(swd_ctx_t *)jtag_interface->transport->ctx; + + switch (CMD_ARGC) { + case 0: + LOG_INFO("Current SWD LogLevel[%d..%d] is: %d (%s)", SWD_LOGLEVEL_MIN, SWD_LOGLEVEL_MAX, swdctx->config.loglevel, swd_log_level_string(swdctx->config.loglevel)); + break; + case 1: + // We want to allow inherit current OpenOCD's debuglevel. + if (strncasecmp(CMD_ARGV[0], "inherit", 7)==0) { + if((loglevel=swd_log_level_inherit(swdctx, debug_level))<0){ + LOG_ERROR("LogLevel inherit failed!"); + return ERROR_FAIL; + } else { + LOG_INFO("Using OpenOCD settings, SWD LogLevel[%d..%d] set to: %d (%s)", SWD_LOGLEVEL_MIN, SWD_LOGLEVEL_MAX, loglevel, swd_log_level_string(loglevel)); + return ERROR_OK; + } + } + // Or we want to set log level for SWD transport by hand. + loglevel=atoi(CMD_ARGV[0]); + if (loglevelSWD_LOGLEVEL_MAX) { + LOG_ERROR("Bad SWD LogLevel value!"); + return ERROR_FAIL; + } else LOG_INFO("Setting SWD LogLevel[%d..%d] to: %d (%s)", SWD_LOGLEVEL_MIN, SWD_LOGLEVEL_MAX, loglevel, swd_log_level_string(loglevel)); + if(swd_log_level_set(swdctx, loglevel)<0){ + return ERROR_FAIL; + } else return ERROR_OK; + } + LOG_INFO("Available values:"); + for (int i=0;i<=SWD_LOGLEVEL_MAX;i++) LOG_INFO(" %d (%s)", i, swd_log_level_string(i)); + return ERROR_OK; +} + +static const struct command_registration swd_subcommand_handlers[] = { + { + /* + * Set up SWD and JTAG targets identically, unless/until + * infrastructure improves ... meanwhile, ignore all + * JTAG-specific stuff like IR length for SWD. + * + * REVISIT can we verify "just one SWD DAP" here/early? + */ + .name = "newdap", + .jim_handler = jim_jtag_newtap, + .mode = COMMAND_CONFIG, + .help = "declare a new SWD DAP" + }, + { + .name = "loglevel", + .handler = handle_swd_loglevel, + .mode = COMMAND_ANY, + .help = "set/inherit/get loglevel for SWD transport.", + }, + + COMMAND_REGISTRATION_DONE +}; + +static const struct command_registration swd_command_handlers[] = { + { + .name = "swd", + .mode = COMMAND_ANY, + .help = "SWD command group", + .chain = swd_subcommand_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + +int swd_register_commands(struct command_context *cmd_ctx) +{ + return register_commands(cmd_ctx, NULL, swd_command_handlers); +} + +/** @} */ -- cgit v1.2.3