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_tcl.h>
22 #include <jtag/hla/hla_transport.h>
23 #include <jtag/hla/hla_interface.h>
24 
25 COMMAND_HANDLER(hl_transport_jtag_command)
26 {
27  LOG_DEBUG("hl_transport_jtag_command");
28 
29  return ERROR_OK;
30 }
31 
32 COMMAND_HANDLER(hl_transport_reset_command)
33 {
34  return hl_interface_init_reset();
35 }
36 
38  {
39  .name = "newdap",
40  .mode = COMMAND_CONFIG,
41  .jim_handler = jim_hl_newtap,
42  .help = "declare a new SWD DAP",
43  },
45 };
46 
48  {
49  .name = "swd",
50  .mode = COMMAND_ANY,
51  .help = "SWD command group",
52  .usage = "",
54  },
56 };
57 
59  {
60  .name = "newtap",
61  .mode = COMMAND_CONFIG,
62  .jim_handler = jim_hl_newtap,
63  .help = "Create a new TAP instance named basename.tap_type, "
64  "and appends it to the scan chain.",
65  .usage = "basename tap_type '-irlen' count "
66  "['-expected_id' number]",
67  },
68  {
69  .name = "init",
70  .mode = COMMAND_ANY,
71  .handler = hl_transport_jtag_command,
72  .usage = ""
73  },
74  {
75  .name = "arp_init",
76  .mode = COMMAND_ANY,
77  .handler = hl_transport_jtag_command,
78  .usage = ""
79  },
80  {
81  .name = "arp_init-reset",
82  .mode = COMMAND_ANY,
83  .handler = hl_transport_reset_command,
84  .usage = ""
85  },
86  {
87  .name = "tapisenabled",
88  .mode = COMMAND_EXEC,
89  .jim_handler = jim_jtag_tap_enabler,
90  },
91  {
92  .name = "tapenable",
93  .mode = COMMAND_EXEC,
94  .jim_handler = jim_jtag_tap_enabler,
95  },
96  {
97  .name = "tapdisable",
98  .mode = COMMAND_EXEC,
99  .handler = hl_transport_jtag_command,
100  .usage = "",
101  },
102  {
103  .name = "configure",
104  .mode = COMMAND_EXEC,
105  .handler = hl_transport_jtag_command,
106  .usage = "",
107  },
108  {
109  .name = "cget",
110  .mode = COMMAND_EXEC,
111  .jim_handler = jim_jtag_configure,
112  },
113  {
114  .name = "names",
115  .mode = COMMAND_ANY,
116  .handler = hl_transport_jtag_command,
117  .usage = "",
118  },
119 
121 };
122 
124  {
125  .name = "jtag",
126  .mode = COMMAND_ANY,
127  .help = "perform jtag tap actions",
128  .usage = "",
130  },
131  {
132  .name = "jtag_ntrst_delay",
133  .mode = COMMAND_ANY,
134  .handler = hl_transport_jtag_command,
135  .usage = "",
136  },
138 };
139 
140 
141 static int hl_transport_init(struct command_context *cmd_ctx)
142 {
143  LOG_DEBUG("hl_transport_init");
144  struct target *t = get_current_target(cmd_ctx);
145  struct transport *transport;
146  enum hl_transports tr;
147 
148  if (!t) {
149  LOG_ERROR("no current target");
150  return ERROR_FAIL;
151  }
152 
154 
155  if (!transport) {
156  LOG_ERROR("no transport selected");
157  return ERROR_FAIL;
158  }
159 
160  LOG_DEBUG("current transport %s", transport->name);
161 
162  /* get selected transport as enum */
164 
165  if (strcmp(transport->name, "hla_swd") == 0)
166  tr = HL_TRANSPORT_SWD;
167  else if (strcmp(transport->name, "hla_jtag") == 0)
168  tr = HL_TRANSPORT_JTAG;
169 
170  int retval = hl_interface_open(tr);
171 
172  if (retval != ERROR_OK)
173  return retval;
174 
175  return hl_interface_init_target(t);
176 }
177 
178 static int hl_jtag_transport_select(struct command_context *cmd_ctx)
179 {
180  LOG_DEBUG("hl_jtag_transport_select");
181 
182  /* NOTE: interface init must already have been done.
183  * That works with only C code ... no Tcl glue required.
184  */
185 
187 }
188 
189 static int hl_swd_transport_select(struct command_context *cmd_ctx)
190 {
191  LOG_DEBUG("hl_swd_transport_select");
193 }
194 
195 static struct transport hl_swd_transport = {
196  .name = "hla_swd",
197  .select = hl_swd_transport_select,
198  .init = hl_transport_init,
199  .override_target = hl_interface_override_target,
200 };
201 
202 static struct transport hl_jtag_transport = {
203  .name = "hla_jtag",
204  .select = hl_jtag_transport_select,
205  .init = hl_transport_init,
206  .override_target = hl_interface_override_target,
207 };
208 
209 const char *hl_transports[] = { "hla_swd", "hla_jtag", NULL };
210 
211 static void hl_constructor(void) __attribute__ ((constructor));
212 static void hl_constructor(void)
213 {
216 }
217 
219 {
220  struct transport *t;
221  t = get_current_transport();
222  return t == &hl_swd_transport || t == &hl_jtag_transport;
223 }
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
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:268
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
struct esp_usb_jtag __attribute__
Definition: armv8.c:804
int hl_interface_init_target(struct target *t)
Definition: hla_interface.c:65
int hl_interface_open(enum hl_transports tr)
Definition: hla_interface.c:42
int hl_interface_override_target(const char **targetname)
int hl_interface_init_reset(void)
int jim_hl_newtap(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: hla_tcl.c:138
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:47
COMMAND_HANDLER(hl_transport_jtag_command)
Definition: hla_transport.c:25
static struct transport hl_swd_transport
static const struct command_registration hl_transport_jtag_subcommand_handlers[]
Definition: hla_transport.c:58
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:37
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
int jim_jtag_tap_enabler(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: jtag/tcl.c:753
int jim_jtag_configure(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: jtag/tcl.c:791
#define ERROR_FAIL
Definition: log.h:161
#define LOG_ERROR(expr ...)
Definition: log.h:123
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:155
const char * name
Definition: command.h:229
Definition: target.h:120
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:536
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