Debian Codegraph @

src/jtag2_defs.h

raw symbols SCIP
1 /*
2 * avarice - The "avarice" program.
3 * Copyright (C) 2005 Joerg Wunsch
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License Version 2
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
17 *
18 * JTAG ICE mkII definitions, taken from Appnote AVR067.
19 *
20 * $Id: jtag2_defs.h 306 2012-11-05 13:18:17Z joerg_wunsch $
21 */
22
23 /*
24 * Communication with the JTAG ICE works in frames.
25 *
26 * Frame format:
27 *
28 * +---------------------------------------------------------------+
29 * | 0 | 1 . 2 | 3 . 4 . 5 . 6 | 7 | ... | N-1 . N |
30 * | | | | | | |
31 * | start | LSB MSB | LSB ....... MSB | token | msg | LSB MSB |
32 * | 0x1B | sequence# | message size | 0x0E | | CRC16 |
33 * +---------------------------------------------------------------+
34 *
35 * Each request message will be returned by a response with a matching
36 * sequence #. Sequence # 0xffff is reserved for asynchronous event
37 * notifications that will be sent by the ICE without a request
38 * message (e.g. when the target hit a breakpoint).
39 *
40 * The message size excludes the framing overhead (10 bytes).
41 *
42 * The first byte of the message is always the request or response
43 * code, which is roughly classified as:
44 *
45 * . Messages (commands) use 0x00 through 0x3f. (The documentation
46 * claims that messages start at 0x01, but actually CMND_SIGN_OFF is
47 * 0x00.)
48 * . Internal commands use 0x40 through 0x7f (not documented).
49 * . Success responses use 0x80 through 0x9f.
50 * . Failure responses use 0xa0 through 0xbf.
51 * . Events use 0xe0 through 0xff.
52 */
53 #define MESSAGE_START 0x1b
54 #define TOKEN 0x0e
55
56 /*
57 * Max message size we are willing to accept. Prevents us from trying
58 * to allocate too much VM in case we received a nonsensical packet
59 * length. We have to allocate the buffer as soon as we've got the
60 * length information (and thus have to trust that information by that
61 * time at first), as the final CRC check can only be done once the
62 * entire packet came it.
63 */
64 #define MAX_MESSAGE 100000
65
66 /* ICE command codes */
67 #define CMND_CHIP_ERASE 0x13
68 #define CMND_CLEAR_EVENTS 0x22
69 #define CMND_CLR_BREAK 0x1A
70 #define CMND_ENTER_PROGMODE 0x14
71 #define CMND_ERASEPAGE_SPM 0x0D
72 #define CMND_FORCED_STOP 0x0A
73 #define CMND_GET_BREAK 0x12
74 #define CMND_GET_PARAMETER 0x03
75 #define CMND_GET_SIGN_ON 0x01
76 #define CMND_GET_SYNC 0x0f
77 #define CMND_GO 0x08
78 #define CMND_LEAVE_PROGMODE 0x15
79 #define CMND_READ_MEMORY 0x05
80 #define CMND_READ_PC 0x07
81 #define CMND_RESET 0x0B
82 #define CMND_RESTORE_TARGET 0x23
83 #define CMND_RUN_TO_ADDR 0x1C
84 #define CMND_SELFTEST 0x10
85 #define CMND_SET_BREAK 0x11
86 #define CMND_SET_DEVICE_DESCRIPTOR 0x0C
87 #define CMND_SET_N_PARAMETERS 0x16
88 #define CMND_SET_PARAMETER 0x02
89 #define CMND_SIGN_OFF 0x00
90 #define CMND_SINGLE_STEP 0x09
91 #define CMND_SPI_CMD 0x1D
92 #define CMND_WRITE_MEMORY 0x04
93 #define CMND_WRITE_PC 0x06
94 #define CMND_XMEGA_ERASE 0x34
95
96 /* ICE responses */
97 #define RSP_DEBUGWIRE_SYNC_FAILED 0xAC
98 #define RSP_FAILED 0xA0
99 #define RSP_GET_BREAK 0x83
100 #define RSP_ILLEGAL_BREAKPOINT 0xA8
101 #define RSP_ILLEGAL_COMMAND 0xAA
102 #define RSP_ILLEGAL_EMULATOR_MODE 0xA4
103 #define RSP_ILLEGAL_JTAG_ID 0xA9
104 #define RSP_ILLEGAL_MCU_STATE 0xA5
105 #define RSP_ILLEGAL_MEMORY_TYPE 0xA2
106 #define RSP_ILLEGAL_MEMORY_RANGE 0xA3
107 #define RSP_ILLEGAL_PARAMETER 0xA1
108 #define RSP_ILLEGAL_POWER_STATE 0xAD
109 #define RSP_ILLEGAL_VALUE 0xA6
110 #define RSP_MEMORY 0x82
111 #define RSP_NO_TARGET_POWER 0xAB
112 #define RSP_OK 0x80
113 #define RSP_PARAMETER 0x81
114 #define RSP_PC 0x84
115 #define RSP_SELFTEST 0x85
116 #define RSP_SET_N_PARAMETERS 0xA7
117 #define RSP_SIGN_ON 0x86
118 #define RSP_SPI_DATA 0x88
119
120 /* ICE events */
121 #define EVT_BREAK 0xE0
122 #define EVT_DEBUG 0xE6
123 #define EVT_ERROR_PHY_FORCE_BREAK_TIMEOUT 0xE2
124 #define EVT_ERROR_PHY_MAX_BIT_LENGTH_DIFF 0xED
125 #define EVT_ERROR_PHY_OPT_RECEIVE_TIMEOUT 0xF9
126 #define EVT_ERROR_PHY_OPT_RECEIVED_BREAK 0xFA
127 #define EVT_ERROR_PHY_RECEIVED_BREAK 0xF8
128 #define EVT_ERROR_PHY_RECEIVE_TIMEOUT 0xF7
129 #define EVT_ERROR_PHY_RELEASE_BREAK_TIMEOUT 0xE3
130 #define EVT_ERROR_PHY_SYNC_OUT_OF_RANGE 0xF5
131 #define EVT_ERROR_PHY_SYNC_TIMEOUT 0xF0
132 #define EVT_ERROR_PHY_SYNC_TIMEOUT_BAUD 0xF4
133 #define EVT_ERROR_PHY_SYNC_WAIT_TIMEOUT 0xF6
134 #define EVT_RESULT_PHY_NO_ACTIVITY 0xFB
135 #define EVT_EXT_RESET 0xE7
136 #define EVT_ICE_POWER_ERROR_STATE 0xEA
137 #define EVT_ICE_POWER_OK 0xEB
138 #define EVT_IDR_DIRTY 0xEC
139 #define EVT_NONE 0xEF
140 #define EVT_PDSB_BREAK 0xF2
141 #define EVT_PDSMB_BREAK 0xF3
142 #define EVT_PROGRAM_BREAK 0xF1
143 #define EVT_RUN 0xE1
144 #define EVT_TARGET_POWER_OFF 0xE5
145 #define EVT_TARGET_POWER_ON 0xE4
146 #define EVT_TARGET_SLEEP 0xE8
147 #define EVT_TARGET_WAKEUP 0xE9
148
149 /* memory types for CMND_{READ,WRITE}_MEMORY */
150 #define MTYPE_IO_SHADOW 0x30 /* cached IO registers? */
151 #define MTYPE_SRAM 0x20 /* target's SRAM or [ext.] IO registers */
152 #define MTYPE_EEPROM 0x22 /* EEPROM, what way? */
153 #define MTYPE_EVENT 0x60 /* ICE event memory */
154 #define MTYPE_SPM 0xA0 /* flash through LPM/SPM */
155 #define MTYPE_FLASH_PAGE 0xB0 /* flash in programming mode */
156 #define MTYPE_EEPROM_PAGE 0xB1 /* EEPROM in programming mode */
157 #define MTYPE_FUSE_BITS 0xB2 /* fuse bits in programming mode */
158 #define MTYPE_LOCK_BITS 0xB3 /* lock bits in programming mode */
159 #define MTYPE_SIGN_JTAG 0xB4 /* signature in programming mode */
160 #define MTYPE_OSCCAL_BYTE 0xB5 /* osccal cells in programming mode */
161 #define MTYPE_CAN 0xB6 /* CAN mailbox */
162
163 /* (some) ICE parameters, for CMND_{GET,SET}_PARAMETER */
164 #define PAR_HW_VERSION 0x01
165 #define PAR_FW_VERSION 0x02
166 #define PAR_EMULATOR_MODE 0x03
167 # define EMULATOR_MODE_DEBUGWIRE 0x00
168 # define EMULATOR_MODE_JTAG 0x01
169 # define EMULATOR_MODE_UNKNOWN 0x02
170 # define EMULATOR_MODE_SPI 0x03
171 #define PAR_IREG 0x04
172 #define PAR_BAUD_RATE 0x05
173 # define PAR_BAUD_2400 0x01
174 # define PAR_BAUD_4800 0x02
175 # define PAR_BAUD_9600 0x03
176 # define PAR_BAUD_19200 0x04 /* default */
177 # define PAR_BAUD_38400 0x05
178 # define PAR_BAUD_57600 0x06
179 # define PAR_BAUD_115200 0x07
180 # define PAR_BAUD_14400 0x08
181 #define PAR_OCD_VTARGET 0x06
182 #define PAR_OCD_JTAG_CLK 0x07
183 #define PAR_OCD_BREAK_CAUSE 0x08
184 #define PAR_TIMERS_RUNNING 0x09
185 #define PAR_BREAK_ON_CHANGE_FLOW 0x0A
186 #define PAR_BREAK_ADDR1 0x0B
187 #define PAR_BREAK_ADDR2 0x0C
188 #define PAR_COMBBREAKCTRL 0x0D
189 #define PAR_JTAGID 0x0E
190 #define PAR_UNITS_BEFORE 0x0F
191 #define PAR_UNITS_AFTER 0x10
192 #define PAR_BIT_BEFORE 0x11
193 #define PAR_BIT_ATER 0x12
194 #define PAR_EXTERNAL_RESET 0x13
195 #define PAR_FLASH_PAGE_SIZE 0x14
196 #define PAR_EEPROM_PAGE_SIZE 0x15
197 #define PAR_UNUSED1 0x16
198 #define PAR_PSB0 0x17
199 #define PAR_PSB1 0x18
200 #define PAR_PROTOCOL_DEBUG_EVENT 0x19
201 #define PAR_MCU_STATE 0x1A
202 # define STOPPED 0x00
203 # define RUNNING 0x01
204 # define PROGRAMMING 0x02
205 #define PAR_DAISY_CHAIN_INFO 0x1B
206 #define PAR_BOOT_ADDRESS 0x1C
207 #define PAR_TARGET_SIGNATURE 0x1D
208 #define PAR_DEBUGWIRE_BAUDRATE 0x1E
209 #define PAR_PROGRAM_ENTRY_POINT 0x1F
210 #define PAR_PACKET_PARSING_ERRORS 0x40
211 #define PAR_VALID_PACKETS_RECEIVED 0x41
212 #define PAR_INTERCOMMUNICATION_TX_FAILURES 0x42
213 #define PAR_INTERCOMMUNICATION_RX_FAILURES 0x43
214 #define PAR_CRC_ERRORS 0x44
215 #define PAR_POWER_SOURCE 0x45
216 # define POWER_EXTERNAL 0x00
217 # define POWER_USB 0x01
218 #define PAR_CAN_FLAG 0x22
219 # define DONT_READ_CAN_MAILBOX 0x00
220 # define READ_CAN_MAILBOX 0x01
221 #define PAR_ENABLE_IDR_IN_RUN_MODE 0x23
222 # define ACCESS_OSCCAL 0x00
223 # define ACCESS_IDR 0x01
224 #define PAR_ALLOW_PAGEPROGRAMMING_IN_SCANCHAIN 0x24
225 # define PAGEPROG_NOT_ALLOWED 0x00
226 # define PAGEPROG_ALLOWED 0x01
227
228 /*
229 * In appnote AVR067, struct device_descriptor is written with
230 * int/long field types. We cannot use them directly, as they were
231 * neither properly aligned for portability, nor did they care for
232 * endianess issues. We thus use arrays of unsigned chars, plus
233 * conversion macros.
234 */
235 struct device_descriptor
236 {
237 unsigned char ucReadIO[8]; /*LSB = IOloc 0, MSB = IOloc63 */
238 unsigned char ucReadIOShadow[8]; /*LSB = IOloc 0, MSB = IOloc63 */
239 unsigned char ucWriteIO[8]; /*LSB = IOloc 0, MSB = IOloc63 */
240 unsigned char ucWriteIOShadow[8]; /*LSB = IOloc 0, MSB = IOloc63 */
241 unsigned char ucReadExtIO[52]; /*LSB = IOloc 96, MSB = IOloc511 */
242 unsigned char ucReadIOExtShadow[52]; /*LSB = IOloc 96, MSB = IOloc511 */
243 unsigned char ucWriteExtIO[52]; /*LSB = IOloc 96, MSB = IOloc511 */
244 unsigned char ucWriteIOExtShadow[52];/*LSB = IOloc 96, MSB = IOloc511 */
245 unsigned char ucIDRAddress; /*IDR address */
246 unsigned char ucSPMCRAddress; /*SPMCR Register address and dW BasePC */
247 unsigned char ucRAMPZAddress; /*RAMPZ Register address in SRAM I/O */
248 /*space */
249 unsigned char uiFlashPageSize[2]; /*Device Flash Page Size, Size = */
250 /*2 exp ucFlashPageSize */
251 unsigned char ucEepromPageSize; /*Device Eeprom Page Size in bytes */
252 unsigned char ulBootAddress[4]; /*Device Boot Loader Start Address */
253 unsigned char uiUpperExtIOLoc[2]; /*Topmost (last) extended I/O */
254 /*location, 0 if no external I/O */
255 unsigned char ulFlashSize[4]; /*Device Flash Size */
256 unsigned char ucEepromInst[20]; /*Instructions for W/R EEPROM */
257 unsigned char ucFlashInst[3]; /*Instructions for W/R FLASH */
258 unsigned char ucSPHaddr; /* stack pointer high */
259 unsigned char ucSPLaddr; /* stack pointer low */
260 /* new as of 16-02-2004 */
261 unsigned char uiFlashpages[2]; /* number of pages in flash */
262 unsigned char ucDWDRAddress; /* DWDR register address */
263 unsigned char ucDWBasePC; /* base/mask value of the PC */
264 /* new as of 30-04-2004 */
265 unsigned char ucAllowFullPageBitstream; /* FALSE on ALL new */
266 /*parts */
267 unsigned char uiStartSmallestBootLoaderSection[2]; /* */
268 /* new as of 18-10-2004 */
269 unsigned char EnablePageProgramming; /* For JTAG parts only, */
270 /* default TRUE */
271 unsigned char ucCacheType; /* CacheType_Normal 0x00, */
272 /* CacheType_CAN 0x01, */
273 /* CacheType_HEIMDALL 0x02 */
274 /* new as of 27-10-2004 */
275 unsigned char uiSramStartAddr[2]; /* Start of SRAM */
276 unsigned char ucResetType; /* Selects reset type. ResetNormal = 0x00 */
277 /* ResetAT76CXXX = 0x01 */
278 unsigned char ucPCMaskExtended; /* For parts with extended PC */
279 unsigned char ucPCMaskHigh; /* PC high mask */
280 unsigned char ucEindAddress; /* Selects reset type. [EIND address...] */
281 /* new as of early 2005, firmware 4.x */
282 unsigned char EECRAddress[2]; /* EECR memory-mapped IO address */
283 };