target/cortex_m: workaround Cortex-M7 erratum 3092511
[openocd.git] / src / target / avrt.c
blob61bef329febeb910433cb465a12e46189bfd0eb4
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 /***************************************************************************
4 * Copyright (C) 2009 by Simon Qian *
5 * SimonQian@SimonQian.com *
6 ***************************************************************************/
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
12 #include "avrt.h"
13 #include "target.h"
14 #include "target_type.h"
16 #define AVR_JTAG_INS_LEN 4
18 /* forward declarations */
19 static int avr_target_create(struct target *target, Jim_Interp *interp);
20 static int avr_init_target(struct command_context *cmd_ctx, struct target *target);
22 static int avr_arch_state(struct target *target);
23 static int avr_poll(struct target *target);
24 static int avr_halt(struct target *target);
25 static int avr_resume(struct target *target, int current, target_addr_t address,
26 int handle_breakpoints, int debug_execution);
27 static int avr_step(struct target *target, int current, target_addr_t address,
28 int handle_breakpoints);
30 static int avr_assert_reset(struct target *target);
31 static int avr_deassert_reset(struct target *target);
33 /* IR and DR functions */
34 static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len, int rti);
35 static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_len, int rti);
36 static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len, int rti);
37 static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int dr_len, int rti);
39 struct target_type avr_target = {
40 .name = "avr",
42 .poll = avr_poll,
43 .arch_state = avr_arch_state,
45 .halt = avr_halt,
46 .resume = avr_resume,
47 .step = avr_step,
49 .assert_reset = avr_assert_reset,
50 .deassert_reset = avr_deassert_reset,
52 .get_gdb_reg_list = avr_get_gdb_reg_list,
54 .read_memory = avr_read_memory,
55 .write_memory = avr_write_memory,
56 .bulk_write_memory = avr_bulk_write_memory,
57 .checksum_memory = avr_checksum_memory,
58 .blank_check_memory = avr_blank_check_memory,
60 .run_algorithm = avr_run_algorithm,
62 .add_breakpoint = avr_add_breakpoint,
63 .remove_breakpoint = avr_remove_breakpoint,
64 .add_watchpoint = avr_add_watchpoint,
65 .remove_watchpoint = avr_remove_watchpoint,
67 .target_create = avr_target_create,
68 .init_target = avr_init_target,
71 static int avr_target_create(struct target *target, Jim_Interp *interp)
73 struct avr_common *avr = calloc(1, sizeof(struct avr_common));
75 avr->jtag_info.tap = target->tap;
76 target->arch_info = avr;
78 return ERROR_OK;
81 static int avr_init_target(struct command_context *cmd_ctx, struct target *target)
83 LOG_DEBUG("%s", __func__);
84 return ERROR_OK;
87 static int avr_arch_state(struct target *target)
89 LOG_DEBUG("%s", __func__);
90 return ERROR_OK;
93 static int avr_poll(struct target *target)
95 if ((target->state == TARGET_RUNNING) || (target->state == TARGET_DEBUG_RUNNING))
96 target->state = TARGET_HALTED;
98 LOG_DEBUG("%s", __func__);
99 return ERROR_OK;
102 static int avr_halt(struct target *target)
104 LOG_DEBUG("%s", __func__);
105 return ERROR_OK;
108 static int avr_resume(struct target *target, int current, target_addr_t address,
109 int handle_breakpoints, int debug_execution)
111 LOG_DEBUG("%s", __func__);
112 return ERROR_OK;
115 static int avr_step(struct target *target, int current, target_addr_t address, int handle_breakpoints)
117 LOG_DEBUG("%s", __func__);
118 return ERROR_OK;
121 static int avr_assert_reset(struct target *target)
123 target->state = TARGET_RESET;
125 LOG_DEBUG("%s", __func__);
126 return ERROR_OK;
129 static int avr_deassert_reset(struct target *target)
131 target->state = TARGET_RUNNING;
133 LOG_DEBUG("%s", __func__);
134 return ERROR_OK;
137 int avr_jtag_senddat(struct jtag_tap *tap, uint32_t *dr_in, uint32_t dr_out,
138 int len)
140 return mcu_write_dr_u32(tap, dr_in, dr_out, len, 1);
143 int avr_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
145 return mcu_write_ir_u8(tap, ir_in, ir_out, AVR_JTAG_INS_LEN, 1);
148 /* IR and DR functions */
149 static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out,
150 int ir_len, int rti)
152 if (!tap) {
153 LOG_ERROR("invalid tap");
154 return ERROR_FAIL;
156 if (ir_len != tap->ir_length) {
157 LOG_ERROR("invalid ir_len");
158 return ERROR_FAIL;
162 jtag_add_plain_ir_scan(tap->ir_length, ir_out, ir_in, TAP_IDLE);
165 return ERROR_OK;
168 static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out,
169 int dr_len, int rti)
171 if (!tap) {
172 LOG_ERROR("invalid tap");
173 return ERROR_FAIL;
177 jtag_add_plain_dr_scan(dr_len, dr_out, dr_in, TAP_IDLE);
180 return ERROR_OK;
183 static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in,
184 uint8_t ir_out, int ir_len, int rti)
186 if (ir_len > 8) {
187 LOG_ERROR("ir_len overflow, maximum is 8");
188 return ERROR_FAIL;
191 mcu_write_ir(tap, ir_in, &ir_out, ir_len, rti);
193 return ERROR_OK;
196 static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *dr_in,
197 uint32_t dr_out, int dr_len, int rti)
199 if (dr_len > 32) {
200 LOG_ERROR("dr_len overflow, maximum is 32");
201 return ERROR_FAIL;
204 mcu_write_dr(tap, (uint8_t *)dr_in, (uint8_t *)&dr_out, dr_len, rti);
206 return ERROR_OK;
209 int mcu_execute_queue(void)
211 return jtag_execute_queue();