flash/nor/at91samd: Use 32-bit register writes for ST-Link compat
[fw/openocd] / src / jtag / commands.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 /***************************************************************************
4  *   Copyright (C) 2005 by Dominic Rath                                    *
5  *   Dominic.Rath@gmx.de                                                   *
6  *                                                                         *
7  *   Copyright (C) 2007,2008 Ã˜yvind Harboe                                 *
8  *   oyvind.harboe@zylin.com                                               *
9  *                                                                         *
10  *   Copyright (C) 2009 Zachary T Welch                                    *
11  *   zw@superlucidity.net                                                  *
12  ***************************************************************************/
13
14 #ifndef OPENOCD_JTAG_COMMANDS_H
15 #define OPENOCD_JTAG_COMMANDS_H
16
17 /**
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.
21  */
22 enum scan_type {
23         /** From device to host, */
24         SCAN_IN = 1,
25         /** From host to device, */
26         SCAN_OUT = 2,
27         /** Full-duplex scan. */
28         SCAN_IO = 3
29 };
30
31 /**
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.
34  */
35 struct scan_command {
36         /** instruction/not data scan */
37         bool ir_scan;
38         /** number of fields in *fields array */
39         int num_fields;
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;
44 };
45
46 struct statemove_command {
47         /** state in which JTAG commands should finish */
48         tap_state_t end_state;
49 };
50
51 struct pathmove_command {
52         /** number of states in *path */
53         int num_states;
54         /** states that have to be passed */
55         tap_state_t *path;
56 };
57
58 struct runtest_command {
59         /** number of cycles to spend in Run-Test/Idle state */
60         int num_cycles;
61         /** state in which JTAG commands should finish */
62         tap_state_t end_state;
63 };
64
65
66 struct stableclocks_command {
67         /** number of clock cycles that should be sent */
68         int num_cycles;
69 };
70
71
72 struct reset_command {
73         /** Set TRST output: 0 = deassert, 1 = assert, -1 = no change */
74         int trst;
75         /** Set SRST output: 0 = deassert, 1 = assert, -1 = no change */
76         int srst;
77 };
78
79 struct end_state_command {
80         /** state in which JTAG commands should finish */
81         tap_state_t end_state;
82 };
83
84 struct sleep_command {
85         /** number of microseconds to sleep */
86         uint32_t us;
87 };
88
89 /**
90  * Encapsulates a series of bits to be clocked out, affecting state
91  * and mode of the interface.
92  *
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).
97  *
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.
100  */
101 struct tms_command {
102         /** How many bits should be clocked out. */
103         unsigned num_bits;
104         /** The bits to clock out; the LSB is bit 0 of bits[0]. */
105         const uint8_t *bits;
106 };
107
108 /**
109  * Defines a container type that hold a pointer to a JTAG command
110  * structure of any defined type.
111  */
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;
122 };
123
124 /**
125  * The type of the @c jtag_command_container contained by a
126  * @c jtag_command_s structure.
127  */
128 enum jtag_command_type {
129         JTAG_SCAN         = 1,
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.
133          *
134          * pathmove does not support reset as one of it's states,
135          * hence the need for an explicit statemove command.
136          */
137         JTAG_TLR_RESET    = 2,
138         JTAG_RUNTEST      = 3,
139         JTAG_RESET        = 4,
140         JTAG_PATHMOVE     = 6,
141         JTAG_SLEEP        = 7,
142         JTAG_STABLECLOCKS = 8,
143         JTAG_TMS          = 9,
144 };
145
146 struct jtag_command {
147         union jtag_command_container cmd;
148         enum jtag_command_type type;
149         struct jtag_command *next;
150 };
151
152 /** The current queue of jtag_command_s structures. */
153 extern struct jtag_command *jtag_command_queue;
154
155 void *cmd_queue_alloc(size_t size);
156
157 void jtag_queue_command(struct jtag_command *cmd);
158 void jtag_command_queue_reset(void);
159
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);
165
166 #endif /* OPENOCD_JTAG_COMMANDS_H */