Cortex-M3: DWT cleanup/fixes
[openocd.git] / src / jtag / commands.h
blob5a76a8fb0e7f1a9c4d32ab6e219394565adb6ef8
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, write to the *
23 * Free Software Foundation, Inc., *
24 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 ***************************************************************************/
26 #ifndef JTAG_COMMANDS_H
27 #define JTAG_COMMANDS_H
29 #include "jtag.h"
31 /**
32 * The inferred type of a scan_command_s structure, indicating whether
33 * the command has the host scan in from the device, the host scan out
34 * to the device, or both.
36 enum scan_type {
37 /// From device to host,
38 SCAN_IN = 1,
39 /// From host to device,
40 SCAN_OUT = 2,
41 /// Full-duplex scan.
42 SCAN_IO = 3
45 /**
46 * The scan_command provide a means of encapsulating a set of scan_field_s
47 * structures that should be scanned in/out to the device.
49 typedef struct scan_command_s
51 /// instruction/not data scan
52 bool ir_scan;
53 /// number of fields in *fields array
54 int num_fields;
55 /// pointer to an array of data scan fields
56 scan_field_t* fields;
57 /// state in which JTAG commands should finish
58 tap_state_t end_state;
59 } scan_command_t;
61 typedef struct statemove_command_s
63 /// state in which JTAG commands should finish
64 tap_state_t end_state;
65 } statemove_command_t;
67 typedef struct pathmove_command_s
69 /// number of states in *path
70 int num_states;
71 /// states that have to be passed
72 tap_state_t* path;
73 } pathmove_command_t;
75 typedef struct runtest_command_s
77 /// number of cycles to spend in Run-Test/Idle state
78 int num_cycles;
79 /// state in which JTAG commands should finish
80 tap_state_t end_state;
81 } runtest_command_t;
84 typedef struct stableclocks_command_s
86 /// number of clock cycles that should be sent
87 int num_cycles;
88 } stableclocks_command_t;
91 typedef struct reset_command_s
93 /// Set TRST output: 0 = deassert, 1 = assert, -1 = no change
94 int trst;
95 /// Set SRST output: 0 = deassert, 1 = assert, -1 = no change
96 int srst;
97 } reset_command_t;
99 typedef struct end_state_command_s
101 /// state in which JTAG commands should finish
102 tap_state_t end_state;
103 } end_state_command_t;
105 typedef struct sleep_command_s
107 /// number of microseconds to sleep
108 uint32_t us;
109 } sleep_command_t;
112 * Defines a container type that hold a pointer to a JTAG command
113 * structure of any defined type.
115 typedef union jtag_command_container_u
117 scan_command_t* scan;
118 statemove_command_t* statemove;
119 pathmove_command_t* pathmove;
120 runtest_command_t* runtest;
121 stableclocks_command_t* stableclocks;
122 reset_command_t* reset;
123 end_state_command_t* end_state;
124 sleep_command_t* sleep;
125 } jtag_command_container_t;
128 * The type of the @c jtag_command_container_u contained by a
129 * @c jtag_command_s structure.
131 enum jtag_command_type {
132 JTAG_SCAN = 1,
133 JTAG_STATEMOVE = 2,
134 JTAG_RUNTEST = 3,
135 JTAG_RESET = 4,
136 JTAG_PATHMOVE = 6,
137 JTAG_SLEEP = 7,
138 JTAG_STABLECLOCKS = 8
141 typedef struct jtag_command_s
143 jtag_command_container_t cmd;
144 enum jtag_command_type type;
145 struct jtag_command_s* next;
146 } jtag_command_t;
148 /// The current queue of jtag_command_s structures.
149 extern jtag_command_t* jtag_command_queue;
151 void* cmd_queue_alloc(size_t size);
152 void cmd_queue_free(void);
154 void jtag_queue_command(jtag_command_t *cmd);
155 void jtag_command_queue_reset(void);
157 enum scan_type jtag_scan_type(const scan_command_t* cmd);
158 int jtag_scan_size(const scan_command_t* cmd);
159 int jtag_read_buffer(uint8_t* buffer, const scan_command_t* cmd);
160 int jtag_build_buffer(const scan_command_t* cmd, uint8_t** buffer);
162 #endif // JTAG_COMMANDS_H