1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /***************************************************************************
4 * Copyright (C) 2005 by Dominic Rath *
5 * Dominic.Rath@gmx.de *
7 * Copyright (C) 2007,2008 Øyvind Harboe *
8 * oyvind.harboe@zylin.com *
10 * Copyright (C) 2009 Zachary T Welch *
11 * zw@superlucidity.net *
12 ***************************************************************************/
14 #ifndef OPENOCD_JTAG_COMMANDS_H
15 #define OPENOCD_JTAG_COMMANDS_H
18 * The inferred type of a scan_command_s structure, indicating whether
19 * the command has the host scan in from the device, the host scan out
20 * to the device, or both.
23 /** From device to host, */
25 /** From host to device, */
27 /** Full-duplex scan. */
32 * The scan_command provide a means of encapsulating a set of scan_field_s
33 * structures that should be scanned in/out to the device.
36 /** instruction/not data scan */
38 /** number of fields in *fields array */
40 /** pointer to an array of data scan fields */
41 struct scan_field *fields;
42 /** state in which JTAG commands should finish */
43 tap_state_t end_state;
46 struct statemove_command {
47 /** state in which JTAG commands should finish */
48 tap_state_t end_state;
51 struct pathmove_command {
52 /** number of states in *path */
54 /** states that have to be passed */
58 struct runtest_command {
59 /** number of cycles to spend in Run-Test/Idle state */
61 /** state in which JTAG commands should finish */
62 tap_state_t end_state;
66 struct stableclocks_command {
67 /** number of clock cycles that should be sent */
72 struct reset_command {
73 /** Set TRST output: 0 = deassert, 1 = assert, -1 = no change */
75 /** Set SRST output: 0 = deassert, 1 = assert, -1 = no change */
79 struct end_state_command {
80 /** state in which JTAG commands should finish */
81 tap_state_t end_state;
84 struct sleep_command {
85 /** number of microseconds to sleep */
90 * Encapsulates a series of bits to be clocked out, affecting state
91 * and mode of the interface.
93 * In JTAG mode these are clocked out on TMS, using TCK. They may be
94 * used for link resets, transitioning between JTAG and SWD modes, or
95 * to implement JTAG state machine transitions (implementing pathmove
96 * or statemove operations).
98 * In SWD mode these are clocked out on SWDIO, using SWCLK, and are
99 * used for link resets and transitioning between SWD and JTAG modes.
102 /** How many bits should be clocked out. */
104 /** The bits to clock out; the LSB is bit 0 of bits[0]. */
109 * Defines a container type that hold a pointer to a JTAG command
110 * structure of any defined type.
112 union jtag_command_container {
113 struct scan_command *scan;
114 struct statemove_command *statemove;
115 struct pathmove_command *pathmove;
116 struct runtest_command *runtest;
117 struct stableclocks_command *stableclocks;
118 struct reset_command *reset;
119 struct end_state_command *end_state;
120 struct sleep_command *sleep;
121 struct tms_command *tms;
125 * The type of the @c jtag_command_container contained by a
126 * @c jtag_command_s structure.
128 enum jtag_command_type {
130 /* JTAG_TLR_RESET's non-minidriver implementation is a
131 * vestige from a statemove cmd. The statemove command
132 * is obsolete and replaced by pathmove.
134 * pathmove does not support reset as one of it's states,
135 * hence the need for an explicit statemove command.
142 JTAG_STABLECLOCKS = 8,
146 struct jtag_command {
147 union jtag_command_container cmd;
148 enum jtag_command_type type;
149 struct jtag_command *next;
152 /** The current queue of jtag_command_s structures. */
153 extern struct jtag_command *jtag_command_queue;
155 void *cmd_queue_alloc(size_t size);
157 void jtag_queue_command(struct jtag_command *cmd);
158 void jtag_command_queue_reset(void);
160 void jtag_scan_field_clone(struct scan_field *dst, const struct scan_field *src);
161 enum scan_type jtag_scan_type(const struct scan_command *cmd);
162 int jtag_scan_size(const struct scan_command *cmd);
163 int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd);
164 int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer);
166 #endif /* OPENOCD_JTAG_COMMANDS_H */