aboutsummaryrefslogtreecommitdiff
path: root/src/jtag/stlink
diff options
context:
space:
mode:
Diffstat (limited to 'src/jtag/stlink')
-rw-r--r--src/jtag/stlink/Makefile.am22
-rw-r--r--src/jtag/stlink/stlink_interface.c225
-rw-r--r--src/jtag/stlink/stlink_interface.h53
-rw-r--r--src/jtag/stlink/stlink_layout.c85
-rw-r--r--src/jtag/stlink/stlink_layout.h81
-rw-r--r--src/jtag/stlink/stlink_tcl.c136
-rw-r--r--src/jtag/stlink/stlink_tcl.h26
-rw-r--r--src/jtag/stlink/stlink_transport.c180
-rw-r--r--src/jtag/stlink/stlink_transport.h23
9 files changed, 831 insertions, 0 deletions
diff --git a/src/jtag/stlink/Makefile.am b/src/jtag/stlink/Makefile.am
new file mode 100644
index 00000000..ac5b3aff
--- /dev/null
+++ b/src/jtag/stlink/Makefile.am
@@ -0,0 +1,22 @@
+include $(top_srcdir)/common.mk
+
+noinst_LTLIBRARIES = libocdstlink.la
+
+libocdstlink_la_SOURCES = \
+ $(STLINKFILES)
+
+nobase_dist_pkglib_DATA =
+
+STLINKFILES =
+
+if STLINK
+STLINKFILES += stlink_transport.c
+STLINKFILES += stlink_tcl.c
+STLINKFILES += stlink_interface.c
+STLINKFILES += stlink_layout.c
+endif
+
+noinst_HEADERS = \
+ stlink_tcl.h
+
+MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
diff --git a/src/jtag/stlink/stlink_interface.c b/src/jtag/stlink/stlink_interface.c
new file mode 100644
index 00000000..a2ac99f7
--- /dev/null
+++ b/src/jtag/stlink/stlink_interface.c
@@ -0,0 +1,225 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Mathias Kuester *
+ * Mathias Kuester <kesmtp@freenet.de> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* project specific includes */
+#include <jtag/interface.h>
+#include <transport/transport.h>
+#include <helper/time_support.h>
+
+#include <jtag/stlink/stlink_tcl.h>
+#include <jtag/stlink/stlink_layout.h>
+#include <jtag/stlink/stlink_interface.h>
+
+#include <target/target.h>
+
+static struct stlink_interface_s stlink_if = { {0, 0, 0, 0}, 0, 0 };
+
+int stlink_interface_open(void)
+{
+ LOG_DEBUG("stlink_interface_open");
+
+ return stlink_if.layout->open(&stlink_if);
+}
+
+int stlink_interface_init_target(struct target *t)
+{
+ int res;
+
+ /* this is the interface for the current target and we
+ * can setup the private pointer in the tap structure
+ * if the interface match the tap idcode
+ */
+ res = stlink_if.layout->api->idcode(stlink_if.fd, &t->tap->idcode);
+
+ if (res != ERROR_OK)
+ return res;
+
+ unsigned ii, limit = t->tap->expected_ids_cnt;
+ int found = 0;
+
+ for (ii = 0; ii < limit; ii++) {
+ uint32_t expected = t->tap->expected_ids[ii];
+
+ if (t->tap->idcode == expected) {
+ found = 1;
+ break;
+ }
+ }
+
+ if (found == 0) {
+ LOG_ERROR
+ ("stlink_interface_init_target: target not found: idcode: %x ",
+ t->tap->idcode);
+ return ERROR_FAIL;
+ }
+
+ t->tap->priv = &stlink_if;
+ t->tap->hasidcode = 1;
+
+ return ERROR_OK;
+}
+
+static int stlink_interface_init(void)
+{
+ LOG_DEBUG("stlink_interface_init");
+
+ /* here we can initialize the layout */
+ return stlink_layout_init(&stlink_if);
+}
+
+static int stlink_interface_quit(void)
+{
+ LOG_DEBUG("stlink_interface_quit");
+
+ return ERROR_OK;
+}
+
+static int stlink_interface_speed(int speed)
+{
+ LOG_DEBUG("stlink_interface_speed: ignore speed %d", speed);
+
+ return ERROR_OK;
+}
+
+static int stlink_interface_execute_queue(void)
+{
+ LOG_DEBUG("stlink_interface_execute_queue: ignored");
+
+ return ERROR_OK;
+}
+
+COMMAND_HANDLER(stlink_interface_handle_device_desc_command)
+{
+ LOG_DEBUG("stlink_interface_handle_device_desc_command");
+
+ if (CMD_ARGC == 1) {
+ stlink_if.param.device_desc = strdup(CMD_ARGV[0]);
+ } else {
+ LOG_ERROR
+ ("expected exactly one argument to stlink_device_desc <description>");
+ }
+
+ return ERROR_OK;
+}
+
+COMMAND_HANDLER(stlink_interface_handle_serial_command)
+{
+ LOG_DEBUG("stlink_interface_handle_serial_command");
+
+ if (CMD_ARGC == 1) {
+ stlink_if.param.serial = strdup(CMD_ARGV[0]);
+ } else {
+ LOG_ERROR
+ ("expected exactly one argument to stlink_serial <serial-number>");
+ }
+
+ return ERROR_OK;
+}
+
+COMMAND_HANDLER(stlink_interface_handle_layout_command)
+{
+ LOG_DEBUG("stlink_interface_handle_layout_command");
+
+ if (CMD_ARGC != 1) {
+ LOG_ERROR("Need exactly one argument to stlink_layout");
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ }
+
+ if (stlink_if.layout) {
+ LOG_ERROR("already specified stlink_layout %s",
+ stlink_if.layout->name);
+ return (strcmp(stlink_if.layout->name, CMD_ARGV[0]) != 0)
+ ? ERROR_FAIL : ERROR_OK;
+ }
+
+ for (const struct stlink_layout *l = stlink_layout_get_list(); l->name;
+ l++) {
+ if (strcmp(l->name, CMD_ARGV[0]) == 0) {
+ stlink_if.layout = l;
+ return ERROR_OK;
+ }
+ }
+
+ LOG_ERROR("No STLINK layout '%s' found", CMD_ARGV[0]);
+ return ERROR_FAIL;
+}
+
+COMMAND_HANDLER(stlink_interface_handle_vid_pid_command)
+{
+ LOG_DEBUG("stlink_interface_handle_vid_pid_command");
+
+ if (CMD_ARGC != 2) {
+ LOG_WARNING
+ ("ignoring extra IDs in stlink_vid_pid (maximum is 1 pair)");
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ }
+
+ COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], stlink_if.param.vid);
+ COMMAND_PARSE_NUMBER(u16, CMD_ARGV[1], stlink_if.param.pid);
+
+ return ERROR_OK;
+}
+
+static const struct command_registration stlink_interface_command_handlers[] = {
+ {
+ .name = "stlink_device_desc",
+ .handler = &stlink_interface_handle_device_desc_command,
+ .mode = COMMAND_CONFIG,
+ .help = "set the stlink device description of the STLINK device",
+ .usage = "description_string",
+ },
+ {
+ .name = "stlink_serial",
+ .handler = &stlink_interface_handle_serial_command,
+ .mode = COMMAND_CONFIG,
+ .help = "set the serial number of the STLINK device",
+ .usage = "serial_string",
+ },
+ {
+ .name = "stlink_layout",
+ .handler = &stlink_interface_handle_layout_command,
+ .mode = COMMAND_CONFIG,
+ .help = "set the layout of the STLINK to usb or sg",
+ .usage = "layout_name",
+ },
+ {
+ .name = "stlink_vid_pid",
+ .handler = &stlink_interface_handle_vid_pid_command,
+ .mode = COMMAND_CONFIG,
+ .help = "the vendor and product ID of the STLINK device",
+ .usage = "(vid pid)* ",
+ },
+ COMMAND_REGISTRATION_DONE
+};
+
+struct jtag_interface stlink_interface = {
+ .name = "stlink",
+ .supported = 0,
+ .commands = stlink_interface_command_handlers,
+ .transports = stlink_transports,
+
+ .init = stlink_interface_init,
+ .quit = stlink_interface_quit,
+ .speed = stlink_interface_speed,
+ .execute_queue = stlink_interface_execute_queue,
+};
diff --git a/src/jtag/stlink/stlink_interface.h b/src/jtag/stlink/stlink_interface.h
new file mode 100644
index 00000000..9b3f791e
--- /dev/null
+++ b/src/jtag/stlink/stlink_interface.h
@@ -0,0 +1,53 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Mathias Kuester *
+ * Mathias Kuester <kesmtp@freenet.de> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef _STLINK_INTERFACE_
+#define _STLINK_INTERFACE_
+
+/** */
+struct target;
+/** */
+extern const char *stlink_transports[];
+
+struct stlink_interface_param_s {
+ /** */
+ char *device_desc;
+ /** */
+ char *serial;
+ /** */
+ uint16_t vid;
+ /** */
+ uint16_t pid;
+};
+
+struct stlink_interface_s {
+ /** */
+ struct stlink_interface_param_s param;
+ /** */
+ const struct stlink_layout *layout;
+ /** */
+ void *fd;
+};
+
+/** */
+int stlink_interface_open(void);
+/** */
+int stlink_interface_init_target(struct target *t);
+
+#endif
diff --git a/src/jtag/stlink/stlink_layout.c b/src/jtag/stlink/stlink_layout.c
new file mode 100644
index 00000000..dfcfbf40
--- /dev/null
+++ b/src/jtag/stlink/stlink_layout.c
@@ -0,0 +1,85 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Mathias Kuester *
+ * Mathias Kuester <kesmtp@freenet.de> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* project specific includes */
+#include <jtag/interface.h>
+#include <transport/transport.h>
+#include <helper/time_support.h>
+
+#include <jtag/stlink/stlink_layout.h>
+#include <jtag/stlink/stlink_tcl.h>
+#include <jtag/stlink/stlink_interface.h>
+
+#define STLINK_LAYOUT_UNKNOWN 0
+#define STLINK_LAYOUT_SG 1
+#define STLINK_LAYOUT_USB 2
+
+static int stlink_layout_open(struct stlink_interface_s *stlink_if)
+{
+ int res;
+
+ LOG_DEBUG("stlink_layout_open");
+
+ stlink_if->fd = NULL;
+
+ res = stlink_if->layout->api->open(&stlink_if->param, &stlink_if->fd);
+
+ if (res != ERROR_OK) {
+ LOG_DEBUG("stlink_layout_open: failed");
+ return res;
+ }
+
+ return ERROR_OK;
+}
+
+static int stlink_layout_close(struct stlink_interface_s *stlink_if)
+{
+ return ERROR_OK;
+}
+
+static const struct stlink_layout stlink_layouts[] = {
+ {
+ .name = "usb",
+ .type = STLINK_LAYOUT_USB,
+ .open = stlink_layout_open,
+ .close = stlink_layout_close,
+ .api = &stlink_layout_api,
+ },
+ {.name = NULL, /* END OF TABLE */ },
+};
+
+/** */
+const struct stlink_layout *stlink_layout_get_list(void)
+{
+ return stlink_layouts;
+}
+
+int stlink_layout_init(struct stlink_interface_s *stlink_if)
+{
+ LOG_DEBUG("stlink_layout_init");
+
+ stlink_if->layout = &stlink_layouts[0];
+
+ return ERROR_OK;
+}
diff --git a/src/jtag/stlink/stlink_layout.h b/src/jtag/stlink/stlink_layout.h
new file mode 100644
index 00000000..46517a78
--- /dev/null
+++ b/src/jtag/stlink/stlink_layout.h
@@ -0,0 +1,81 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Mathias Kuester *
+ * Mathias Kuester <kesmtp@freenet.de> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef _STLINK_LAYOUT_H_
+#define _STLINK_LAYOUT_H_
+
+/** */
+struct stlink_interface_s;
+struct stlink_interface_param_s;
+
+/** */
+extern struct stlink_layout_api_s stlink_layout_api;
+
+/** */
+struct stlink_layout_api_s {
+ /** */
+ int (*open) (struct stlink_interface_param_s *param, void **fd);
+ /** */
+ int (*close) (void *fd);
+ /** */
+ int (*reset) (void *fd);
+ /** */
+ int (*run) (void *fd);
+ /** */
+ int (*halt) (void *fd);
+ /** */
+ int (*step) (void *fd);
+ /** */
+ int (*read_regs) (void *fd);
+ /** */
+ int (*read_reg) (void *fd, int num, uint32_t *val);
+ /** */
+ int (*write_reg) (void *fd, int num, uint32_t val);
+ /** */
+ int (*read_mem32) (void *handle, uint32_t addr, uint16_t len,
+ uint32_t *buffer);
+ /** */
+ int (*write_mem32) (void *handle, uint32_t addr, uint16_t len,
+ uint32_t *buffer);
+ /** */
+ int (*idcode) (void *fd, uint32_t *idcode);
+ /** */
+ enum target_state (*state) (void *fd);
+};
+
+/** */
+struct stlink_layout {
+ /** */
+ char *name;
+ /** */
+ int type;
+ /** */
+ int (*open) (struct stlink_interface_s *stlink_if);
+ /** */
+ int (*close) (struct stlink_interface_s *stlink_if);
+ /** */
+ struct stlink_layout_api_s *api;
+};
+
+/** */
+const struct stlink_layout *stlink_layout_get_list(void);
+/** */
+int stlink_layout_init(struct stlink_interface_s *stlink_if);
+
+#endif
diff --git a/src/jtag/stlink/stlink_tcl.c b/src/jtag/stlink/stlink_tcl.c
new file mode 100644
index 00000000..a73afa36
--- /dev/null
+++ b/src/jtag/stlink/stlink_tcl.c
@@ -0,0 +1,136 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Mathias Kuester *
+ * Mathias Kuester <kesmtp@freenet.de> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* project specific includes */
+#include <jtag/interface.h>
+#include <transport/transport.h>
+#include <helper/time_support.h>
+
+static int jim_newtap_expected_id(Jim_Nvp *n, Jim_GetOptInfo *goi,
+ struct jtag_tap *pTap)
+{
+ jim_wide w;
+ int e = Jim_GetOpt_Wide(goi, &w);
+ if (e != JIM_OK) {
+ Jim_SetResultFormatted(goi->interp, "option: %s bad parameter",
+ n->name);
+ return e;
+ }
+
+ unsigned expected_len = sizeof(uint32_t) * pTap->expected_ids_cnt;
+ uint32_t *new_expected_ids = malloc(expected_len + sizeof(uint32_t));
+ if (new_expected_ids == NULL) {
+ Jim_SetResultFormatted(goi->interp, "no memory");
+ return JIM_ERR;
+ }
+
+ memcpy(new_expected_ids, pTap->expected_ids, expected_len);
+
+ new_expected_ids[pTap->expected_ids_cnt] = w;
+
+ free(pTap->expected_ids);
+ pTap->expected_ids = new_expected_ids;
+ pTap->expected_ids_cnt++;
+
+ return JIM_OK;
+}
+
+#define NTAP_OPT_EXPECTED_ID 0
+
+static int jim_stlink_newtap_cmd(Jim_GetOptInfo *goi)
+{
+ struct jtag_tap *pTap;
+ int x;
+ int e;
+ Jim_Nvp *n;
+ char *cp;
+ const Jim_Nvp opts[] = {
+ {.name = "-expected-id", .value = NTAP_OPT_EXPECTED_ID},
+ {.name = NULL, .value = -1},
+ };
+
+ pTap = calloc(1, sizeof(struct jtag_tap));
+ if (!pTap) {
+ Jim_SetResultFormatted(goi->interp, "no memory");
+ return JIM_ERR;
+ }
+
+ /*
+ * we expect CHIP + TAP + OPTIONS
+ * */
+ if (goi->argc < 3) {
+ Jim_SetResultFormatted(goi->interp,
+ "Missing CHIP TAP OPTIONS ....");
+ free(pTap);
+ return JIM_ERR;
+ }
+ Jim_GetOpt_String(goi, &cp, NULL);
+ pTap->chip = strdup(cp);
+
+ Jim_GetOpt_String(goi, &cp, NULL);
+ pTap->tapname = strdup(cp);
+
+ /* name + dot + name + null */
+ x = strlen(pTap->chip) + 1 + strlen(pTap->tapname) + 1;
+ cp = malloc(x);
+ sprintf(cp, "%s.%s", pTap->chip, pTap->tapname);
+ pTap->dotted_name = cp;
+
+ LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
+ pTap->chip, pTap->tapname, pTap->dotted_name, goi->argc);
+
+ while (goi->argc) {
+ e = Jim_GetOpt_Nvp(goi, opts, &n);
+ if (e != JIM_OK) {
+ Jim_GetOpt_NvpUnknown(goi, opts, 0);
+ free((void *)pTap->dotted_name);
+ free(pTap);
+ return e;
+ }
+ LOG_DEBUG("Processing option: %s", n->name);
+ switch (n->value) {
+ case NTAP_OPT_EXPECTED_ID:
+ e = jim_newtap_expected_id(n, goi, pTap);
+ if (JIM_OK != e) {
+ free((void *)pTap->dotted_name);
+ free(pTap);
+ return e;
+ }
+ break;
+ } /* switch (n->value) */
+ } /* while (goi->argc) */
+
+ /* default is enabled-after-reset */
+ pTap->enabled = !pTap->disabled_after_reset;
+
+ jtag_tap_init(pTap);
+ return JIM_OK;
+}
+
+int jim_stlink_newtap(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
+{
+ Jim_GetOptInfo goi;
+ Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1);
+ return jim_stlink_newtap_cmd(&goi);
+}
diff --git a/src/jtag/stlink/stlink_tcl.h b/src/jtag/stlink/stlink_tcl.h
new file mode 100644
index 00000000..395d546d
--- /dev/null
+++ b/src/jtag/stlink/stlink_tcl.h
@@ -0,0 +1,26 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Mathias Kuester *
+ * Mathias Kuester <kesmtp@freenet.de> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef _STLINK_TCL_
+#define _STLINK_TCL_
+
+/** */
+int jim_stlink_newtap(Jim_Interp *interp, int argc, Jim_Obj * const *argv);
+
+#endif
diff --git a/src/jtag/stlink/stlink_transport.c b/src/jtag/stlink/stlink_transport.c
new file mode 100644
index 00000000..6f161954
--- /dev/null
+++ b/src/jtag/stlink/stlink_transport.c
@@ -0,0 +1,180 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Mathias Kuester *
+ * Mathias Kuester <kesmtp@freenet.de> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* project specific includes */
+#include <jtag/interface.h>
+#include <jtag/tcl.h>
+#include <transport/transport.h>
+#include <helper/time_support.h>
+#include <target/target.h>
+#include <jtag/stlink/stlink_tcl.h>
+#include <jtag/stlink/stlink_interface.h>
+
+COMMAND_HANDLER(stlink_transport_jtag_command)
+{
+ LOG_DEBUG("stlink_transport_jtag_command");
+
+ return ERROR_OK;
+}
+
+static const struct command_registration
+stlink_transport_stlink_subcommand_handlers[] = {
+ {
+ .name = "newtap",
+ .mode = COMMAND_CONFIG,
+ .jim_handler = jim_stlink_newtap,
+ .help = "Create a new TAP instance named basename.tap_type, "
+ "and appends it to the scan chain.",
+ .usage = "basename tap_type '-irlen' count "
+ "['-expected_id' number] ",
+ },
+
+ COMMAND_REGISTRATION_DONE
+};
+
+static const struct command_registration
+stlink_transport_jtag_subcommand_handlers[] = {
+ {
+ .name = "init",
+ .mode = COMMAND_ANY,
+ .handler = stlink_transport_jtag_command,
+ },
+ {
+ .name = "arp_init",
+ .mode = COMMAND_ANY,
+ .handler = stlink_transport_jtag_command,
+ },
+ {
+ .name = "arp_init-reset",
+ .mode = COMMAND_ANY,
+ .handler = stlink_transport_jtag_command,
+ },
+ {
+ .name = "tapisenabled",
+ .mode = COMMAND_EXEC,
+ .jim_handler = jim_jtag_tap_enabler,
+ },
+ {
+ .name = "tapenable",
+ .mode = COMMAND_EXEC,
+ .jim_handler = jim_jtag_tap_enabler,
+ },
+ {
+ .name = "tapdisable",
+ .mode = COMMAND_EXEC,
+ .handler = stlink_transport_jtag_command,
+ },
+ {
+ .name = "configure",
+ .mode = COMMAND_EXEC,
+ .handler = stlink_transport_jtag_command,
+ },
+ {
+ .name = "cget",
+ .mode = COMMAND_EXEC,
+ .jim_handler = jim_jtag_configure,
+ },
+ {
+ .name = "names",
+ .mode = COMMAND_ANY,
+ .handler = stlink_transport_jtag_command,
+ },
+
+ COMMAND_REGISTRATION_DONE
+};
+
+static const struct command_registration stlink_transport_command_handlers[] = {
+
+ {
+ .name = "stlink",
+ .mode = COMMAND_ANY,
+ .help = "perform stlink actions",
+ .chain = stlink_transport_stlink_subcommand_handlers,
+ },
+ {
+ .name = "jtag",
+ .mode = COMMAND_ANY,
+ .chain = stlink_transport_jtag_subcommand_handlers,
+ },
+ COMMAND_REGISTRATION_DONE
+};
+
+static int stlink_transport_register_commands(struct command_context *cmd_ctx)
+{
+ return register_commands(cmd_ctx, NULL,
+ stlink_transport_command_handlers);
+}
+
+static int stlink_transport_init(struct command_context *cmd_ctx)
+{
+ LOG_DEBUG("stlink_transport_init");
+ struct target *t = get_current_target(cmd_ctx);
+
+ if (!t) {
+ LOG_ERROR("stlink_transport_init: no current target");
+ return ERROR_FAIL;
+
+ }
+
+ stlink_interface_open();
+
+ return stlink_interface_init_target(t);
+}
+
+static int stlink_transport_select(struct command_context *ctx)
+{
+ LOG_DEBUG("stlink_transport_select");
+
+ int retval;
+
+ /* NOTE: interface init must already have been done.
+ * That works with only C code ... no Tcl glue required.
+ */
+
+ retval = stlink_transport_register_commands(ctx);
+
+ if (retval != ERROR_OK)
+ return retval;
+
+ return ERROR_OK;
+}
+
+static struct transport stlink_transport = {
+ .name = "stlink",
+ .select = stlink_transport_select,
+ .init = stlink_transport_init,
+};
+
+const char *stlink_transports[] = { "stlink", NULL };
+
+static void stlink_constructor(void) __attribute__ ((constructor));
+static void stlink_constructor(void)
+{
+ transport_register(&stlink_transport);
+}
+
+bool transport_is_stlink(void)
+{
+ return get_current_transport() == &stlink_transport;
+}
diff --git a/src/jtag/stlink/stlink_transport.h b/src/jtag/stlink/stlink_transport.h
new file mode 100644
index 00000000..066b194b
--- /dev/null
+++ b/src/jtag/stlink/stlink_transport.h
@@ -0,0 +1,23 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Mathias Kuester *
+ * Mathias Kuester <kesmtp@freenet.de> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef _STLINK_TRANSPORT_
+#define _STLINK_TRANSPORT_
+
+#endif