]> git.sur5r.net Git - openocd/blob - src/jtag/commands.h
jtag: make cmd_queue_scan_field_clone public
[openocd] / src / jtag / commands.h
1 /***************************************************************************
2  *   Copyright (C) 2005 by Dominic Rath                                    *
3  *   Dominic.Rath@gmx.de                                                   *
4  *                                                                         *
5  *   Copyright (C) 2007,2008 Ã˜yvind Harboe                                 *
6  *   oyvind.harboe@zylin.com                                               *
7  *                                                                         *
8  *   Copyright (C) 2009 Zachary T Welch                                    *
9  *   zw@superlucidity.net                                                  *
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  *   This program is distributed in the hope that it will be useful,       *
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
19  *   GNU General Public License for more details.                          *
20  *                                                                         *
21  *   You should have received a copy of the GNU General Public License     *
22  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
23  ***************************************************************************/
24
25 #ifndef OPENOCD_JTAG_COMMANDS_H
26 #define OPENOCD_JTAG_COMMANDS_H
27
28 /**
29  * The inferred type of a scan_command_s structure, indicating whether
30  * the command has the host scan in from the device, the host scan out
31  * to the device, or both.
32  */
33 enum scan_type {
34         /** From device to host, */
35         SCAN_IN = 1,
36         /** From host to device, */
37         SCAN_OUT = 2,
38         /** Full-duplex scan. */
39         SCAN_IO = 3
40 };
41
42 /**
43  * The scan_command provide a means of encapsulating a set of scan_field_s
44  * structures that should be scanned in/out to the device.
45  */
46 struct scan_command {
47         /** instruction/not data scan */
48         bool ir_scan;
49         /** number of fields in *fields array */
50         int num_fields;
51         /** pointer to an array of data scan fields */
52         struct scan_field *fields;
53         /** state in which JTAG commands should finish */
54         tap_state_t end_state;
55 };
56
57 struct statemove_command {
58         /** state in which JTAG commands should finish */
59         tap_state_t end_state;
60 };
61
62 struct pathmove_command {
63         /** number of states in *path */
64         int num_states;
65         /** states that have to be passed */
66         tap_state_t *path;
67 };
68
69 struct runtest_command {
70         /** number of cycles to spend in Run-Test/Idle state */
71         int num_cycles;
72         /** state in which JTAG commands should finish */
73         tap_state_t end_state;
74 };
75
76
77 struct stableclocks_command {
78         /** number of clock cycles that should be sent */
79         int num_cycles;
80 };
81
82
83 struct reset_command {
84         /** Set TRST output: 0 = deassert, 1 = assert, -1 = no change */
85         int trst;
86         /** Set SRST output: 0 = deassert, 1 = assert, -1 = no change */
87         int srst;
88 };
89
90 struct end_state_command {
91         /** state in which JTAG commands should finish */
92         tap_state_t end_state;
93 };
94
95 struct sleep_command {
96         /** number of microseconds to sleep */
97         uint32_t us;
98 };
99
100 /**
101  * Encapsulates a series of bits to be clocked out, affecting state
102  * and mode of the interface.
103  *
104  * In JTAG mode these are clocked out on TMS, using TCK.  They may be
105  * used for link resets, transitioning between JTAG and SWD modes, or
106  * to implement JTAG state machine transitions (implementing pathmove
107  * or statemove operations).
108  *
109  * In SWD mode these are clocked out on SWDIO, using SWCLK, and are
110  * used for link resets and transitioning between SWD and JTAG modes.
111  */
112 struct tms_command {
113         /** How many bits should be clocked out. */
114         unsigned num_bits;
115         /** The bits to clock out; the LSB is bit 0 of bits[0]. */
116         const uint8_t *bits;
117 };
118
119 /**
120  * Defines a container type that hold a pointer to a JTAG command
121  * structure of any defined type.
122  */
123 union jtag_command_container {
124         struct scan_command *scan;
125         struct statemove_command *statemove;
126         struct pathmove_command *pathmove;
127         struct runtest_command *runtest;
128         struct stableclocks_command *stableclocks;
129         struct reset_command *reset;
130         struct end_state_command *end_state;
131         struct sleep_command *sleep;
132         struct tms_command *tms;
133 };
134
135 /**
136  * The type of the @c jtag_command_container contained by a
137  * @c jtag_command_s structure.
138  */
139 enum jtag_command_type {
140         JTAG_SCAN         = 1,
141         /* JTAG_TLR_RESET's non-minidriver implementation is a
142          * vestige from a statemove cmd. The statemove command
143          * is obsolete and replaced by pathmove.
144          *
145          * pathmove does not support reset as one of it's states,
146          * hence the need for an explicit statemove command.
147          */
148         JTAG_TLR_RESET    = 2,
149         JTAG_RUNTEST      = 3,
150         JTAG_RESET        = 4,
151         JTAG_PATHMOVE     = 6,
152         JTAG_SLEEP        = 7,
153         JTAG_STABLECLOCKS = 8,
154         JTAG_TMS          = 9,
155 };
156
157 struct jtag_command {
158         union jtag_command_container cmd;
159         enum jtag_command_type type;
160         struct jtag_command *next;
161 };
162
163 /** The current queue of jtag_command_s structures. */
164 extern struct jtag_command *jtag_command_queue;
165
166 void *cmd_queue_alloc(size_t size);
167
168 void jtag_queue_command(struct jtag_command *cmd);
169 void jtag_command_queue_reset(void);
170
171 void jtag_scan_field_clone(struct scan_field *dst, const struct scan_field *src);
172 enum scan_type jtag_scan_type(const struct scan_command *cmd);
173 int jtag_scan_size(const struct scan_command *cmd);
174 int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd);
175 int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer);
176
177 #endif /* OPENOCD_JTAG_COMMANDS_H */