Add FTDI SWD driver
[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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
19 ***************************************************************************/
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "avrt.h"
26 #include "target.h"
27 #include "target_type.h"
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,
39 int handle_breakpoints, int debug_execution);
40 static int avr_step(struct target *target, int current, uint32_t address,
41 int handle_breakpoints);
42
43 static int avr_assert_reset(struct target *target);
44 static int avr_deassert_reset(struct target *target);
45
46 /* IR and DR functions */
47 static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len, int rti);
48 static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_len, int rti);
49 static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len, int rti);
50 static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int dr_len, int rti);
51
52 struct target_type avr_target = {
53 .name = "avr",
54
55 .poll = avr_poll,
56 .arch_state = avr_arch_state,
57
58 .halt = avr_halt,
59 .resume = avr_resume,
60 .step = avr_step,
61
62 .assert_reset = avr_assert_reset,
63 .deassert_reset = avr_deassert_reset,
64 /*
65 .get_gdb_reg_list = avr_get_gdb_reg_list,
66
67 .read_memory = avr_read_memory,
68 .write_memory = avr_write_memory,
69 .bulk_write_memory = avr_bulk_write_memory,
70 .checksum_memory = avr_checksum_memory,
71 .blank_check_memory = avr_blank_check_memory,
72
73 .run_algorithm = avr_run_algorithm,
74
75 .add_breakpoint = avr_add_breakpoint,
76 .remove_breakpoint = avr_remove_breakpoint,
77 .add_watchpoint = avr_add_watchpoint,
78 .remove_watchpoint = avr_remove_watchpoint,
79 */
80 .target_create = avr_target_create,
81 .init_target = avr_init_target,
82 };
83
84 static int avr_target_create(struct target *target, Jim_Interp *interp)
85 {
86 struct avr_common *avr = calloc(1, sizeof(struct avr_common));
87
88 avr->jtag_info.tap = target->tap;
89 target->arch_info = avr;
90
91 return ERROR_OK;
92 }
93
94 static int avr_init_target(struct command_context *cmd_ctx, struct target *target)
95 {
96 LOG_DEBUG("%s", __func__);
97 return ERROR_OK;
98 }
99
100 static int avr_arch_state(struct target *target)
101 {
102 LOG_DEBUG("%s", __func__);
103 return ERROR_OK;
104 }
105
106 static int avr_poll(struct target *target)
107 {
108 if ((target->state == TARGET_RUNNING) || (target->state == TARGET_DEBUG_RUNNING))
109 target->state = TARGET_HALTED;
110
111 LOG_DEBUG("%s", __func__);
112 return ERROR_OK;
113 }
114
115 static int avr_halt(struct target *target)
116 {
117 LOG_DEBUG("%s", __func__);
118 return ERROR_OK;
119 }
120
121 static int avr_resume(struct target *target, int current, uint32_t address,
122 int handle_breakpoints, int debug_execution)
123 {
124 LOG_DEBUG("%s", __func__);
125 return ERROR_OK;
126 }
127
128 static int avr_step(struct target *target, int current, uint32_t address, int handle_breakpoints)
129 {
130 LOG_DEBUG("%s", __func__);
131 return ERROR_OK;
132 }
133
134 static int avr_assert_reset(struct target *target)
135 {
136 target->state = TARGET_RESET;
137
138 LOG_DEBUG("%s", __func__);
139 return ERROR_OK;
140 }
141
142 static int avr_deassert_reset(struct target *target)
143 {
144 target->state = TARGET_RUNNING;
145
146 LOG_DEBUG("%s", __func__);
147 return ERROR_OK;
148 }
149
150 int avr_jtag_senddat(struct jtag_tap *tap, uint32_t* dr_in, uint32_t dr_out,
151 int len)
152 {
153 return mcu_write_dr_u32(tap, dr_in, dr_out, len, 1);
154 }
155
156 int avr_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
157 {
158 return mcu_write_ir_u8(tap, ir_in, ir_out, AVR_JTAG_INS_LEN, 1);
159 }
160
161 /* IR and DR functions */
162 static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out,
163 int ir_len, int rti)
164 {
165 if (NULL == tap) {
166 LOG_ERROR("invalid tap");
167 return ERROR_FAIL;
168 }
169 if (ir_len != tap->ir_length) {
170 LOG_ERROR("invalid ir_len");
171 return ERROR_FAIL;
172 }
173
174 {
175 jtag_add_plain_ir_scan(tap->ir_length, ir_out, ir_in, TAP_IDLE);
176 }
177
178 return ERROR_OK;
179 }
180
181 static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out,
182 int dr_len, int rti)
183 {
184 if (NULL == tap) {
185 LOG_ERROR("invalid tap");
186 return ERROR_FAIL;
187 }
188
189 {
190 jtag_add_plain_dr_scan(dr_len, dr_out, dr_in, TAP_IDLE);
191 }
192
193 return ERROR_OK;
194 }
195
196 static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in,
197 uint8_t ir_out, int ir_len, int rti)
198 {
199 if (ir_len > 8) {
200 LOG_ERROR("ir_len overflow, maxium is 8");
201 return ERROR_FAIL;
202 }
203
204 mcu_write_ir(tap, ir_in, &ir_out, ir_len, rti);
205
206 return ERROR_OK;
207 }
208
209 static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *dr_in,
210 uint32_t dr_out, int dr_len, int rti)
211 {
212 if (dr_len > 32) {
213 LOG_ERROR("dr_len overflow, maxium is 32");
214 return ERROR_FAIL;
215 }
216
217 mcu_write_dr(tap, (uint8_t *)dr_in, (uint8_t *)&dr_out, dr_len, rti);
218
219 return ERROR_OK;
220 }
221
222 int mcu_execute_queue(void)
223 {
224 return jtag_execute_queue();
225 }

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)