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, write to the *
20 * Free Software Foundation, Inc., *
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
22 ***************************************************************************/
28 /* project specific includes */
29 #include <jtag/interface.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");
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[] = {
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[] = {
70 .handler = hl_transport_jtag_command,
76 .handler = hl_transport_jtag_command,
80 .name = "arp_init-reset",
82 .handler = hl_transport_reset_command,
86 .name = "tapisenabled",
88 .jim_handler = jim_jtag_tap_enabler,
93 .jim_handler = jim_jtag_tap_enabler,
98 .handler = hl_transport_jtag_command,
103 .mode = COMMAND_EXEC,
104 .handler = hl_transport_jtag_command,
109 .mode = COMMAND_EXEC,
110 .jim_handler = jim_jtag_configure,
115 .handler = hl_transport_jtag_command,
119 COMMAND_REGISTRATION_DONE
122 static const struct command_registration stlink_transport_command_handlers[] = {
127 .help = "perform hl adapter actions",
129 .chain = hl_transport_stlink_subcommand_handlers,
135 .chain = hl_transport_jtag_subcommand_handlers,
138 .name = "jtag_ntrst_delay",
140 .handler = hl_transport_jtag_command,
143 COMMAND_REGISTRATION_DONE
146 static int hl_transport_register_commands(struct command_context *cmd_ctx)
148 return register_commands(cmd_ctx, NULL,
149 stlink_transport_command_handlers);
152 static int hl_transport_init(struct command_context *cmd_ctx)
154 LOG_DEBUG("hl_transport_init");
155 struct target *t = get_current_target(cmd_ctx);
156 struct transport *transport;
157 enum hl_transports tr;
160 LOG_ERROR("no current target");
164 transport = get_current_transport();
167 LOG_ERROR("no transport selected");
171 LOG_DEBUG("current transport %s", transport->name);
173 /* get selected transport as enum */
174 tr = HL_TRANSPORT_UNKNOWN;
176 if (strcmp(transport->name, "hla_swd") == 0)
177 tr = HL_TRANSPORT_SWD;
178 else if (strcmp(transport->name, "hla_jtag") == 0)
179 tr = HL_TRANSPORT_JTAG;
180 else if (strcmp(transport->name, "stlink_swim") == 0)
181 tr = HL_TRANSPORT_SWIM;
183 int retval = hl_interface_open(tr);
185 if (retval != ERROR_OK)
188 return hl_interface_init_target(t);
191 static int hl_transport_select(struct command_context *ctx)
193 LOG_DEBUG("hl_transport_select");
197 /* NOTE: interface init must already have been done.
198 * That works with only C code ... no Tcl glue required.
201 retval = hl_transport_register_commands(ctx);
203 if (retval != ERROR_OK)
209 static struct transport hl_swd_transport = {
211 .select = hl_transport_select,
212 .init = hl_transport_init,
213 .override_target = hl_interface_override_target,
216 static struct transport hl_jtag_transport = {
218 .select = hl_transport_select,
219 .init = hl_transport_init,
220 .override_target = hl_interface_override_target,
223 static struct transport stlink_swim_transport = {
224 .name = "stlink_swim",
225 .select = hl_transport_select,
226 .init = hl_transport_init,
229 const char *hl_transports[] = { "hla_swd", "hla_jtag", "stlink_swim", NULL };
231 static void hl_constructor(void) __attribute__ ((constructor));
232 static void hl_constructor(void)
234 transport_register(&hl_swd_transport);
235 transport_register(&hl_jtag_transport);
236 transport_register(&stlink_swim_transport);