1 /***************************************************************************
2 * Copyright (C) 2011 by Mathias Kuester *
3 * Mathias Kuester <kesmtp@freenet.de> *
5 * Copyright (C) 2012 by Spencer Oliver *
6 * spen@spen-soft.co.uk *
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. *
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. *
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 ***************************************************************************/
26 /* project specific includes */
27 #include <jtag/interface.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");
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[] = {
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[] = {
68 .handler = hl_transport_jtag_command,
74 .handler = hl_transport_jtag_command,
78 .name = "arp_init-reset",
80 .handler = hl_transport_reset_command,
84 .name = "tapisenabled",
86 .jim_handler = jim_jtag_tap_enabler,
91 .jim_handler = jim_jtag_tap_enabler,
96 .handler = hl_transport_jtag_command,
101 .mode = COMMAND_EXEC,
102 .handler = hl_transport_jtag_command,
107 .mode = COMMAND_EXEC,
108 .jim_handler = jim_jtag_configure,
113 .handler = hl_transport_jtag_command,
117 COMMAND_REGISTRATION_DONE
120 static const struct command_registration stlink_transport_command_handlers[] = {
125 .help = "perform hl adapter actions",
127 .chain = hl_transport_stlink_subcommand_handlers,
133 .chain = hl_transport_jtag_subcommand_handlers,
136 .name = "jtag_ntrst_delay",
138 .handler = hl_transport_jtag_command,
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;
158 LOG_ERROR("no current target");
162 transport = get_current_transport();
165 LOG_ERROR("no transport selected");
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;
179 int retval = hl_interface_open(tr);
181 if (retval != ERROR_OK)
184 return hl_interface_init_target(t);
187 static int hl_transport_select(struct command_context *ctx)
189 LOG_DEBUG("hl_transport_select");
193 /* NOTE: interface init must already have been done.
194 * That works with only C code ... no Tcl glue required.
197 retval = hl_transport_register_commands(ctx);
199 if (retval != ERROR_OK)
205 static struct transport hl_swd_transport = {
207 .select = hl_transport_select,
208 .init = hl_transport_init,
209 .override_target = hl_interface_override_target,
212 static struct transport hl_jtag_transport = {
214 .select = hl_transport_select,
215 .init = hl_transport_init,
216 .override_target = hl_interface_override_target,
219 const char *hl_transports[] = { "hla_swd", "hla_jtag", NULL };
221 static void hl_constructor(void) __attribute__ ((constructor));
222 static void hl_constructor(void)
224 transport_register(&hl_swd_transport);
225 transport_register(&hl_jtag_transport);
228 bool transport_is_hla(void)
231 t = get_current_transport();
232 return t == &hl_swd_transport || t == &hl_jtag_transport;