target/avr: review scope of symbols
[openocd.git] / src / target / avrt.c
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
23
24 #include "avrt.h"
25 #include "target.h"
26 #include "target_type.h"
27
28
29 #define AVR_JTAG_INS_LEN 4
30
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);
34
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);
40
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);
44
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 int mcu_write_dr_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int dr_len, int rti);
50 int mcu_write_ir_u16(struct jtag_tap *tap, uint16_t *ir_in, uint16_t ir_out, int ir_len, int rti);
51 int mcu_write_dr_u16(struct jtag_tap *tap, uint16_t *ir_in, uint16_t ir_out, int dr_len, int rti);
52 int mcu_write_ir_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int ir_len, int rti);
53 static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int dr_len, int rti);
54
55 struct target_type avr_target =
56 {
57 .name = "avr",
58
59 .poll = avr_poll,
60 .arch_state = avr_arch_state,
61
62 .target_request_data = NULL,
63
64 .halt = avr_halt,
65 .resume = avr_resume,
66 .step = avr_step,
67
68 .assert_reset = avr_assert_reset,
69 .deassert_reset = avr_deassert_reset,
70 .soft_reset_halt = avr_soft_reset_halt,
71 /*
72 .get_gdb_reg_list = avr_get_gdb_reg_list,
73
74 .read_memory = avr_read_memory,
75 .write_memory = avr_write_memory,
76 .bulk_write_memory = avr_bulk_write_memory,
77 .checksum_memory = avr_checksum_memory,
78 .blank_check_memory = avr_blank_check_memory,
79
80 .run_algorithm = avr_run_algorithm,
81
82 .add_breakpoint = avr_add_breakpoint,
83 .remove_breakpoint = avr_remove_breakpoint,
84 .add_watchpoint = avr_add_watchpoint,
85 .remove_watchpoint = avr_remove_watchpoint,
86 */
87 .target_create = avr_target_create,
88 .init_target = avr_init_target,
89 };
90
91 static int avr_target_create(struct target *target, Jim_Interp *interp)
92 {
93 struct avr_common *avr = calloc(1, sizeof(struct avr_common));
94
95 avr->jtag_info.tap = target->tap;
96 target->arch_info = avr;
97
98 return ERROR_OK;
99 }
100
101 static int avr_init_target(struct command_context *cmd_ctx, struct target *target)
102 {
103 LOG_DEBUG("%s", __FUNCTION__);
104 return ERROR_OK;
105 }
106
107 static int avr_arch_state(struct target *target)
108 {
109 LOG_DEBUG("%s", __FUNCTION__);
110 return ERROR_OK;
111 }
112
113 static int avr_poll(struct target *target)
114 {
115 if ((target->state == TARGET_RUNNING) || (target->state == TARGET_DEBUG_RUNNING))
116 {
117 target->state = TARGET_HALTED;
118 }
119
120 LOG_DEBUG("%s", __FUNCTION__);
121 return ERROR_OK;
122 }
123
124 static int avr_halt(struct target *target)
125 {
126 LOG_DEBUG("%s", __FUNCTION__);
127 return ERROR_OK;
128 }
129
130 static int avr_resume(struct target *target, int current, uint32_t address,
131 int handle_breakpoints, int debug_execution)
132 {
133 LOG_DEBUG("%s", __FUNCTION__);
134 return ERROR_OK;
135 }
136
137 static int avr_step(struct target *target, int current, uint32_t address, int handle_breakpoints)
138 {
139 LOG_DEBUG("%s", __FUNCTION__);
140 return ERROR_OK;
141 }
142
143 static int avr_assert_reset(struct target *target)
144 {
145 target->state = TARGET_RESET;
146
147 LOG_DEBUG("%s", __FUNCTION__);
148 return ERROR_OK;
149 }
150
151 static int avr_deassert_reset(struct target *target)
152 {
153 target->state = TARGET_RUNNING;
154
155 LOG_DEBUG("%s", __FUNCTION__);
156 return ERROR_OK;
157 }
158
159 static int avr_soft_reset_halt(struct target *target)
160 {
161 LOG_DEBUG("%s", __FUNCTION__);
162 return ERROR_OK;
163 }
164
165 int avr_jtag_senddat(struct jtag_tap *tap, uint32_t* dr_in, uint32_t dr_out,
166 int len)
167 {
168 return mcu_write_dr_u32(tap, dr_in, dr_out, len, 1);
169 }
170
171 int avr_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
172 {
173 return mcu_write_ir_u8(tap, ir_in, ir_out, AVR_JTAG_INS_LEN, 1);
174 }
175
176 /* IR and DR functions */
177 static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out,
178 int ir_len, int rti)
179 {
180 if (NULL == tap)
181 {
182 LOG_ERROR("invalid tap");
183 return ERROR_FAIL;
184 }
185 if (ir_len != tap->ir_length)
186 {
187 LOG_ERROR("invalid ir_len");
188 return ERROR_FAIL;
189 }
190
191 {
192 jtag_add_plain_ir_scan(tap->ir_length, ir_out, ir_in, TAP_IDLE);
193 }
194
195 return ERROR_OK;
196 }
197
198 static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out,
199 int dr_len, int rti)
200 {
201 if (NULL == tap)
202 {
203 LOG_ERROR("invalid tap");
204 return ERROR_FAIL;
205 }
206
207 {
208 jtag_add_plain_dr_scan(dr_len, dr_out, dr_in, TAP_IDLE);
209 }
210
211 return ERROR_OK;
212 }
213
214 static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in,
215 uint8_t ir_out, int ir_len, int rti)
216 {
217 if (ir_len > 8)
218 {
219 LOG_ERROR("ir_len overflow, maxium is 8");
220 return ERROR_FAIL;
221 }
222
223 mcu_write_ir(tap, ir_in, &ir_out, ir_len, rti);
224
225 return ERROR_OK;
226 }
227
228 int mcu_write_dr_u8(struct jtag_tap *tap, uint8_t *dr_in, uint8_t dr_out, int dr_len, int rti)
229 {
230 if (dr_len > 8)
231 {
232 LOG_ERROR("dr_len overflow, maxium is 8");
233 return ERROR_FAIL;
234 }
235
236 mcu_write_dr(tap, dr_in, &dr_out, dr_len, rti);
237
238 return ERROR_OK;
239 }
240
241 int mcu_write_ir_u16(struct jtag_tap *tap, uint16_t *ir_in, uint16_t ir_out, int ir_len, int rti)
242 {
243 if (ir_len > 16)
244 {
245 LOG_ERROR("ir_len overflow, maxium is 16");
246 return ERROR_FAIL;
247 }
248
249 mcu_write_ir(tap, (uint8_t*)ir_in, (uint8_t*)&ir_out, ir_len, rti);
250
251 return ERROR_OK;
252 }
253
254 int mcu_write_dr_u16(struct jtag_tap *tap, uint16_t *dr_in, uint16_t dr_out, int dr_len, int rti)
255 {
256 if (dr_len > 16)
257 {
258 LOG_ERROR("dr_len overflow, maxium is 16");
259 return ERROR_FAIL;
260 }
261
262 mcu_write_dr(tap, (uint8_t*)dr_in, (uint8_t*)&dr_out, dr_len, rti);
263
264 return ERROR_OK;
265 }
266
267 int mcu_write_ir_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int ir_len, int rti)
268 {
269 if (ir_len > 32)
270 {
271 LOG_ERROR("ir_len overflow, maxium is 32");
272 return ERROR_FAIL;
273 }
274
275 mcu_write_ir(tap, (uint8_t*)ir_in, (uint8_t*)&ir_out, ir_len, rti);
276
277 return ERROR_OK;
278 }
279
280 static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *dr_in,
281 uint32_t dr_out, int dr_len, int rti)
282 {
283 if (dr_len > 32)
284 {
285 LOG_ERROR("dr_len overflow, maxium is 32");
286 return ERROR_FAIL;
287 }
288
289 mcu_write_dr(tap, (uint8_t*)dr_in, (uint8_t*)&dr_out, dr_len, rti);
290
291 return ERROR_OK;
292 }
293
294 int mcu_execute_queue(void)
295 {
296 return jtag_execute_queue();
297 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)