jtag_interface: .speed can be NULL when not needed
[openocd.git] / src / jtag / hla / hla_interface.c
blob53ad8e71739fbbdfbbecf092973993806f542ca7
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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
28 /* project specific includes */
29 #include <jtag/interface.h>
30 #include <transport/transport.h>
31 #include <helper/time_support.h>
33 #include <jtag/hla/hla_tcl.h>
34 #include <jtag/hla/hla_layout.h>
35 #include <jtag/hla/hla_transport.h>
36 #include <jtag/hla/hla_interface.h>
38 #include <target/target.h>
40 static struct hl_interface_s hl_if = { {0, 0, 0, 0, 0, 0, 0}, 0, 0 };
42 int hl_interface_open(enum hl_transports tr)
44 LOG_DEBUG("hl_interface_open");
46 /* set transport mode */
47 hl_if.param.transport = tr;
49 int result = hl_if.layout->open(&hl_if);
50 if (result != ERROR_OK)
51 return result;
53 return hl_interface_init_reset();
56 int hl_interface_init_target(struct target *t)
58 int res;
60 LOG_DEBUG("hl_interface_init_target");
62 /* this is the interface for the current target and we
63 * can setup the private pointer in the tap structure
64 * if the interface match the tap idcode
66 res = hl_if.layout->api->idcode(hl_if.fd, &t->tap->idcode);
68 if (res != ERROR_OK)
69 return res;
71 unsigned ii, limit = t->tap->expected_ids_cnt;
72 int found = 0;
74 for (ii = 0; ii < limit; ii++) {
75 uint32_t expected = t->tap->expected_ids[ii];
77 /* treat "-expected-id 0" as a "don't-warn" wildcard */
78 if (!expected || (t->tap->idcode == expected)) {
79 found = 1;
80 break;
84 if (found == 0) {
85 LOG_ERROR("hl_interface_init_target: target not found: idcode: 0x%08x",
86 t->tap->idcode);
87 return ERROR_FAIL;
90 t->tap->priv = &hl_if;
91 t->tap->hasidcode = 1;
93 return ERROR_OK;
96 static int hl_interface_init(void)
98 LOG_DEBUG("hl_interface_init");
100 /* here we can initialize the layout */
101 return hl_layout_init(&hl_if);
104 static int hl_interface_quit(void)
106 LOG_DEBUG("hl_interface_quit");
108 return ERROR_OK;
111 static int hl_interface_execute_queue(void)
113 LOG_DEBUG("hl_interface_execute_queue: ignored");
115 return ERROR_OK;
118 int hl_interface_init_reset(void)
120 enum reset_types jtag_reset_config = jtag_get_reset_config();
122 if (jtag_reset_config & RESET_CNCT_UNDER_SRST) {
123 if (jtag_reset_config & RESET_SRST_NO_GATING) {
124 jtag_add_reset(0, 1);
125 hl_if.layout->api->assert_srst(hl_if.fd, 0);
126 } else
127 LOG_WARNING("\'srst_nogate\' reset_config option is required");
130 return ERROR_OK;
133 COMMAND_HANDLER(hl_interface_handle_device_desc_command)
135 LOG_DEBUG("hl_interface_handle_device_desc_command");
137 if (CMD_ARGC == 1) {
138 hl_if.param.device_desc = strdup(CMD_ARGV[0]);
139 } else {
140 LOG_ERROR("expected exactly one argument to hl_device_desc <description>");
143 return ERROR_OK;
146 COMMAND_HANDLER(hl_interface_handle_serial_command)
148 LOG_DEBUG("hl_interface_handle_serial_command");
150 if (CMD_ARGC == 1) {
151 hl_if.param.serial = strdup(CMD_ARGV[0]);
152 } else {
153 LOG_ERROR("expected exactly one argument to hl_serial <serial-number>");
156 return ERROR_OK;
159 COMMAND_HANDLER(hl_interface_handle_layout_command)
161 LOG_DEBUG("hl_interface_handle_layout_command");
163 if (CMD_ARGC != 1) {
164 LOG_ERROR("Need exactly one argument to stlink_layout");
165 return ERROR_COMMAND_SYNTAX_ERROR;
168 if (hl_if.layout) {
169 LOG_ERROR("already specified hl_layout %s",
170 hl_if.layout->name);
171 return (strcmp(hl_if.layout->name, CMD_ARGV[0]) != 0)
172 ? ERROR_FAIL : ERROR_OK;
175 for (const struct hl_layout *l = hl_layout_get_list(); l->name;
176 l++) {
177 if (strcmp(l->name, CMD_ARGV[0]) == 0) {
178 hl_if.layout = l;
179 return ERROR_OK;
183 LOG_ERROR("No adapter layout '%s' found", CMD_ARGV[0]);
184 return ERROR_FAIL;
187 COMMAND_HANDLER(hl_interface_handle_vid_pid_command)
189 LOG_DEBUG("hl_interface_handle_vid_pid_command");
191 if (CMD_ARGC != 2) {
192 LOG_WARNING("ignoring extra IDs in hl_vid_pid (maximum is 1 pair)");
193 return ERROR_COMMAND_SYNTAX_ERROR;
196 COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], hl_if.param.vid);
197 COMMAND_PARSE_NUMBER(u16, CMD_ARGV[1], hl_if.param.pid);
199 return ERROR_OK;
202 COMMAND_HANDLER(stlink_interface_handle_api_command)
204 if (CMD_ARGC != 1)
205 return ERROR_COMMAND_SYNTAX_ERROR;
207 unsigned new_api;
208 COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], new_api);
209 if ((new_api == 0) || (new_api > 2))
210 return ERROR_COMMAND_SYNTAX_ERROR;
212 hl_if.param.api = new_api;
214 return ERROR_OK;
217 static const struct command_registration hl_interface_command_handlers[] = {
219 .name = "hla_device_desc",
220 .handler = &hl_interface_handle_device_desc_command,
221 .mode = COMMAND_CONFIG,
222 .help = "set the a device description of the adapter",
223 .usage = "description_string",
226 .name = "hla_serial",
227 .handler = &hl_interface_handle_serial_command,
228 .mode = COMMAND_CONFIG,
229 .help = "set the serial number of the adapter",
230 .usage = "serial_string",
233 .name = "hla_layout",
234 .handler = &hl_interface_handle_layout_command,
235 .mode = COMMAND_CONFIG,
236 .help = "set the layout of the adapter",
237 .usage = "layout_name",
240 .name = "hla_vid_pid",
241 .handler = &hl_interface_handle_vid_pid_command,
242 .mode = COMMAND_CONFIG,
243 .help = "the vendor and product ID of the adapter",
244 .usage = "(vid pid)* ",
247 .name = "stlink_api",
248 .handler = &stlink_interface_handle_api_command,
249 .mode = COMMAND_CONFIG,
250 .help = "set the desired stlink api level",
251 .usage = "api version 1 or 2",
253 COMMAND_REGISTRATION_DONE
256 struct jtag_interface hl_interface = {
257 .name = "hla",
258 .supported = 0,
259 .commands = hl_interface_command_handlers,
260 .transports = hl_transports,
261 .init = hl_interface_init,
262 .quit = hl_interface_quit,
263 .execute_queue = hl_interface_execute_queue,