jtag: rewrite jim_jtag_configure() as COMMAND_HANDLER
[openocd.git] / src / target / adi_v5_dapdirect.c
blobd198dacf3913953e6938bef9b7cc378ecd4aab61
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 /*
4 * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
5 * Author(s): Antonio Borneo <borneo.antonio@gmail.com> for STMicroelectronics
6 */
8 /**
9 * @file
10 * Utilities to support in-circuit debuggers that provide APIs to access
11 * directly ARM DAP, hiding the access to the underlining transport used
12 * for the physical connection (either JTAG or SWD).
13 * E.g. STMicroelectronics ST-Link/V2 (from version V2J24) and STLINK-V3.
15 * Single-DAP support only.
17 * For details, see "ARM IHI 0031A"
18 * ARM Debug Interface v5 Architecture Specification
20 * FIXME: in JTAG mode, trst is not managed
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #include <jtag/interface.h>
28 #include <jtag/tcl.h>
29 #include <transport/transport.h>
31 COMMAND_HANDLER(dapdirect_jtag_empty_command)
33 LOG_DEBUG("dapdirect_jtag_empty_command(\"%s\")", CMD_NAME);
35 return ERROR_OK;
38 COMMAND_HANDLER(dapdirect_jtag_reset_command)
40 enum reset_types jtag_reset_config = jtag_get_reset_config();
43 * in case the adapter has not already handled asserting srst
44 * we will attempt it again
46 if (jtag_reset_config & RESET_CNCT_UNDER_SRST) {
47 if (jtag_reset_config & RESET_SRST_NO_GATING) {
48 adapter_assert_reset();
49 return ERROR_OK;
51 LOG_WARNING("\'srst_nogate\' reset_config option is required");
53 adapter_deassert_reset();
54 return ERROR_OK;
57 static const struct command_registration dapdirect_jtag_subcommand_handlers[] = {
59 .name = "newtap",
60 .mode = COMMAND_CONFIG,
61 .handler = handle_jtag_newtap,
62 .help = "declare a new TAP",
63 .usage = "basename tap_type '-irlen' count "
64 "['-enable'|'-disable'] "
65 "['-expected_id' number] "
66 "['-ignore-version'] "
67 "['-ignore-bypass'] "
68 "['-ircapture' number] "
69 "['-ir-bypass' number] "
70 "['-mask' number]",
73 .name = "init",
74 .mode = COMMAND_ANY,
75 .handler = dapdirect_jtag_empty_command,
76 .usage = ""
79 .name = "arp_init",
80 .mode = COMMAND_ANY,
81 .handler = dapdirect_jtag_empty_command,
82 .usage = ""
85 .name = "arp_init-reset",
86 .mode = COMMAND_ANY,
87 .handler = dapdirect_jtag_reset_command,
88 .usage = ""
91 .name = "tapisenabled",
92 .mode = COMMAND_EXEC,
93 .handler = handle_jtag_tap_enabler,
94 .help = "Returns a Tcl boolean (0/1) indicating whether "
95 "the TAP is enabled (1) or not (0).",
96 .usage = "tap_name",
99 .name = "tapenable",
100 .mode = COMMAND_EXEC,
101 .handler = handle_jtag_tap_enabler,
102 .help = "Try to enable the specified TAP using the "
103 "'tap-enable' TAP event.",
104 .usage = "tap_name",
107 .name = "tapdisable",
108 .mode = COMMAND_EXEC,
109 .handler = dapdirect_jtag_empty_command,
110 .usage = "",
113 .name = "configure",
114 .mode = COMMAND_ANY,
115 .handler = dapdirect_jtag_empty_command,
116 .usage = "",
119 .name = "cget",
120 .mode = COMMAND_EXEC,
121 .handler = handle_jtag_configure,
122 .usage = "",
125 .name = "names",
126 .mode = COMMAND_ANY,
127 .handler = dapdirect_jtag_empty_command,
128 .usage = "",
130 COMMAND_REGISTRATION_DONE
133 static const struct command_registration dapdirect_jtag_handlers[] = {
135 .name = "jtag",
136 .mode = COMMAND_ANY,
137 .chain = dapdirect_jtag_subcommand_handlers,
138 .usage = "",
141 .name = "jtag_ntrst_delay",
142 .mode = COMMAND_ANY,
143 .handler = dapdirect_jtag_empty_command,
144 .usage = "",
146 COMMAND_REGISTRATION_DONE
149 static const struct command_registration dapdirect_swd_subcommand_handlers[] = {
151 .name = "newdap",
152 .mode = COMMAND_CONFIG,
153 .handler = handle_jtag_newtap,
154 .help = "declare a new SWD DAP",
155 .usage = "basename dap_type ['-irlen' count] "
156 "['-enable'|'-disable'] "
157 "['-expected_id' number] "
158 "['-ignore-version'] "
159 "['-ignore-bypass'] "
160 "['-ircapture' number] "
161 "['-ir-bypass' number] "
162 "['-mask' number]",
164 COMMAND_REGISTRATION_DONE
167 static const struct command_registration dapdirect_swd_handlers[] = {
169 .name = "swd",
170 .mode = COMMAND_ANY,
171 .help = "SWD command group",
172 .usage = "",
173 .chain = dapdirect_swd_subcommand_handlers,
175 COMMAND_REGISTRATION_DONE
178 static int dapdirect_jtag_select(struct command_context *ctx)
180 LOG_DEBUG("dapdirect_jtag_select()");
182 return register_commands(ctx, NULL, dapdirect_jtag_handlers);
185 static int dapdirect_swd_select(struct command_context *ctx)
187 LOG_DEBUG("dapdirect_swd_select()");
189 return register_commands(ctx, NULL, dapdirect_swd_handlers);
192 static int dapdirect_init(struct command_context *ctx)
194 enum reset_types jtag_reset_config = jtag_get_reset_config();
196 LOG_DEBUG("dapdirect_init()");
198 if (jtag_reset_config & RESET_CNCT_UNDER_SRST) {
199 if (jtag_reset_config & RESET_SRST_NO_GATING)
200 adapter_assert_reset();
201 else
202 LOG_WARNING("\'srst_nogate\' reset_config option is required");
203 } else
204 adapter_deassert_reset();
206 return ERROR_OK;
209 static struct transport dapdirect_jtag_transport = {
210 .name = "dapdirect_jtag",
211 .select = dapdirect_jtag_select,
212 .init = dapdirect_init,
215 static struct transport dapdirect_swd_transport = {
216 .name = "dapdirect_swd",
217 .select = dapdirect_swd_select,
218 .init = dapdirect_init,
221 static void dapdirect_constructor(void) __attribute__((constructor));
222 static void dapdirect_constructor(void)
224 transport_register(&dapdirect_jtag_transport);
225 transport_register(&dapdirect_swd_transport);
229 * Returns true if the current debug session
230 * is using JTAG as its transport.
232 bool transport_is_dapdirect_jtag(void)
234 return get_current_transport() == &dapdirect_jtag_transport;
238 * Returns true if the current debug session
239 * is using SWD as its transport.
241 bool transport_is_dapdirect_swd(void)
243 return get_current_transport() == &dapdirect_swd_transport;