1 /***************************************************************************
2 * Copyright (C) 2011 by Mathias Kuester *
3 * Mathias Kuester <kesmtp@freenet.de> *
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, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
25 /* project specific includes */
26 #include <jtag/interface.h>
28 #include <transport/transport.h>
29 #include <helper/time_support.h>
30 #include <target/target.h>
31 #include <jtag/stlink/stlink_tcl.h>
32 #include <jtag/stlink/stlink_interface.h>
34 COMMAND_HANDLER(stlink_transport_jtag_command
)
36 LOG_DEBUG("stlink_transport_jtag_command");
41 static const struct command_registration
42 stlink_transport_stlink_subcommand_handlers
[] = {
45 .mode
= COMMAND_CONFIG
,
46 .jim_handler
= jim_stlink_newtap
,
47 .help
= "Create a new TAP instance named basename.tap_type, "
48 "and appends it to the scan chain.",
49 .usage
= "basename tap_type '-irlen' count "
50 "['-expected_id' number] ",
53 COMMAND_REGISTRATION_DONE
56 static const struct command_registration
57 stlink_transport_jtag_subcommand_handlers
[] = {
61 .handler
= stlink_transport_jtag_command
,
66 .handler
= stlink_transport_jtag_command
,
69 .name
= "arp_init-reset",
71 .handler
= stlink_transport_jtag_command
,
74 .name
= "tapisenabled",
76 .jim_handler
= jim_jtag_tap_enabler
,
81 .jim_handler
= jim_jtag_tap_enabler
,
86 .handler
= stlink_transport_jtag_command
,
91 .handler
= stlink_transport_jtag_command
,
96 .jim_handler
= jim_jtag_configure
,
101 .handler
= stlink_transport_jtag_command
,
104 COMMAND_REGISTRATION_DONE
107 static const struct command_registration stlink_transport_command_handlers
[] = {
112 .help
= "perform stlink actions",
113 .chain
= stlink_transport_stlink_subcommand_handlers
,
118 .chain
= stlink_transport_jtag_subcommand_handlers
,
120 COMMAND_REGISTRATION_DONE
123 static int stlink_transport_register_commands(struct command_context
*cmd_ctx
)
125 return register_commands(cmd_ctx
, NULL
,
126 stlink_transport_command_handlers
);
129 static int stlink_transport_init(struct command_context
*cmd_ctx
)
131 LOG_DEBUG("stlink_transport_init");
132 struct target
*t
= get_current_target(cmd_ctx
);
135 LOG_ERROR("stlink_transport_init: no current target");
140 stlink_interface_open();
142 return stlink_interface_init_target(t
);
145 static int stlink_transport_select(struct command_context
*ctx
)
147 LOG_DEBUG("stlink_transport_select");
151 /* NOTE: interface init must already have been done.
152 * That works with only C code ... no Tcl glue required.
155 retval
= stlink_transport_register_commands(ctx
);
157 if (retval
!= ERROR_OK
)
163 static struct transport stlink_transport
= {
165 .select
= stlink_transport_select
,
166 .init
= stlink_transport_init
,
169 const char *stlink_transports
[] = { "stlink", NULL
};
171 static void stlink_constructor(void) __attribute__ ((constructor
));
172 static void stlink_constructor(void)
174 transport_register(&stlink_transport
);
177 bool transport_is_stlink(void)
179 return get_current_transport() == &stlink_transport
;