update files to correct FSF address
[openocd.git] / src / jtag / hla / hla_transport.c
blobe3c003dc44ecbe764d86fa6be6d25c19e576a5ac
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, write to the *
20 * Free Software Foundation, Inc., *
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
22 ***************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
28 /* project specific includes */
29 #include <jtag/interface.h>
30 #include <jtag/tcl.h>
31 #include <transport/transport.h>
32 #include <helper/time_support.h>
33 #include <target/target.h>
34 #include <jtag/hla/hla_tcl.h>
35 #include <jtag/hla/hla_transport.h>
36 #include <jtag/hla/hla_interface.h>
38 COMMAND_HANDLER(hl_transport_jtag_command)
40 LOG_DEBUG("hl_transport_jtag_command");
42 return ERROR_OK;
45 COMMAND_HANDLER(hl_transport_reset_command)
47 return hl_interface_init_reset();
50 static const struct command_registration
51 hl_transport_stlink_subcommand_handlers[] = {
53 .name = "newtap",
54 .mode = COMMAND_CONFIG,
55 .jim_handler = jim_hl_newtap,
56 .help = "Create a new TAP instance named basename.tap_type, "
57 "and appends it to the scan chain.",
58 .usage = "basename tap_type '-irlen' count "
59 "['-expected_id' number] ",
62 COMMAND_REGISTRATION_DONE
65 static const struct command_registration
66 hl_transport_jtag_subcommand_handlers[] = {
68 .name = "init",
69 .mode = COMMAND_ANY,
70 .handler = hl_transport_jtag_command,
71 .usage = ""
74 .name = "arp_init",
75 .mode = COMMAND_ANY,
76 .handler = hl_transport_jtag_command,
77 .usage = ""
80 .name = "arp_init-reset",
81 .mode = COMMAND_ANY,
82 .handler = hl_transport_reset_command,
83 .usage = ""
86 .name = "tapisenabled",
87 .mode = COMMAND_EXEC,
88 .jim_handler = jim_jtag_tap_enabler,
91 .name = "tapenable",
92 .mode = COMMAND_EXEC,
93 .jim_handler = jim_jtag_tap_enabler,
96 .name = "tapdisable",
97 .mode = COMMAND_EXEC,
98 .handler = hl_transport_jtag_command,
99 .usage = "",
102 .name = "configure",
103 .mode = COMMAND_EXEC,
104 .handler = hl_transport_jtag_command,
105 .usage = "",
108 .name = "cget",
109 .mode = COMMAND_EXEC,
110 .jim_handler = jim_jtag_configure,
113 .name = "names",
114 .mode = COMMAND_ANY,
115 .handler = hl_transport_jtag_command,
116 .usage = "",
119 COMMAND_REGISTRATION_DONE
122 static const struct command_registration stlink_transport_command_handlers[] = {
125 .name = "hla",
126 .mode = COMMAND_ANY,
127 .help = "perform hl adapter actions",
128 .usage = "",
129 .chain = hl_transport_stlink_subcommand_handlers,
132 .name = "jtag",
133 .mode = COMMAND_ANY,
134 .usage = "",
135 .chain = hl_transport_jtag_subcommand_handlers,
137 COMMAND_REGISTRATION_DONE
140 static int hl_transport_register_commands(struct command_context *cmd_ctx)
142 return register_commands(cmd_ctx, NULL,
143 stlink_transport_command_handlers);
146 static int hl_transport_init(struct command_context *cmd_ctx)
148 LOG_DEBUG("hl_transport_init");
149 struct target *t = get_current_target(cmd_ctx);
150 struct transport *transport;
151 enum hl_transports tr;
153 if (!t) {
154 LOG_ERROR("no current target");
155 return ERROR_FAIL;
158 transport = get_current_transport();
160 if (!transport) {
161 LOG_ERROR("no transport selected");
162 return ERROR_FAIL;
165 LOG_DEBUG("current transport %s", transport->name);
167 /* get selected transport as enum */
168 tr = HL_TRANSPORT_UNKNOWN;
170 if (strcmp(transport->name, "hla_swd") == 0)
171 tr = HL_TRANSPORT_SWD;
172 else if (strcmp(transport->name, "hla_jtag") == 0)
173 tr = HL_TRANSPORT_JTAG;
174 else if (strcmp(transport->name, "stlink_swim") == 0)
175 tr = HL_TRANSPORT_SWIM;
177 int retval = hl_interface_open(tr);
179 if (retval != ERROR_OK)
180 return retval;
182 return hl_interface_init_target(t);
185 static int hl_transport_select(struct command_context *ctx)
187 LOG_DEBUG("hl_transport_select");
189 int retval;
191 /* NOTE: interface init must already have been done.
192 * That works with only C code ... no Tcl glue required.
195 retval = hl_transport_register_commands(ctx);
197 if (retval != ERROR_OK)
198 return retval;
200 return ERROR_OK;
203 static struct transport hl_swd_transport = {
204 .name = "hla_swd",
205 .select = hl_transport_select,
206 .init = hl_transport_init,
209 static struct transport hl_jtag_transport = {
210 .name = "hla_jtag",
211 .select = hl_transport_select,
212 .init = hl_transport_init,
215 static struct transport stlink_swim_transport = {
216 .name = "stlink_swim",
217 .select = hl_transport_select,
218 .init = hl_transport_init,
221 const char *hl_transports[] = { "hla_swd", "hla_jtag", "stlink_swim", NULL };
223 static void hl_constructor(void) __attribute__ ((constructor));
224 static void hl_constructor(void)
226 transport_register(&hl_swd_transport);
227 transport_register(&hl_jtag_transport);
228 transport_register(&stlink_swim_transport);