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[] = {
66 .chain = hl_transport_stlink_subcommand_handlers,
71 .handler = hl_transport_jtag_command,
77 .handler = hl_transport_jtag_command,
81 .name = "arp_init-reset",
83 .handler = hl_transport_reset_command,
87 .name = "tapisenabled",
89 .jim_handler = jim_jtag_tap_enabler,
94 .jim_handler = jim_jtag_tap_enabler,
99 .handler = hl_transport_jtag_command,
104 .mode = COMMAND_EXEC,
105 .handler = hl_transport_jtag_command,
110 .mode = COMMAND_EXEC,
111 .jim_handler = jim_jtag_configure,
116 .handler = hl_transport_jtag_command,
120 COMMAND_REGISTRATION_DONE
123 static const struct command_registration stlink_transport_command_handlers[] = {
128 .help = "perform hl adapter actions",
130 .chain = hl_transport_stlink_subcommand_handlers,
136 .chain = hl_transport_jtag_subcommand_handlers,
139 .name = "jtag_ntrst_delay",
141 .handler = hl_transport_jtag_command,
144 COMMAND_REGISTRATION_DONE
147 static int hl_transport_register_commands(struct command_context *cmd_ctx)
149 return register_commands(cmd_ctx, NULL,
150 stlink_transport_command_handlers);
153 static int hl_transport_init(struct command_context *cmd_ctx)
155 LOG_DEBUG("hl_transport_init");
156 struct target *t = get_current_target(cmd_ctx);
157 struct transport *transport;
158 enum hl_transports tr;
161 LOG_ERROR("no current target");
165 transport = get_current_transport();
168 LOG_ERROR("no transport selected");
172 LOG_DEBUG("current transport %s", transport->name);
174 /* get selected transport as enum */
175 tr = HL_TRANSPORT_UNKNOWN;
177 if (strcmp(transport->name, "hla_swd") == 0)
178 tr = HL_TRANSPORT_SWD;
179 else if (strcmp(transport->name, "hla_jtag") == 0)
180 tr = HL_TRANSPORT_JTAG;
182 int retval = hl_interface_open(tr);
184 if (retval != ERROR_OK)
187 return hl_interface_init_target(t);
190 static int hl_transport_select(struct command_context *ctx)
192 LOG_DEBUG("hl_transport_select");
196 /* NOTE: interface init must already have been done.
197 * That works with only C code ... no Tcl glue required.
200 retval = hl_transport_register_commands(ctx);
202 if (retval != ERROR_OK)
208 static struct transport hl_swd_transport = {
210 .select = hl_transport_select,
211 .init = hl_transport_init,
212 .override_target = hl_interface_override_target,
215 static struct transport hl_jtag_transport = {
217 .select = hl_transport_select,
218 .init = hl_transport_init,
219 .override_target = hl_interface_override_target,
222 const char *hl_transports[] = { "hla_swd", "hla_jtag", NULL };
224 static void hl_constructor(void) __attribute__ ((constructor));
225 static void hl_constructor(void)
227 transport_register(&hl_swd_transport);
228 transport_register(&hl_jtag_transport);
231 bool transport_is_hla(void)
234 t = get_current_transport();
235 return t == &hl_swd_transport || t == &hl_jtag_transport;