OpenOCD
hla_transport.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2011 by Mathias Kuester *
5  * Mathias Kuester <kesmtp@freenet.de> *
6  * *
7  * Copyright (C) 2012 by Spencer Oliver *
8  * spen@spen-soft.co.uk *
9  ***************************************************************************/
10 
11 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14 
15 /* project specific includes */
16 #include <jtag/interface.h>
17 #include <jtag/tcl.h>
18 #include <transport/transport.h>
19 #include <helper/time_support.h>
20 #include <target/target.h>
21 #include <jtag/hla/hla_transport.h>
22 #include <jtag/hla/hla_interface.h>
23 
24 COMMAND_HANDLER(hl_transport_jtag_command)
25 {
26  LOG_DEBUG("hl_transport_jtag_command");
27 
28  return ERROR_OK;
29 }
30 
31 COMMAND_HANDLER(hl_transport_reset_command)
32 {
33  return hl_interface_init_reset();
34 }
35 
37  {
38  .name = "newdap",
39  .mode = COMMAND_CONFIG,
40  .handler = handle_jtag_newtap,
41  .help = "declare a new SWD DAP",
42  .usage = "basename dap_type ['-irlen' count] "
43  "['-enable'|'-disable'] "
44  "['-expected_id' number] "
45  "['-ignore-version'] "
46  "['-ignore-bypass'] "
47  "['-ircapture' number] "
48  "['-ir-bypass' number] "
49  "['-mask' number]",
50  },
52 };
53 
55  {
56  .name = "swd",
57  .mode = COMMAND_ANY,
58  .help = "SWD command group",
59  .usage = "",
61  },
63 };
64 
66  {
67  .name = "newtap",
68  .mode = COMMAND_CONFIG,
69  .handler = handle_jtag_newtap,
70  .help = "Create a new TAP instance named basename.tap_type, "
71  "and appends it to the scan chain.",
72  .usage = "basename tap_type '-irlen' count "
73  "['-enable'|'-disable'] "
74  "['-expected_id' number] "
75  "['-ignore-version'] "
76  "['-ignore-bypass'] "
77  "['-ircapture' number] "
78  "['-ir-bypass' number] "
79  "['-mask' number]",
80  },
81  {
82  .name = "init",
83  .mode = COMMAND_ANY,
84  .handler = hl_transport_jtag_command,
85  .usage = ""
86  },
87  {
88  .name = "arp_init",
89  .mode = COMMAND_ANY,
90  .handler = hl_transport_jtag_command,
91  .usage = ""
92  },
93  {
94  .name = "arp_init-reset",
95  .mode = COMMAND_ANY,
96  .handler = hl_transport_reset_command,
97  .usage = ""
98  },
99  {
100  .name = "tapisenabled",
101  .mode = COMMAND_EXEC,
102  .handler = handle_jtag_tap_enabler,
103  .help = "Returns a Tcl boolean (0/1) indicating whether "
104  "the TAP is enabled (1) or not (0).",
105  .usage = "tap_name",
106  },
107  {
108  .name = "tapenable",
109  .mode = COMMAND_EXEC,
110  .handler = handle_jtag_tap_enabler,
111  .help = "Try to enable the specified TAP using the "
112  "'tap-enable' TAP event.",
113  .usage = "tap_name",
114  },
115  {
116  .name = "tapdisable",
117  .mode = COMMAND_EXEC,
118  .handler = hl_transport_jtag_command,
119  .usage = "",
120  },
121  {
122  .name = "configure",
123  .mode = COMMAND_EXEC,
124  .handler = hl_transport_jtag_command,
125  .usage = "",
126  },
127  {
128  .name = "cget",
129  .mode = COMMAND_EXEC,
130  .handler = handle_jtag_configure,
131  .usage = "",
132  },
133  {
134  .name = "names",
135  .mode = COMMAND_ANY,
136  .handler = hl_transport_jtag_command,
137  .usage = "",
138  },
139 
141 };
142 
144  {
145  .name = "jtag",
146  .mode = COMMAND_ANY,
147  .help = "perform jtag tap actions",
148  .usage = "",
150  },
151  {
152  .name = "jtag_ntrst_delay",
153  .mode = COMMAND_ANY,
154  .handler = hl_transport_jtag_command,
155  .usage = "",
156  },
158 };
159 
160 
161 static int hl_transport_init(struct command_context *cmd_ctx)
162 {
163  LOG_DEBUG("hl_transport_init");
164  struct target *t = get_current_target(cmd_ctx);
165  struct transport *transport;
166  enum hl_transports tr;
167 
168  if (!t) {
169  LOG_ERROR("no current target");
170  return ERROR_FAIL;
171  }
172 
174 
175  if (!transport) {
176  LOG_ERROR("no transport selected");
177  return ERROR_FAIL;
178  }
179 
180  LOG_DEBUG("current transport %s", transport->name);
181 
182  /* get selected transport as enum */
184 
185  if (strcmp(transport->name, "hla_swd") == 0)
186  tr = HL_TRANSPORT_SWD;
187  else if (strcmp(transport->name, "hla_jtag") == 0)
188  tr = HL_TRANSPORT_JTAG;
189 
190  int retval = hl_interface_open(tr);
191 
192  if (retval != ERROR_OK)
193  return retval;
194 
195  return hl_interface_init_target(t);
196 }
197 
198 static int hl_jtag_transport_select(struct command_context *cmd_ctx)
199 {
200  LOG_DEBUG("hl_jtag_transport_select");
201 
202  /* NOTE: interface init must already have been done.
203  * That works with only C code ... no Tcl glue required.
204  */
205 
207 }
208 
209 static int hl_swd_transport_select(struct command_context *cmd_ctx)
210 {
211  LOG_DEBUG("hl_swd_transport_select");
213 }
214 
215 static struct transport hl_swd_transport = {
216  .name = "hla_swd",
217  .select = hl_swd_transport_select,
218  .init = hl_transport_init,
219  .override_target = hl_interface_override_target,
220 };
221 
222 static struct transport hl_jtag_transport = {
223  .name = "hla_jtag",
224  .select = hl_jtag_transport_select,
225  .init = hl_transport_init,
226  .override_target = hl_interface_override_target,
227 };
228 
229 const char *hl_transports[] = { "hla_swd", "hla_jtag", NULL };
230 
231 static void hl_constructor(void) __attribute__ ((constructor));
232 static void hl_constructor(void)
233 {
236 }
237 
239 {
240  struct transport *t;
241  t = get_current_transport();
242  return t == &hl_swd_transport || t == &hl_jtag_transport;
243 }
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
static int register_commands(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds)
Register one or more commands in the specified context, as children of parent (or top-level commends,...
Definition: command.h:274
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
int hl_interface_init_target(struct target *t)
Definition: hla_interface.c:63
int hl_interface_open(enum hl_transports tr)
Definition: hla_interface.c:40
int hl_interface_override_target(const char **targetname)
int hl_interface_init_reset(void)
static int hl_swd_transport_select(struct command_context *cmd_ctx)
static const struct command_registration hl_swd_transport_command_handlers[]
Definition: hla_transport.c:54
COMMAND_HANDLER(hl_transport_jtag_command)
Definition: hla_transport.c:24
static struct transport hl_swd_transport
static const struct command_registration hl_transport_jtag_subcommand_handlers[]
Definition: hla_transport.c:65
static struct transport hl_jtag_transport
static void hl_constructor(void)
static int hl_transport_init(struct command_context *cmd_ctx)
static int hl_jtag_transport_select(struct command_context *cmd_ctx)
static const struct command_registration hl_jtag_transport_command_handlers[]
bool transport_is_hla(void)
static const struct command_registration hl_swd_transport_subcommand_handlers[]
Definition: hla_transport.c:36
hl_transports
Definition: hla_transport.h:14
@ HL_TRANSPORT_SWD
Definition: hla_transport.h:16
@ HL_TRANSPORT_JTAG
Definition: hla_transport.h:17
@ HL_TRANSPORT_UNKNOWN
Definition: hla_transport.h:15
#define ERROR_FAIL
Definition: log.h:170
#define LOG_ERROR(expr ...)
Definition: log.h:132
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:164
struct qn908x_flash_bank __attribute__
Definition: armv8.c:1016
const char * name
Definition: command.h:235
Definition: target.h:116
Wrapper for transport lifecycle operations.
Definition: transport.h:35
const char * name
Each transport has a unique name, used to select it from among the alternatives.
Definition: transport.h:41
struct target * get_current_target(struct command_context *cmd_ctx)
Definition: target.c:458
struct transport * get_current_transport(void)
Returns the transport currently being used by this debug or programming session.
Definition: transport.c:157
int transport_register(struct transport *new_transport)
Registers a transport.
Definition: transport.c:129
#define NULL
Definition: usb.h:16