]> git.sur5r.net Git - openocd/blob - src/jtag/hla/hla_transport.c
update files to correct FSF address
[openocd] / src / jtag / hla / hla_transport.c
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  ***************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
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>
37
38 COMMAND_HANDLER(hl_transport_jtag_command)
39 {
40         LOG_DEBUG("hl_transport_jtag_command");
41
42         return ERROR_OK;
43 }
44
45 COMMAND_HANDLER(hl_transport_reset_command)
46 {
47         return hl_interface_init_reset();
48 }
49
50 static const struct command_registration
51 hl_transport_stlink_subcommand_handlers[] = {
52         {
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] ",
60          },
61
62         COMMAND_REGISTRATION_DONE
63 };
64
65 static const struct command_registration
66 hl_transport_jtag_subcommand_handlers[] = {
67         {
68          .name = "init",
69          .mode = COMMAND_ANY,
70          .handler = hl_transport_jtag_command,
71          .usage = ""
72          },
73         {
74          .name = "arp_init",
75          .mode = COMMAND_ANY,
76          .handler = hl_transport_jtag_command,
77          .usage = ""
78          },
79         {
80          .name = "arp_init-reset",
81          .mode = COMMAND_ANY,
82          .handler = hl_transport_reset_command,
83          .usage = ""
84          },
85         {
86          .name = "tapisenabled",
87          .mode = COMMAND_EXEC,
88          .jim_handler = jim_jtag_tap_enabler,
89          },
90         {
91          .name = "tapenable",
92          .mode = COMMAND_EXEC,
93          .jim_handler = jim_jtag_tap_enabler,
94          },
95         {
96          .name = "tapdisable",
97          .mode = COMMAND_EXEC,
98          .handler = hl_transport_jtag_command,
99          .usage = "",
100          },
101         {
102          .name = "configure",
103          .mode = COMMAND_EXEC,
104          .handler = hl_transport_jtag_command,
105          .usage = "",
106          },
107         {
108          .name = "cget",
109          .mode = COMMAND_EXEC,
110          .jim_handler = jim_jtag_configure,
111          },
112         {
113          .name = "names",
114          .mode = COMMAND_ANY,
115          .handler = hl_transport_jtag_command,
116          .usage = "",
117          },
118
119         COMMAND_REGISTRATION_DONE
120 };
121
122 static const struct command_registration stlink_transport_command_handlers[] = {
123
124         {
125          .name = "hla",
126          .mode = COMMAND_ANY,
127          .help = "perform hl adapter actions",
128          .usage = "",
129          .chain = hl_transport_stlink_subcommand_handlers,
130          },
131         {
132          .name = "jtag",
133          .mode = COMMAND_ANY,
134          .usage = "",
135          .chain = hl_transport_jtag_subcommand_handlers,
136          },
137         COMMAND_REGISTRATION_DONE
138 };
139
140 static int hl_transport_register_commands(struct command_context *cmd_ctx)
141 {
142         return register_commands(cmd_ctx, NULL,
143                                  stlink_transport_command_handlers);
144 }
145
146 static int hl_transport_init(struct command_context *cmd_ctx)
147 {
148         LOG_DEBUG("hl_transport_init");
149         struct target *t = get_current_target(cmd_ctx);
150         struct transport *transport;
151         enum hl_transports tr;
152
153         if (!t) {
154                 LOG_ERROR("no current target");
155                 return ERROR_FAIL;
156         }
157
158         transport = get_current_transport();
159
160         if (!transport) {
161                 LOG_ERROR("no transport selected");
162                 return ERROR_FAIL;
163         }
164
165         LOG_DEBUG("current transport %s", transport->name);
166
167         /* get selected transport as enum */
168         tr = HL_TRANSPORT_UNKNOWN;
169
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;
176
177         int retval = hl_interface_open(tr);
178
179         if (retval != ERROR_OK)
180                 return retval;
181
182         return hl_interface_init_target(t);
183 }
184
185 static int hl_transport_select(struct command_context *ctx)
186 {
187         LOG_DEBUG("hl_transport_select");
188
189         int retval;
190
191         /* NOTE:  interface init must already have been done.
192          * That works with only C code ... no Tcl glue required.
193          */
194
195         retval = hl_transport_register_commands(ctx);
196
197         if (retval != ERROR_OK)
198                 return retval;
199
200         return ERROR_OK;
201 }
202
203 static struct transport hl_swd_transport = {
204         .name = "hla_swd",
205         .select = hl_transport_select,
206         .init = hl_transport_init,
207 };
208
209 static struct transport hl_jtag_transport = {
210         .name = "hla_jtag",
211         .select = hl_transport_select,
212         .init = hl_transport_init,
213 };
214
215 static struct transport stlink_swim_transport = {
216         .name = "stlink_swim",
217         .select = hl_transport_select,
218         .init = hl_transport_init,
219 };
220
221 const char *hl_transports[] = { "hla_swd", "hla_jtag", "stlink_swim", NULL };
222
223 static void hl_constructor(void) __attribute__ ((constructor));
224 static void hl_constructor(void)
225 {
226         transport_register(&hl_swd_transport);
227         transport_register(&hl_jtag_transport);
228         transport_register(&stlink_swim_transport);
229 }