OpenOCD
avrt.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2009 by Simon Qian *
5  * SimonQian@SimonQian.com *
6  ***************************************************************************/
7 
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11 
12 #include "avrt.h"
13 #include "target.h"
14 #include "target_type.h"
15 
16 #define AVR_JTAG_INS_LEN 4
17 
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);
21 
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);
29 
30 static int avr_assert_reset(struct target *target);
31 static int avr_deassert_reset(struct target *target);
32 
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);
35 static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_len);
36 static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len);
37 static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int dr_len);
38 
39 struct target_type avr_target = {
40  .name = "avr",
41 
42  .poll = avr_poll,
43  .arch_state = avr_arch_state,
44 
45  .halt = avr_halt,
46  .resume = avr_resume,
47  .step = avr_step,
48 
49  .assert_reset = avr_assert_reset,
50  .deassert_reset = avr_deassert_reset,
51 /*
52  .get_gdb_reg_list = avr_get_gdb_reg_list,
53 
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,
59 
60  .run_algorithm = avr_run_algorithm,
61 
62  .add_breakpoint = avr_add_breakpoint,
63  .remove_breakpoint = avr_remove_breakpoint,
64  .add_watchpoint = avr_add_watchpoint,
65  .remove_watchpoint = avr_remove_watchpoint,
66 */
67  .target_create = avr_target_create,
68  .init_target = avr_init_target,
69 };
70 
71 static int avr_target_create(struct target *target, Jim_Interp *interp)
72 {
73  struct avr_common *avr = calloc(1, sizeof(struct avr_common));
74 
75  avr->jtag_info.tap = target->tap;
76  target->arch_info = avr;
77 
78  return ERROR_OK;
79 }
80 
81 static int avr_init_target(struct command_context *cmd_ctx, struct target *target)
82 {
83  LOG_DEBUG("%s", __func__);
84  return ERROR_OK;
85 }
86 
87 static int avr_arch_state(struct target *target)
88 {
89  LOG_DEBUG("%s", __func__);
90  return ERROR_OK;
91 }
92 
93 static int avr_poll(struct target *target)
94 {
97 
98  LOG_DEBUG("%s", __func__);
99  return ERROR_OK;
100 }
101 
102 static int avr_halt(struct target *target)
103 {
104  LOG_DEBUG("%s", __func__);
105  return ERROR_OK;
106 }
107 
108 static int avr_resume(struct target *target, int current, target_addr_t address,
109  int handle_breakpoints, int debug_execution)
110 {
111  LOG_DEBUG("%s", __func__);
112  return ERROR_OK;
113 }
114 
115 static int avr_step(struct target *target, int current, target_addr_t address, int handle_breakpoints)
116 {
117  LOG_DEBUG("%s", __func__);
118  return ERROR_OK;
119 }
120 
121 static int avr_assert_reset(struct target *target)
122 {
124 
125  LOG_DEBUG("%s", __func__);
126  return ERROR_OK;
127 }
128 
129 static int avr_deassert_reset(struct target *target)
130 {
132 
133  LOG_DEBUG("%s", __func__);
134  return ERROR_OK;
135 }
136 
137 int avr_jtag_senddat(struct jtag_tap *tap, uint32_t *dr_in, uint32_t dr_out,
138  int len)
139 {
140  return mcu_write_dr_u32(tap, dr_in, dr_out, len);
141 }
142 
143 int avr_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
144 {
145  return mcu_write_ir_u8(tap, ir_in, ir_out, AVR_JTAG_INS_LEN);
146 }
147 
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)
151 {
152  if (!tap) {
153  LOG_ERROR("invalid tap");
154  return ERROR_FAIL;
155  }
156  if ((unsigned int)ir_len != tap->ir_length) {
157  LOG_ERROR("invalid ir_len");
158  return ERROR_FAIL;
159  }
160 
161  {
162  jtag_add_plain_ir_scan(tap->ir_length, ir_out, ir_in, TAP_IDLE);
163  }
164 
165  return ERROR_OK;
166 }
167 
168 static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out,
169  int dr_len)
170 {
171  if (!tap) {
172  LOG_ERROR("invalid tap");
173  return ERROR_FAIL;
174  }
175 
176  {
177  jtag_add_plain_dr_scan(dr_len, dr_out, dr_in, TAP_IDLE);
178  }
179 
180  return ERROR_OK;
181 }
182 
183 static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in,
184  uint8_t ir_out, int ir_len)
185 {
186  if (ir_len > 8) {
187  LOG_ERROR("ir_len overflow, maximum is 8");
188  return ERROR_FAIL;
189  }
190 
191  mcu_write_ir(tap, ir_in, &ir_out, ir_len);
192 
193  return ERROR_OK;
194 }
195 
196 static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *dr_in,
197  uint32_t dr_out, int dr_len)
198 {
199  if (dr_len > 32) {
200  LOG_ERROR("dr_len overflow, maximum is 32");
201  return ERROR_FAIL;
202  }
203 
204  mcu_write_dr(tap, (uint8_t *)dr_in, (uint8_t *)&dr_out, dr_len);
205 
206  return ERROR_OK;
207 }
208 
210 {
211  return jtag_execute_queue();
212 }
static int avr_arch_state(struct target *target)
Definition: avrt.c:87
static int avr_step(struct target *target, int current, target_addr_t address, int handle_breakpoints)
Definition: avrt.c:115
static int avr_poll(struct target *target)
Definition: avrt.c:93
static int avr_init_target(struct command_context *cmd_ctx, struct target *target)
Definition: avrt.c:81
int avr_jtag_senddat(struct jtag_tap *tap, uint32_t *dr_in, uint32_t dr_out, int len)
Definition: avrt.c:137
#define AVR_JTAG_INS_LEN
Definition: avrt.c:16
static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len)
Definition: avrt.c:183
static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len)
Definition: avrt.c:149
static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int dr_len)
Definition: avrt.c:196
int avr_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
Definition: avrt.c:143
static int avr_halt(struct target *target)
Definition: avrt.c:102
static int avr_assert_reset(struct target *target)
Definition: avrt.c:121
static int avr_target_create(struct target *target, Jim_Interp *interp)
Definition: avrt.c:71
struct target_type avr_target
Definition: avrt.c:39
int mcu_execute_queue(void)
Definition: avrt.c:209
static int avr_resume(struct target *target, int current, target_addr_t address, int handle_breakpoints, int debug_execution)
Definition: avrt.c:108
static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_len)
Definition: avrt.c:168
static int avr_deassert_reset(struct target *target)
Definition: avrt.c:129
void jtag_add_plain_dr_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, tap_state_t state)
Scan out the bits in ir scan mode.
Definition: jtag/core.c:465
void jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, tap_state_t state)
Scan out the bits in ir scan mode.
Definition: jtag/core.c:392
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
Definition: jtag/core.c:1037
@ TAP_IDLE
Definition: jtag.h:53
#define ERROR_FAIL
Definition: log.h:170
#define LOG_ERROR(expr ...)
Definition: log.h:132
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:164
struct mcu_jtag jtag_info
Definition: avrt.h:18
Definition: jtag.h:101
unsigned int ir_length
size of instruction register
Definition: jtag.h:110
struct jtag_tap * tap
Definition: avrt.h:14
This holds methods shared between all instances of a given target type.
Definition: target_type.h:26
const char * name
Name of this type of target.
Definition: target_type.h:31
Definition: target.h:116
struct jtag_tap * tap
Definition: target.h:119
enum target_state state
Definition: target.h:157
void * arch_info
Definition: target.h:164
@ TARGET_RESET
Definition: target.h:57
@ TARGET_DEBUG_RUNNING
Definition: target.h:58
@ TARGET_HALTED
Definition: target.h:56
@ TARGET_RUNNING
Definition: target.h:55
uint64_t target_addr_t
Definition: types.h:335