Remove FSF address from GPL notices
[openocd.git] / src / jtag / hla / hla_transport.c
blob5a5671db6892fc7b81b0a43100280b4e4814cf82
1 /***************************************************************************
2 * Copyright (C) 2011 by Mathias Kuester *
3 * Mathias Kuester <kesmtp@freenet.de> *
4 * *
5 * Copyright (C) 2012 by Spencer Oliver *
6 * spen@spen-soft.co.uk *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
20 ***************************************************************************/
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
26 /* project specific includes */
27 #include <jtag/interface.h>
28 #include <jtag/tcl.h>
29 #include <transport/transport.h>
30 #include <helper/time_support.h>
31 #include <target/target.h>
32 #include <jtag/hla/hla_tcl.h>
33 #include <jtag/hla/hla_transport.h>
34 #include <jtag/hla/hla_interface.h>
36 COMMAND_HANDLER(hl_transport_jtag_command)
38 LOG_DEBUG("hl_transport_jtag_command");
40 return ERROR_OK;
43 COMMAND_HANDLER(hl_transport_reset_command)
45 return hl_interface_init_reset();
48 static const struct command_registration
49 hl_transport_stlink_subcommand_handlers[] = {
51 .name = "newtap",
52 .mode = COMMAND_CONFIG,
53 .jim_handler = jim_hl_newtap,
54 .help = "Create a new TAP instance named basename.tap_type, "
55 "and appends it to the scan chain.",
56 .usage = "basename tap_type '-irlen' count "
57 "['-expected_id' number] ",
60 COMMAND_REGISTRATION_DONE
63 static const struct command_registration
64 hl_transport_jtag_subcommand_handlers[] = {
66 .name = "init",
67 .mode = COMMAND_ANY,
68 .handler = hl_transport_jtag_command,
69 .usage = ""
72 .name = "arp_init",
73 .mode = COMMAND_ANY,
74 .handler = hl_transport_jtag_command,
75 .usage = ""
78 .name = "arp_init-reset",
79 .mode = COMMAND_ANY,
80 .handler = hl_transport_reset_command,
81 .usage = ""
84 .name = "tapisenabled",
85 .mode = COMMAND_EXEC,
86 .jim_handler = jim_jtag_tap_enabler,
89 .name = "tapenable",
90 .mode = COMMAND_EXEC,
91 .jim_handler = jim_jtag_tap_enabler,
94 .name = "tapdisable",
95 .mode = COMMAND_EXEC,
96 .handler = hl_transport_jtag_command,
97 .usage = "",
100 .name = "configure",
101 .mode = COMMAND_EXEC,
102 .handler = hl_transport_jtag_command,
103 .usage = "",
106 .name = "cget",
107 .mode = COMMAND_EXEC,
108 .jim_handler = jim_jtag_configure,
111 .name = "names",
112 .mode = COMMAND_ANY,
113 .handler = hl_transport_jtag_command,
114 .usage = "",
117 COMMAND_REGISTRATION_DONE
120 static const struct command_registration stlink_transport_command_handlers[] = {
123 .name = "hla",
124 .mode = COMMAND_ANY,
125 .help = "perform hl adapter actions",
126 .usage = "",
127 .chain = hl_transport_stlink_subcommand_handlers,
130 .name = "jtag",
131 .mode = COMMAND_ANY,
132 .usage = "",
133 .chain = hl_transport_jtag_subcommand_handlers,
136 .name = "jtag_ntrst_delay",
137 .mode = COMMAND_ANY,
138 .handler = hl_transport_jtag_command,
139 .usage = "",
141 COMMAND_REGISTRATION_DONE
144 static int hl_transport_register_commands(struct command_context *cmd_ctx)
146 return register_commands(cmd_ctx, NULL,
147 stlink_transport_command_handlers);
150 static int hl_transport_init(struct command_context *cmd_ctx)
152 LOG_DEBUG("hl_transport_init");
153 struct target *t = get_current_target(cmd_ctx);
154 struct transport *transport;
155 enum hl_transports tr;
157 if (!t) {
158 LOG_ERROR("no current target");
159 return ERROR_FAIL;
162 transport = get_current_transport();
164 if (!transport) {
165 LOG_ERROR("no transport selected");
166 return ERROR_FAIL;
169 LOG_DEBUG("current transport %s", transport->name);
171 /* get selected transport as enum */
172 tr = HL_TRANSPORT_UNKNOWN;
174 if (strcmp(transport->name, "hla_swd") == 0)
175 tr = HL_TRANSPORT_SWD;
176 else if (strcmp(transport->name, "hla_jtag") == 0)
177 tr = HL_TRANSPORT_JTAG;
178 else if (strcmp(transport->name, "stlink_swim") == 0)
179 tr = HL_TRANSPORT_SWIM;
181 int retval = hl_interface_open(tr);
183 if (retval != ERROR_OK)
184 return retval;
186 return hl_interface_init_target(t);
189 static int hl_transport_select(struct command_context *ctx)
191 LOG_DEBUG("hl_transport_select");
193 int retval;
195 /* NOTE: interface init must already have been done.
196 * That works with only C code ... no Tcl glue required.
199 retval = hl_transport_register_commands(ctx);
201 if (retval != ERROR_OK)
202 return retval;
204 return ERROR_OK;
207 static struct transport hl_swd_transport = {
208 .name = "hla_swd",
209 .select = hl_transport_select,
210 .init = hl_transport_init,
211 .override_target = hl_interface_override_target,
214 static struct transport hl_jtag_transport = {
215 .name = "hla_jtag",
216 .select = hl_transport_select,
217 .init = hl_transport_init,
218 .override_target = hl_interface_override_target,
221 static struct transport stlink_swim_transport = {
222 .name = "stlink_swim",
223 .select = hl_transport_select,
224 .init = hl_transport_init,
227 const char *hl_transports[] = { "hla_swd", "hla_jtag", "stlink_swim", NULL };
229 static void hl_constructor(void) __attribute__ ((constructor));
230 static void hl_constructor(void)
232 transport_register(&hl_swd_transport);
233 transport_register(&hl_jtag_transport);
234 transport_register(&stlink_swim_transport);