Rename jtag_add_end_state to jtag_set_end_state since "add" implies that
[openocd.git] / src / target / avrt.c
1 /***************************************************************************
2 * Copyright (C) 2009 by Simon Qian *
3 * SimonQian@SimonQian.com *
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 as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "avrt.h"
25 #include "target.h"
26 #include "target_type.h"
27
28
29 #define AVR_JTAG_INS_LEN 4
30
31 /* cli handling */
32 int avr_register_commands(struct command_context_s *cmd_ctx);
33
34 /* forward declarations */
35 int avr_target_create(struct target_s *target, Jim_Interp *interp);
36 int avr_init_target(struct command_context_s *cmd_ctx, struct target_s *target);
37 int avr_quit(void);
38
39 int avr_arch_state(struct target_s *target);
40 int avr_poll(target_t *target);
41 int avr_halt(target_t *target);
42 int avr_resume(struct target_s *target, int current, u32 address, int handle_breakpoints, int debug_execution);
43 int avr_step(struct target_s *target, int current, u32 address, int handle_breakpoints);
44
45 int avr_assert_reset(target_t *target);
46 int avr_deassert_reset(target_t *target);
47 int avr_soft_reset_halt(struct target_s *target);
48
49 /* IR and DR functions */
50 int avr_jtag_sendinstr(jtag_tap_t *tap, u8 *ir_in, u8 ir_out);
51 int avr_jtag_senddat(jtag_tap_t *tap, u32 *dr_in, u32 dr_out, int len);
52
53 int mcu_write_ir(jtag_tap_t *tap, u8 *ir_in, u8 *ir_out, int ir_len, int rti);
54 int mcu_write_dr(jtag_tap_t *tap, u8 *dr_in, u8 *dr_out, int dr_len, int rti);
55 int mcu_write_ir_u8(jtag_tap_t *tap, u8 *ir_in, u8 ir_out, int ir_len, int rti);
56 int mcu_write_dr_u8(jtag_tap_t *tap, u8 *ir_in, u8 ir_out, int dr_len, int rti);
57 int mcu_write_ir_u16(jtag_tap_t *tap, u16 *ir_in, u16 ir_out, int ir_len, int rti);
58 int mcu_write_dr_u16(jtag_tap_t *tap, u16 *ir_in, u16 ir_out, int dr_len, int rti);
59 int mcu_write_ir_u32(jtag_tap_t *tap, u32 *ir_in, u32 ir_out, int ir_len, int rti);
60 int mcu_write_dr_u32(jtag_tap_t *tap, u32 *ir_in, u32 ir_out, int dr_len, int rti);
61 int mcu_execute_queue(void);
62
63 target_type_t avr_target =
64 {
65 .name = "avr",
66
67 .poll = avr_poll,
68 .arch_state = avr_arch_state,
69
70 .target_request_data = NULL,
71
72 .halt = avr_halt,
73 .resume = avr_resume,
74 .step = avr_step,
75
76 .assert_reset = avr_assert_reset,
77 .deassert_reset = avr_deassert_reset,
78 .soft_reset_halt = avr_soft_reset_halt,
79 /*
80 .get_gdb_reg_list = avr_get_gdb_reg_list,
81
82 .read_memory = avr_read_memory,
83 .write_memory = avr_write_memory,
84 .bulk_write_memory = avr_bulk_write_memory,
85 .checksum_memory = avr_checksum_memory,
86 .blank_check_memory = avr_blank_check_memory,
87
88 .run_algorithm = avr_run_algorithm,
89
90 .add_breakpoint = avr_add_breakpoint,
91 .remove_breakpoint = avr_remove_breakpoint,
92 .add_watchpoint = avr_add_watchpoint,
93 .remove_watchpoint = avr_remove_watchpoint,
94 */
95 .register_commands = avr_register_commands,
96 .target_create = avr_target_create,
97 .init_target = avr_init_target,
98 .quit = avr_quit,
99 /*
100 .virt2phys = avr_virt2phys,
101 .mmu = avr_mmu
102 */
103 };
104
105 int avr_register_commands(struct command_context_s *cmd_ctx)
106 {
107 LOG_DEBUG("%s", __FUNCTION__);
108 return ERROR_OK;
109 }
110
111 int avr_target_create(struct target_s *target, Jim_Interp *interp)
112 {
113 avr_common_t *avr = calloc(1, sizeof(avr_common_t));
114
115 avr->jtag_info.tap = target->tap;
116 target->arch_info = avr;
117
118 return ERROR_OK;
119 }
120
121 int avr_init_target(struct command_context_s *cmd_ctx, struct target_s *target)
122 {
123 LOG_DEBUG("%s", __FUNCTION__);
124 return ERROR_OK;
125 }
126
127 int avr_quit(void)
128 {
129 LOG_DEBUG("%s", __FUNCTION__);
130 return ERROR_OK;
131 }
132
133 int avr_arch_state(struct target_s *target)
134 {
135 LOG_DEBUG("%s", __FUNCTION__);
136 return ERROR_OK;
137 }
138
139 int avr_poll(target_t *target)
140 {
141 if ((target->state == TARGET_RUNNING) || (target->state == TARGET_DEBUG_RUNNING))
142 {
143 target->state = TARGET_HALTED;
144 }
145
146 LOG_DEBUG("%s", __FUNCTION__);
147 return ERROR_OK;
148 }
149
150 int avr_halt(target_t *target)
151 {
152 LOG_DEBUG("%s", __FUNCTION__);
153 return ERROR_OK;
154 }
155
156 int avr_resume(struct target_s *target, int current, u32 address, int handle_breakpoints, int debug_execution)
157 {
158 LOG_DEBUG("%s", __FUNCTION__);
159 return ERROR_OK;
160 }
161
162 int avr_step(struct target_s *target, int current, u32 address, int handle_breakpoints)
163 {
164 LOG_DEBUG("%s", __FUNCTION__);
165 return ERROR_OK;
166 }
167
168 int avr_assert_reset(target_t *target)
169 {
170 target->state = TARGET_RESET;
171
172 LOG_DEBUG("%s", __FUNCTION__);
173 return ERROR_OK;
174 }
175
176 int avr_deassert_reset(target_t *target)
177 {
178 target->state = TARGET_RUNNING;
179
180 LOG_DEBUG("%s", __FUNCTION__);
181 return ERROR_OK;
182 }
183
184 int avr_soft_reset_halt(struct target_s *target)
185 {
186 LOG_DEBUG("%s", __FUNCTION__);
187 return ERROR_OK;
188 }
189
190 int avr_jtag_senddat(jtag_tap_t *tap, u32* dr_in, u32 dr_out, int len)
191 {
192 return mcu_write_dr_u32(tap, dr_in, dr_out, len, 1);
193 }
194
195 int avr_jtag_sendinstr(jtag_tap_t *tap, u8 *ir_in, u8 ir_out)
196 {
197 return mcu_write_ir_u8(tap, ir_in, ir_out, AVR_JTAG_INS_LEN, 1);
198 }
199
200 /* IR and DR functions */
201 int mcu_write_ir(jtag_tap_t *tap, u8 *ir_in, u8 *ir_out, int ir_len, int rti)
202 {
203 if (NULL == tap)
204 {
205 LOG_ERROR("invalid tap");
206 return ERROR_FAIL;
207 }
208 if (ir_len != tap->ir_length)
209 {
210 LOG_ERROR("invalid ir_len");
211 return ERROR_FAIL;
212 }
213
214 {
215 scan_field_t field[1];
216
217 field[0].tap = tap;
218 field[0].num_bits = tap->ir_length;
219 field[0].out_value = ir_out;
220 field[0].in_value = ir_in;
221 jtag_add_plain_ir_scan(sizeof(field) / sizeof(field[0]), field, jtag_set_end_state(TAP_IDLE));
222 }
223
224 return ERROR_OK;
225 }
226
227 int mcu_write_dr(jtag_tap_t *tap, u8 *dr_in, u8 *dr_out, int dr_len, int rti)
228 {
229 if (NULL == tap)
230 {
231 LOG_ERROR("invalid tap");
232 return ERROR_FAIL;
233 }
234
235 {
236 scan_field_t field[1];
237
238 field[0].tap = tap;
239 field[0].num_bits = dr_len;
240 field[0].out_value = dr_out;
241 field[0].in_value = dr_in;
242 jtag_add_plain_dr_scan(sizeof(field) / sizeof(field[0]), field, jtag_set_end_state(TAP_IDLE));
243 }
244
245 return ERROR_OK;
246 }
247
248 int mcu_write_ir_u8(jtag_tap_t *tap, u8 *ir_in, u8 ir_out, int ir_len, int rti)
249 {
250 if (ir_len > 8)
251 {
252 LOG_ERROR("ir_len overflow, maxium is 8");
253 return ERROR_FAIL;
254 }
255
256 mcu_write_ir(tap, ir_in, &ir_out, ir_len, rti);
257
258 return ERROR_OK;
259 }
260
261 int mcu_write_dr_u8(jtag_tap_t *tap, u8 *dr_in, u8 dr_out, int dr_len, int rti)
262 {
263 if (dr_len > 8)
264 {
265 LOG_ERROR("dr_len overflow, maxium is 8");
266 return ERROR_FAIL;
267 }
268
269 mcu_write_dr(tap, dr_in, &dr_out, dr_len, rti);
270
271 return ERROR_OK;
272 }
273
274 int mcu_write_ir_u16(jtag_tap_t *tap, u16 *ir_in, u16 ir_out, int ir_len, int rti)
275 {
276 if (ir_len > 16)
277 {
278 LOG_ERROR("ir_len overflow, maxium is 16");
279 return ERROR_FAIL;
280 }
281
282 mcu_write_ir(tap, (u8*)ir_in, (u8*)&ir_out, ir_len, rti);
283
284 return ERROR_OK;
285 }
286
287 int mcu_write_dr_u16(jtag_tap_t *tap, u16 *dr_in, u16 dr_out, int dr_len, int rti)
288 {
289 if (dr_len > 16)
290 {
291 LOG_ERROR("dr_len overflow, maxium is 16");
292 return ERROR_FAIL;
293 }
294
295 mcu_write_dr(tap, (u8*)dr_in, (u8*)&dr_out, dr_len, rti);
296
297 return ERROR_OK;
298 }
299
300 int mcu_write_ir_u32(jtag_tap_t *tap, u32 *ir_in, u32 ir_out, int ir_len, int rti)
301 {
302 if (ir_len > 32)
303 {
304 LOG_ERROR("ir_len overflow, maxium is 32");
305 return ERROR_FAIL;
306 }
307
308 mcu_write_ir(tap, (u8*)ir_in, (u8*)&ir_out, ir_len, rti);
309
310 return ERROR_OK;
311 }
312
313 int mcu_write_dr_u32(jtag_tap_t *tap, u32 *dr_in, u32 dr_out, int dr_len, int rti)
314 {
315 if (dr_len > 32)
316 {
317 LOG_ERROR("dr_len overflow, maxium is 32");
318 return ERROR_FAIL;
319 }
320
321 mcu_write_dr(tap, (u8*)dr_in, (u8*)&dr_out, dr_len, rti);
322
323 return ERROR_OK;
324 }
325
326 int mcu_execute_queue(void)
327 {
328 return jtag_execute_queue();
329 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)