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, bool current, target_addr_t address,
26  bool handle_breakpoints, bool debug_execution);
27 static int avr_step(struct target *target, bool current, target_addr_t address,
28  bool 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, bool current, target_addr_t address,
109  bool handle_breakpoints, bool debug_execution)
110 {
111  LOG_DEBUG("%s", __func__);
112  return ERROR_OK;
113 }
114 
115 static int avr_step(struct target *target, bool current, target_addr_t address,
116  bool handle_breakpoints)
117 {
118  LOG_DEBUG("%s", __func__);
119  return ERROR_OK;
120 }
121 
122 static int avr_assert_reset(struct target *target)
123 {
125 
126  LOG_DEBUG("%s", __func__);
127  return ERROR_OK;
128 }
129 
130 static int avr_deassert_reset(struct target *target)
131 {
133 
134  LOG_DEBUG("%s", __func__);
135  return ERROR_OK;
136 }
137 
138 int avr_jtag_senddat(struct jtag_tap *tap, uint32_t *dr_in, uint32_t dr_out,
139  int len)
140 {
141  return mcu_write_dr_u32(tap, dr_in, dr_out, len);
142 }
143 
144 int avr_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
145 {
146  return mcu_write_ir_u8(tap, ir_in, ir_out, AVR_JTAG_INS_LEN);
147 }
148 
149 /* IR and DR functions */
150 static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out,
151  int ir_len)
152 {
153  if (!tap) {
154  LOG_ERROR("invalid tap");
155  return ERROR_FAIL;
156  }
157  if ((unsigned int)ir_len != tap->ir_length) {
158  LOG_ERROR("invalid ir_len");
159  return ERROR_FAIL;
160  }
161 
162  {
163  jtag_add_plain_ir_scan(tap->ir_length, ir_out, ir_in, TAP_IDLE);
164  }
165 
166  return ERROR_OK;
167 }
168 
169 static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out,
170  int dr_len)
171 {
172  if (!tap) {
173  LOG_ERROR("invalid tap");
174  return ERROR_FAIL;
175  }
176 
177  {
178  jtag_add_plain_dr_scan(dr_len, dr_out, dr_in, TAP_IDLE);
179  }
180 
181  return ERROR_OK;
182 }
183 
184 static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in,
185  uint8_t ir_out, int ir_len)
186 {
187  if (ir_len > 8) {
188  LOG_ERROR("ir_len overflow, maximum is 8");
189  return ERROR_FAIL;
190  }
191 
192  mcu_write_ir(tap, ir_in, &ir_out, ir_len);
193 
194  return ERROR_OK;
195 }
196 
197 static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *dr_in,
198  uint32_t dr_out, int dr_len)
199 {
200  if (dr_len > 32) {
201  LOG_ERROR("dr_len overflow, maximum is 32");
202  return ERROR_FAIL;
203  }
204 
205  mcu_write_dr(tap, (uint8_t *)dr_in, (uint8_t *)&dr_out, dr_len);
206 
207  return ERROR_OK;
208 }
209 
211 {
212  return jtag_execute_queue();
213 }
static int avr_arch_state(struct target *target)
Definition: avrt.c:87
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:138
#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:184
static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len)
Definition: avrt.c:150
static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int dr_len)
Definition: avrt.c:197
int avr_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
Definition: avrt.c:144
static int avr_step(struct target *target, bool current, target_addr_t address, bool handle_breakpoints)
Definition: avrt.c:115
static int avr_halt(struct target *target)
Definition: avrt.c:102
static int avr_assert_reset(struct target *target)
Definition: avrt.c:122
static int avr_resume(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
Definition: avrt.c:108
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:210
static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_len)
Definition: avrt.c:169
static int avr_deassert_reset(struct target *target)
Definition: avrt.c:130
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
void jtag_add_plain_dr_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, enum tap_state state)
Scan out the bits in ir scan mode.
Definition: jtag/core.c:471
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
Definition: jtag/core.c:1050
void jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, enum tap_state state)
Scan out the bits in ir scan mode.
Definition: jtag/core.c:398
@ TAP_IDLE
Definition: jtag.h:53
#define ERROR_FAIL
Definition: log.h:174
#define LOG_ERROR(expr ...)
Definition: log.h:133
#define LOG_DEBUG(expr ...)
Definition: log.h:110
#define ERROR_OK
Definition: log.h:168
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