diff options
author | Tomek CEDRO <cederom@tlen.pl> | 2011-09-09 22:18:56 +0000 |
---|---|---|
committer | Tomek CEDRO <cederom@tlen.pl> | 2011-09-09 22:18:56 +0000 |
commit | b542c103767836b846d278b51ff682f73fc4c618 (patch) | |
tree | 6dad2ef841449d98232056e14bedefabb3a11f84 /src | |
parent | 59994223e388f9e087eb8930f6b3055360451824 (diff) | |
download | openocd_libswd-b542c103767836b846d278b51ff682f73fc4c618.tar.gz openocd_libswd-b542c103767836b846d278b51ff682f73fc4c618.tar.bz2 openocd_libswd-b542c103767836b846d278b51ff682f73fc4c618.tar.xz openocd_libswd-b542c103767836b846d278b51ff682f73fc4c618.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/Makefile.am | 1 | ||||
-rw-r--r-- | src/transport/swd.h | 9 | ||||
-rw-r--r-- | src/transport/swd_core.c | 6 | ||||
-rw-r--r-- | src/transport/swd_tcl.c | 120 |
4 files changed, 136 insertions, 0 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index f011236b..fc0a055b 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -5,6 +5,7 @@ noinst_LTLIBRARIES = libtransport.la libtransport_la_SOURCES = \ transport.c \ swd_core.c \ + swd_tcl.c \ swd_libswd_drv_openocd.c noinst_HEADERS = \ diff --git a/src/transport/swd.h b/src/transport/swd.h index cd908169..437a8a5e 100644 --- a/src/transport/swd.h +++ b/src/transport/swd.h @@ -35,10 +35,17 @@ */ /** \file swd.h SWD Transport Header File for OpenOCD. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include <libswd.h> #include <transport/transport.h> +#include <target/arm.h> #include <target/arm_adi_v5.h> +#include <helper/log.h> +#include <interface/interface.h> +#include <jtag/interface.h> int oocd_swd_queue_idcode_read(struct adiv5_dap *dap, uint8_t *ack, uint32_t *data); int oocd_swd_queue_dp_read(struct adiv5_dap *dap, unsigned reg, uint32_t *data); @@ -53,3 +60,5 @@ int oocd_swd_transport_select(struct command_context *ctx); extern struct transport oocd_transport_swd; extern const struct dap_ops oocd_dap_ops_swd; +int swd_register_commands(struct command_context *cmd_ctx); + diff --git a/src/transport/swd_core.c b/src/transport/swd_core.c index c608bf21..da287e7a 100644 --- a/src/transport/swd_core.c +++ b/src/transport/swd_core.c @@ -180,6 +180,12 @@ int oocd_swd_transport_select(struct command_context *ctx){ LOG_ERROR("Unable to set log level: %s", swd_error_string(retval)); return ERROR_FAIL; } + + retval=swd_register_commands(ctx); + if (retval!=ERROR_OK) { + LOG_ERROR("Unable to register SWD commands!"); + return retval; + } LOG_DEBUG("SWD Transport selection complete..."); return ERROR_OK; } 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 <cederom@tlen.pl>, 2010-2011; + * + */ + +/** \file swd_tcl.c TCL Interface for SWD Transport. + * This file contains TCL interface and functions to work with SWD transport. + */ + +#include <transport/swd.h> + +//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 (loglevel<SWD_LOGLEVEL_MIN || loglevel>SWD_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); +} + +/** @} */ |