helper/command: register full-name commands in jim
[openocd.git] / src / target / adi_v5_dapdirect.c
blobc0deee165f5fae4a8f39c9cc962010d724a6e4f8
1 /*
2 * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
3 * Author(s): Antonio Borneo <borneo.antonio@gmail.com> for STMicroelectronics
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 /**
20 * @file
21 * Utilities to support in-circuit debuggers that provide APIs to access
22 * directly ARM DAP, hiding the access to the underlining transport used
23 * for the physical connection (either JTAG or SWD).
24 * E.g. STMicroelectronics ST-Link/V2 (from version V2J24) and STLINK-V3.
26 * Single-DAP support only.
28 * For details, see "ARM IHI 0031A"
29 * ARM Debug Interface v5 Architecture Specification
31 * FIXME: in JTAG mode, trst is not managed
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
38 #include <jtag/interface.h>
39 #include <jtag/tcl.h>
40 #include <transport/transport.h>
42 COMMAND_HANDLER(dapdirect_jtag_empty_command)
44 LOG_DEBUG("dapdirect_jtag_empty_command(\"%s\")", CMD_NAME);
46 return ERROR_OK;
49 COMMAND_HANDLER(dapdirect_jtag_reset_command)
51 enum reset_types jtag_reset_config = jtag_get_reset_config();
54 * in case the adapter has not already handled asserting srst
55 * we will attempt it again
57 if (jtag_reset_config & RESET_CNCT_UNDER_SRST) {
58 if (jtag_reset_config & RESET_SRST_NO_GATING) {
59 adapter_assert_reset();
60 return ERROR_OK;
62 LOG_WARNING("\'srst_nogate\' reset_config option is required");
64 adapter_deassert_reset();
65 return ERROR_OK;
68 static const struct command_registration dapdirect_jtag_subcommand_handlers[] = {
70 .name = "newtap",
71 .mode = COMMAND_CONFIG,
72 .jim_handler = jim_jtag_newtap,
73 .help = "declare a new TAP"
76 .name = "init",
77 .mode = COMMAND_ANY,
78 .handler = dapdirect_jtag_empty_command,
79 .usage = ""
82 .name = "arp_init",
83 .mode = COMMAND_ANY,
84 .handler = dapdirect_jtag_empty_command,
85 .usage = ""
88 .name = "arp_init-reset",
89 .mode = COMMAND_ANY,
90 .handler = dapdirect_jtag_reset_command,
91 .usage = ""
94 .name = "tapisenabled",
95 .mode = COMMAND_EXEC,
96 .jim_handler = jim_jtag_tap_enabler,
99 .name = "tapenable",
100 .mode = COMMAND_EXEC,
101 .jim_handler = jim_jtag_tap_enabler,
104 .name = "tapdisable",
105 .mode = COMMAND_EXEC,
106 .handler = dapdirect_jtag_empty_command,
107 .usage = "",
110 .name = "configure",
111 .mode = COMMAND_ANY,
112 .handler = dapdirect_jtag_empty_command,
113 .usage = "",
116 .name = "cget",
117 .mode = COMMAND_EXEC,
118 .jim_handler = jim_jtag_configure,
121 .name = "names",
122 .mode = COMMAND_ANY,
123 .handler = dapdirect_jtag_empty_command,
124 .usage = "",
126 COMMAND_REGISTRATION_DONE
129 static const struct command_registration dapdirect_jtag_handlers[] = {
131 .name = "jtag",
132 .mode = COMMAND_ANY,
133 .chain = dapdirect_jtag_subcommand_handlers,
134 .usage = "",
137 .name = "jtag_ntrst_delay",
138 .mode = COMMAND_ANY,
139 .handler = dapdirect_jtag_empty_command,
140 .usage = "",
142 COMMAND_REGISTRATION_DONE
145 static const struct command_registration dapdirect_swd_subcommand_handlers[] = {
147 .name = "newdap",
148 .mode = COMMAND_CONFIG,
149 .jim_handler = jim_jtag_newtap,
150 .help = "declare a new SWD DAP",
152 COMMAND_REGISTRATION_DONE
155 static const struct command_registration dapdirect_swd_handlers[] = {
157 .name = "swd",
158 .mode = COMMAND_ANY,
159 .help = "SWD command group",
160 .usage = "",
161 .chain = dapdirect_swd_subcommand_handlers,
163 COMMAND_REGISTRATION_DONE
166 static int dapdirect_jtag_select(struct command_context *ctx)
168 LOG_DEBUG("dapdirect_jtag_select()");
170 return register_commands(ctx, NULL, dapdirect_jtag_handlers);
173 static int dapdirect_swd_select(struct command_context *ctx)
175 LOG_DEBUG("dapdirect_swd_select()");
177 return register_commands(ctx, NULL, dapdirect_swd_handlers);
180 static int dapdirect_init(struct command_context *ctx)
182 enum reset_types jtag_reset_config = jtag_get_reset_config();
184 LOG_DEBUG("dapdirect_init()");
186 if (jtag_reset_config & RESET_CNCT_UNDER_SRST) {
187 if (jtag_reset_config & RESET_SRST_NO_GATING)
188 adapter_assert_reset();
189 else
190 LOG_WARNING("\'srst_nogate\' reset_config option is required");
191 } else
192 adapter_deassert_reset();
194 return ERROR_OK;
197 static struct transport dapdirect_jtag_transport = {
198 .name = "dapdirect_jtag",
199 .select = dapdirect_jtag_select,
200 .init = dapdirect_init,
203 static struct transport dapdirect_swd_transport = {
204 .name = "dapdirect_swd",
205 .select = dapdirect_swd_select,
206 .init = dapdirect_init,
209 static void dapdirect_constructor(void) __attribute__((constructor));
210 static void dapdirect_constructor(void)
212 transport_register(&dapdirect_jtag_transport);
213 transport_register(&dapdirect_swd_transport);
217 * Returns true if the current debug session
218 * is using JTAG as its transport.
220 bool transport_is_dapdirect_jtag(void)
222 return get_current_transport() == &dapdirect_jtag_transport;
226 * Returns true if the current debug session
227 * is using SWD as its transport.
229 bool transport_is_dapdirect_swd(void)
231 return get_current_transport() == &dapdirect_swd_transport;