unbreak arm11. TAP_INVALID is used to communicate inband that a special state should...
[openocd.git] / src / target / avrt.c
blob373f6b9f76f8baa81e6410824b0d5dd4638281ca
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
24 #include "avrt.h"
25 #include "target.h"
26 #include "target_type.h"
29 #define AVR_JTAG_INS_LEN 4
31 /* cli handling */
32 int avr_register_commands(struct command_context_s *cmd_ctx);
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);
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);
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);
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);
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);
63 target_type_t avr_target =
65 .name = "avr",
67 .poll = avr_poll,
68 .arch_state = avr_arch_state,
70 .target_request_data = NULL,
72 .halt = avr_halt,
73 .resume = avr_resume,
74 .step = avr_step,
76 .assert_reset = avr_assert_reset,
77 .deassert_reset = avr_deassert_reset,
78 .soft_reset_halt = avr_soft_reset_halt,
80 .get_gdb_reg_list = avr_get_gdb_reg_list,
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,
88 .run_algorithm = avr_run_algorithm,
90 .add_breakpoint = avr_add_breakpoint,
91 .remove_breakpoint = avr_remove_breakpoint,
92 .add_watchpoint = avr_add_watchpoint,
93 .remove_watchpoint = avr_remove_watchpoint,
95 .register_commands = avr_register_commands,
96 .target_create = avr_target_create,
97 .init_target = avr_init_target,
98 .quit = avr_quit,
100 .virt2phys = avr_virt2phys,
101 .mmu = avr_mmu
105 int avr_register_commands(struct command_context_s *cmd_ctx)
107 LOG_DEBUG("%s", __FUNCTION__);
108 return ERROR_OK;
111 int avr_target_create(struct target_s *target, Jim_Interp *interp)
113 avr_common_t *avr = calloc(1, sizeof(avr_common_t));
115 avr->jtag_info.tap = target->tap;
116 target->arch_info = avr;
118 return ERROR_OK;
121 int avr_init_target(struct command_context_s *cmd_ctx, struct target_s *target)
123 LOG_DEBUG("%s", __FUNCTION__);
124 return ERROR_OK;
127 int avr_quit(void)
129 LOG_DEBUG("%s", __FUNCTION__);
130 return ERROR_OK;
133 int avr_arch_state(struct target_s *target)
135 LOG_DEBUG("%s", __FUNCTION__);
136 return ERROR_OK;
139 int avr_poll(target_t *target)
141 if ((target->state == TARGET_RUNNING) || (target->state == TARGET_DEBUG_RUNNING))
143 target->state = TARGET_HALTED;
146 LOG_DEBUG("%s", __FUNCTION__);
147 return ERROR_OK;
150 int avr_halt(target_t *target)
152 LOG_DEBUG("%s", __FUNCTION__);
153 return ERROR_OK;
156 int avr_resume(struct target_s *target, int current, u32 address, int handle_breakpoints, int debug_execution)
158 LOG_DEBUG("%s", __FUNCTION__);
159 return ERROR_OK;
162 int avr_step(struct target_s *target, int current, u32 address, int handle_breakpoints)
164 LOG_DEBUG("%s", __FUNCTION__);
165 return ERROR_OK;
168 int avr_assert_reset(target_t *target)
170 target->state = TARGET_RESET;
172 LOG_DEBUG("%s", __FUNCTION__);
173 return ERROR_OK;
176 int avr_deassert_reset(target_t *target)
178 target->state = TARGET_RUNNING;
180 LOG_DEBUG("%s", __FUNCTION__);
181 return ERROR_OK;
184 int avr_soft_reset_halt(struct target_s *target)
186 LOG_DEBUG("%s", __FUNCTION__);
187 return ERROR_OK;
190 int avr_jtag_senddat(jtag_tap_t *tap, u32* dr_in, u32 dr_out, int len)
192 return mcu_write_dr_u32(tap, dr_in, dr_out, len, 1);
195 int avr_jtag_sendinstr(jtag_tap_t *tap, u8 *ir_in, u8 ir_out)
197 return mcu_write_ir_u8(tap, ir_in, ir_out, AVR_JTAG_INS_LEN, 1);
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)
203 if (NULL == tap)
205 LOG_ERROR("invalid tap");
206 return ERROR_FAIL;
208 if (ir_len != tap->ir_length)
210 LOG_ERROR("invalid ir_len");
211 return ERROR_FAIL;
215 scan_field_t field[1];
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));
224 return ERROR_OK;
227 int mcu_write_dr(jtag_tap_t *tap, u8 *dr_in, u8 *dr_out, int dr_len, int rti)
229 if (NULL == tap)
231 LOG_ERROR("invalid tap");
232 return ERROR_FAIL;
236 scan_field_t field[1];
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));
245 return ERROR_OK;
248 int mcu_write_ir_u8(jtag_tap_t *tap, u8 *ir_in, u8 ir_out, int ir_len, int rti)
250 if (ir_len > 8)
252 LOG_ERROR("ir_len overflow, maxium is 8");
253 return ERROR_FAIL;
256 mcu_write_ir(tap, ir_in, &ir_out, ir_len, rti);
258 return ERROR_OK;
261 int mcu_write_dr_u8(jtag_tap_t *tap, u8 *dr_in, u8 dr_out, int dr_len, int rti)
263 if (dr_len > 8)
265 LOG_ERROR("dr_len overflow, maxium is 8");
266 return ERROR_FAIL;
269 mcu_write_dr(tap, dr_in, &dr_out, dr_len, rti);
271 return ERROR_OK;
274 int mcu_write_ir_u16(jtag_tap_t *tap, u16 *ir_in, u16 ir_out, int ir_len, int rti)
276 if (ir_len > 16)
278 LOG_ERROR("ir_len overflow, maxium is 16");
279 return ERROR_FAIL;
282 mcu_write_ir(tap, (u8*)ir_in, (u8*)&ir_out, ir_len, rti);
284 return ERROR_OK;
287 int mcu_write_dr_u16(jtag_tap_t *tap, u16 *dr_in, u16 dr_out, int dr_len, int rti)
289 if (dr_len > 16)
291 LOG_ERROR("dr_len overflow, maxium is 16");
292 return ERROR_FAIL;
295 mcu_write_dr(tap, (u8*)dr_in, (u8*)&dr_out, dr_len, rti);
297 return ERROR_OK;
300 int mcu_write_ir_u32(jtag_tap_t *tap, u32 *ir_in, u32 ir_out, int ir_len, int rti)
302 if (ir_len > 32)
304 LOG_ERROR("ir_len overflow, maxium is 32");
305 return ERROR_FAIL;
308 mcu_write_ir(tap, (u8*)ir_in, (u8*)&ir_out, ir_len, rti);
310 return ERROR_OK;
313 int mcu_write_dr_u32(jtag_tap_t *tap, u32 *dr_in, u32 dr_out, int dr_len, int rti)
315 if (dr_len > 32)
317 LOG_ERROR("dr_len overflow, maxium is 32");
318 return ERROR_FAIL;
321 mcu_write_dr(tap, (u8*)dr_in, (u8*)&dr_out, dr_len, rti);
323 return ERROR_OK;
326 int mcu_execute_queue(void)
328 return jtag_execute_queue();