STLINK: swd transport renamed and jtag+swim transport added
[openocd/andreasf.git] / src / jtag / stlink / stlink_transport.c
blobdc3c68106df78360be9a9f9c8ccf19c34ba61063
1 /***************************************************************************
2 * Copyright (C) 2011 by Mathias Kuester *
3 * Mathias Kuester <kesmtp@freenet.de> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
25 /* project specific includes */
26 #include <jtag/interface.h>
27 #include <jtag/tcl.h>
28 #include <transport/transport.h>
29 #include <helper/time_support.h>
30 #include <target/target.h>
31 #include <jtag/stlink/stlink_tcl.h>
32 #include <jtag/stlink/stlink_transport.h>
33 #include <jtag/stlink/stlink_interface.h>
35 COMMAND_HANDLER(stlink_transport_jtag_command)
37 LOG_DEBUG("stlink_transport_jtag_command");
39 return ERROR_OK;
42 static const struct command_registration
43 stlink_transport_stlink_subcommand_handlers[] = {
45 .name = "newtap",
46 .mode = COMMAND_CONFIG,
47 .jim_handler = jim_stlink_newtap,
48 .help = "Create a new TAP instance named basename.tap_type, "
49 "and appends it to the scan chain.",
50 .usage = "basename tap_type '-irlen' count "
51 "['-expected_id' number] ",
54 COMMAND_REGISTRATION_DONE
57 static const struct command_registration
58 stlink_transport_jtag_subcommand_handlers[] = {
60 .name = "init",
61 .mode = COMMAND_ANY,
62 .handler = stlink_transport_jtag_command,
63 .usage = ""
66 .name = "arp_init",
67 .mode = COMMAND_ANY,
68 .handler = stlink_transport_jtag_command,
69 .usage = ""
72 .name = "arp_init-reset",
73 .mode = COMMAND_ANY,
74 .handler = stlink_transport_jtag_command,
75 .usage = ""
78 .name = "tapisenabled",
79 .mode = COMMAND_EXEC,
80 .jim_handler = jim_jtag_tap_enabler,
83 .name = "tapenable",
84 .mode = COMMAND_EXEC,
85 .jim_handler = jim_jtag_tap_enabler,
88 .name = "tapdisable",
89 .mode = COMMAND_EXEC,
90 .handler = stlink_transport_jtag_command,
91 .usage = "",
94 .name = "configure",
95 .mode = COMMAND_EXEC,
96 .handler = stlink_transport_jtag_command,
97 .usage = "",
100 .name = "cget",
101 .mode = COMMAND_EXEC,
102 .jim_handler = jim_jtag_configure,
105 .name = "names",
106 .mode = COMMAND_ANY,
107 .handler = stlink_transport_jtag_command,
108 .usage = "",
111 COMMAND_REGISTRATION_DONE
114 static const struct command_registration stlink_transport_command_handlers[] = {
117 .name = "stlink",
118 .mode = COMMAND_ANY,
119 .help = "perform stlink actions",
120 .usage = "",
121 .chain = stlink_transport_stlink_subcommand_handlers,
124 .name = "jtag",
125 .mode = COMMAND_ANY,
126 .usage = "",
127 .chain = stlink_transport_jtag_subcommand_handlers,
129 COMMAND_REGISTRATION_DONE
132 static int stlink_transport_register_commands(struct command_context *cmd_ctx)
134 return register_commands(cmd_ctx, NULL,
135 stlink_transport_command_handlers);
138 static int stlink_transport_init(struct command_context *cmd_ctx)
140 LOG_DEBUG("stlink_transport_init");
141 struct target *t = get_current_target(cmd_ctx);
142 struct transport *transport;
143 enum stlink_transports tr;
145 if (!t) {
146 LOG_ERROR("no current target");
147 return ERROR_FAIL;
150 transport = get_current_transport();
152 if (!transport) {
153 LOG_ERROR("no transport selected");
154 return ERROR_FAIL;
157 LOG_DEBUG("current transport %s", transport->name);
159 /* get selected transport as enum */
160 tr = STLINK_TRANSPORT_UNKNOWN;
162 if (strcmp(transport->name, "stlink_swd") == 0)
163 tr = STLINK_TRANSPORT_SWD;
164 else if (strcmp(transport->name, "stlink_jtag") == 0)
165 tr = STLINK_TRANSPORT_JTAG;
166 else if (strcmp(transport->name, "stlink_swim") == 0)
167 tr = STLINK_TRANSPORT_SWIM;
169 int retval = stlink_interface_open(tr);
171 if (retval != ERROR_OK)
172 return retval;
174 return stlink_interface_init_target(t);
177 static int stlink_transport_select(struct command_context *ctx)
179 LOG_DEBUG("stlink_transport_select");
181 int retval;
183 /* NOTE: interface init must already have been done.
184 * That works with only C code ... no Tcl glue required.
187 retval = stlink_transport_register_commands(ctx);
189 if (retval != ERROR_OK)
190 return retval;
192 return ERROR_OK;
195 static struct transport stlink_swd_transport = {
196 .name = "stlink_swd",
197 .select = stlink_transport_select,
198 .init = stlink_transport_init,
201 static struct transport stlink_jtag_transport = {
202 .name = "stlink_jtag",
203 .select = stlink_transport_select,
204 .init = stlink_transport_init,
207 static struct transport stlink_swim_transport = {
208 .name = "stlink_swim",
209 .select = stlink_transport_select,
210 .init = stlink_transport_init,
213 const char *stlink_transports[] = { "stlink_swd", "stlink_jtag", "stlink_swim", NULL };
215 static void stlink_constructor(void) __attribute__ ((constructor));
216 static void stlink_constructor(void)
218 transport_register(&stlink_swd_transport);
219 transport_register(&stlink_jtag_transport);
220 transport_register(&stlink_swim_transport);
223 bool transport_is_stlink(void)
225 return get_current_transport() == &stlink_swd_transport;