RTOS Thread awareness support wip
[openocd/openocdswd.git] / src / target / avrt.c
blob1ddf24d8f74e84801cb0011fa2797afad01d4bc1
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 /* forward declarations */
32 static int avr_target_create(struct target *target, Jim_Interp *interp);
33 static int avr_init_target(struct command_context *cmd_ctx, struct target *target);
35 static int avr_arch_state(struct target *target);
36 static int avr_poll(struct target *target);
37 static int avr_halt(struct target *target);
38 static int avr_resume(struct target *target, int current, uint32_t address, int handle_breakpoints, int debug_execution);
39 static int avr_step(struct target *target, int current, uint32_t address, int handle_breakpoints);
41 static int avr_assert_reset(struct target *target);
42 static int avr_deassert_reset(struct target *target);
43 static int avr_soft_reset_halt(struct target *target);
45 /* IR and DR functions */
46 static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len, int rti);
47 static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_len, int rti);
48 static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len, int rti);
49 static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int dr_len, int rti);
51 struct target_type avr_target =
53 .name = "avr",
55 .poll = avr_poll,
56 .arch_state = avr_arch_state,
58 .target_request_data = NULL,
60 .halt = avr_halt,
61 .resume = avr_resume,
62 .step = avr_step,
64 .assert_reset = avr_assert_reset,
65 .deassert_reset = avr_deassert_reset,
66 .soft_reset_halt = avr_soft_reset_halt,
68 .get_gdb_reg_list = avr_get_gdb_reg_list,
70 .read_memory = avr_read_memory,
71 .write_memory = avr_write_memory,
72 .bulk_write_memory = avr_bulk_write_memory,
73 .checksum_memory = avr_checksum_memory,
74 .blank_check_memory = avr_blank_check_memory,
76 .run_algorithm = avr_run_algorithm,
78 .add_breakpoint = avr_add_breakpoint,
79 .remove_breakpoint = avr_remove_breakpoint,
80 .add_watchpoint = avr_add_watchpoint,
81 .remove_watchpoint = avr_remove_watchpoint,
83 .target_create = avr_target_create,
84 .init_target = avr_init_target,
87 static int avr_target_create(struct target *target, Jim_Interp *interp)
89 struct avr_common *avr = calloc(1, sizeof(struct avr_common));
91 avr->jtag_info.tap = target->tap;
92 target->arch_info = avr;
94 return ERROR_OK;
97 static int avr_init_target(struct command_context *cmd_ctx, struct target *target)
99 LOG_DEBUG("%s", __FUNCTION__);
100 return ERROR_OK;
103 static int avr_arch_state(struct target *target)
105 LOG_DEBUG("%s", __FUNCTION__);
106 return ERROR_OK;
109 static int avr_poll(struct target *target)
111 if ((target->state == TARGET_RUNNING) || (target->state == TARGET_DEBUG_RUNNING))
113 target->state = TARGET_HALTED;
116 LOG_DEBUG("%s", __FUNCTION__);
117 return ERROR_OK;
120 static int avr_halt(struct target *target)
122 LOG_DEBUG("%s", __FUNCTION__);
123 return ERROR_OK;
126 static int avr_resume(struct target *target, int current, uint32_t address,
127 int handle_breakpoints, int debug_execution)
129 LOG_DEBUG("%s", __FUNCTION__);
130 return ERROR_OK;
133 static int avr_step(struct target *target, int current, uint32_t address, int handle_breakpoints)
135 LOG_DEBUG("%s", __FUNCTION__);
136 return ERROR_OK;
139 static int avr_assert_reset(struct target *target)
141 target->state = TARGET_RESET;
143 LOG_DEBUG("%s", __FUNCTION__);
144 return ERROR_OK;
147 static int avr_deassert_reset(struct target *target)
149 target->state = TARGET_RUNNING;
151 LOG_DEBUG("%s", __FUNCTION__);
152 return ERROR_OK;
155 static int avr_soft_reset_halt(struct target *target)
157 LOG_DEBUG("%s", __FUNCTION__);
158 return ERROR_OK;
161 int avr_jtag_senddat(struct jtag_tap *tap, uint32_t* dr_in, uint32_t dr_out,
162 int len)
164 return mcu_write_dr_u32(tap, dr_in, dr_out, len, 1);
167 int avr_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
169 return mcu_write_ir_u8(tap, ir_in, ir_out, AVR_JTAG_INS_LEN, 1);
172 /* IR and DR functions */
173 static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out,
174 int ir_len, int rti)
176 if (NULL == tap)
178 LOG_ERROR("invalid tap");
179 return ERROR_FAIL;
181 if (ir_len != tap->ir_length)
183 LOG_ERROR("invalid ir_len");
184 return ERROR_FAIL;
188 jtag_add_plain_ir_scan(tap->ir_length, ir_out, ir_in, TAP_IDLE);
191 return ERROR_OK;
194 static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out,
195 int dr_len, int rti)
197 if (NULL == tap)
199 LOG_ERROR("invalid tap");
200 return ERROR_FAIL;
204 jtag_add_plain_dr_scan(dr_len, dr_out, dr_in, TAP_IDLE);
207 return ERROR_OK;
210 static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in,
211 uint8_t ir_out, int ir_len, int rti)
213 if (ir_len > 8)
215 LOG_ERROR("ir_len overflow, maxium is 8");
216 return ERROR_FAIL;
219 mcu_write_ir(tap, ir_in, &ir_out, ir_len, rti);
221 return ERROR_OK;
224 static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *dr_in,
225 uint32_t dr_out, int dr_len, int rti)
227 if (dr_len > 32)
229 LOG_ERROR("dr_len overflow, maxium is 32");
230 return ERROR_FAIL;
233 mcu_write_dr(tap, (uint8_t*)dr_in, (uint8_t*)&dr_out, dr_len, rti);
235 return ERROR_OK;
238 int mcu_execute_queue(void)
240 return jtag_execute_queue();