flash/nor/stm32l4x: Remove redundant error messages
[openocd.git] / src / target / dsp563xx_once.c
blob866f33152d4b6c964f1b27a38888044872bd1090
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 /***************************************************************************
4 * Copyright (C) 2009 by Mathias Kuester *
5 * mkdorg@users.sourceforge.net *
6 ***************************************************************************/
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
12 #include <jim.h>
14 #include "target.h"
15 #include "target_type.h"
16 #include "register.h"
17 #include "dsp563xx.h"
18 #include "dsp563xx_once.h"
20 #define JTAG_STATUS_STATIC_MASK 0x03
21 #define JTAG_STATUS_STATIC_VALUE 0x01
23 #define JTAG_STATUS_NORMAL 0x01
24 #define JTAG_STATUS_STOPWAIT 0x05
25 #define JTAG_STATUS_BUSY 0x09
26 #define JTAG_STATUS_DEBUG 0x0d
28 #define JTAG_INSTR_EXTEST 0x00
29 #define JTAG_INSTR_SAMPLE_PRELOAD 0x01
30 #define JTAG_INSTR_IDCODE 0x02
31 #define JTAG_INSTR_HIZ 0x04
32 #define JTAG_INSTR_CLAMP 0x05
33 #define JTAG_INSTR_ENABLE_ONCE 0x06
34 #define JTAG_INSTR_DEBUG_REQUEST 0x07
35 #define JTAG_INSTR_BYPASS 0x0F
37 /** */
38 static inline int dsp563xx_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_len, int rti)
40 jtag_add_plain_dr_scan(dr_len, dr_out, dr_in, TAP_IDLE);
42 return ERROR_OK;
45 /** */
46 static inline int dsp563xx_write_dr_u8(struct jtag_tap *tap, uint8_t *dr_in, uint8_t dr_out, int dr_len, int rti)
48 return dsp563xx_write_dr(tap, dr_in, &dr_out, dr_len, rti);
51 /** */
52 static inline int dsp563xx_write_dr_u32(struct jtag_tap *tap, uint32_t *dr_in, uint32_t dr_out, int dr_len, int rti)
54 return dsp563xx_write_dr(tap, (uint8_t *) dr_in, (uint8_t *) &dr_out, dr_len, rti);
57 /** single word instruction */
58 static inline int dsp563xx_once_ir_exec(struct jtag_tap *tap, int flush, uint8_t instr,
59 uint8_t rw, uint8_t go, uint8_t ex)
61 int err;
63 err = dsp563xx_write_dr_u8(tap, NULL, instr | (ex << 5) | (go << 6) | (rw << 7), 8, 0);
64 if (err != ERROR_OK)
65 return err;
66 if (flush)
67 err = jtag_execute_queue();
68 return err;
71 /* IR and DR functions */
72 static inline int dsp563xx_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len, int rti)
74 jtag_add_plain_ir_scan(tap->ir_length, ir_out, ir_in, TAP_IDLE);
76 return ERROR_OK;
79 static inline int dsp563xx_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len, int rti)
81 return dsp563xx_write_ir(tap, ir_in, &ir_out, ir_len, rti);
84 static inline int dsp563xx_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
86 return dsp563xx_write_ir_u8(tap, ir_in, ir_out, tap->ir_length, 1);
89 /** */
90 int dsp563xx_once_target_status(struct jtag_tap *tap)
92 int err;
93 uint8_t jtag_status;
95 err = dsp563xx_jtag_sendinstr(tap, &jtag_status, JTAG_INSTR_ENABLE_ONCE);
96 if (err != ERROR_OK)
97 return TARGET_UNKNOWN;
98 err = jtag_execute_queue();
99 if (err != ERROR_OK)
100 return TARGET_UNKNOWN;
102 /* verify correct static status pattern */
103 if ((jtag_status & JTAG_STATUS_STATIC_MASK) != JTAG_STATUS_STATIC_VALUE)
104 return TARGET_UNKNOWN;
106 if (jtag_status != JTAG_STATUS_DEBUG)
107 return TARGET_RUNNING;
109 return TARGET_HALTED;
112 /** */
113 int dsp563xx_once_request_debug(struct jtag_tap *tap, int reset_state)
115 int err;
116 uint8_t ir_in = 0, pattern = 0;
117 uint32_t retry = 0;
119 /* in reset state we only get a ACK
120 * from the interface */
121 if (reset_state)
122 pattern = 1;
123 else
124 pattern = JTAG_STATUS_DEBUG;
126 /* wait until we get the ack */
127 while (ir_in != pattern) {
128 err = dsp563xx_jtag_sendinstr(tap, &ir_in, JTAG_INSTR_DEBUG_REQUEST);
129 if (err != ERROR_OK)
130 return err;
131 err = jtag_execute_queue();
132 if (err != ERROR_OK)
133 return err;
135 LOG_DEBUG("debug request: %02X", ir_in);
137 if (retry++ == 100)
138 return ERROR_TARGET_FAILURE;
141 /* we cant enable the once in reset state */
142 if (pattern == 1)
143 return ERROR_OK;
145 /* try to enable once */
146 retry = 0;
147 ir_in = 0;
148 while (ir_in != pattern) {
149 err = dsp563xx_jtag_sendinstr(tap, &ir_in, JTAG_INSTR_ENABLE_ONCE);
150 if (err != ERROR_OK)
151 return err;
152 err = jtag_execute_queue();
153 if (err != ERROR_OK)
154 return err;
156 LOG_DEBUG("enable once: %02X", ir_in);
158 if (retry++ == 100) {
159 LOG_DEBUG("error");
160 return ERROR_TARGET_FAILURE;
164 if (ir_in != JTAG_STATUS_DEBUG)
165 return ERROR_TARGET_FAILURE;
167 return ERROR_OK;
170 /** once read registers */
171 int dsp563xx_once_read_register(struct jtag_tap *tap, int flush, struct once_reg *regs, int len)
173 int i;
174 int err = ERROR_OK;
176 for (i = 0; i < len; i++) {
177 err = dsp563xx_once_reg_read_ex(tap, flush, regs[i].addr, regs[i].len, &regs[i].reg);
178 if (err != ERROR_OK)
179 return err;
182 if (flush)
183 err = jtag_execute_queue();
184 return err;
187 /** once read register with register len */
188 int dsp563xx_once_reg_read_ex(struct jtag_tap *tap, int flush, uint8_t reg, uint8_t len, uint32_t *data)
190 int err;
192 err = dsp563xx_once_ir_exec(tap, 1, reg, 1, 0, 0);
193 if (err != ERROR_OK)
194 return err;
195 err = dsp563xx_write_dr_u32(tap, data, 0x00, len, 0);
196 if (err != ERROR_OK)
197 return err;
198 if (flush)
199 err = jtag_execute_queue();
201 return err;
204 /** once read register */
205 int dsp563xx_once_reg_read(struct jtag_tap *tap, int flush, uint8_t reg, uint32_t *data)
207 int err;
209 err = dsp563xx_once_ir_exec(tap, flush, reg, 1, 0, 0);
210 if (err != ERROR_OK)
211 return err;
212 err = dsp563xx_write_dr_u32(tap, data, 0x00, 24, 0);
213 if (err != ERROR_OK)
214 return err;
215 if (flush)
216 err = jtag_execute_queue();
218 return err;
221 /** once write register */
222 int dsp563xx_once_reg_write(struct jtag_tap *tap, int flush, uint8_t reg, uint32_t data)
224 int err;
226 err = dsp563xx_once_ir_exec(tap, flush, reg, 0, 0, 0);
227 if (err != ERROR_OK)
228 return err;
229 err = dsp563xx_write_dr_u32(tap, NULL, data, 24, 0);
230 if (err != ERROR_OK)
231 return err;
232 if (flush)
233 err = jtag_execute_queue();
234 return err;
237 /** single word instruction */
238 int dsp563xx_once_execute_sw_ir(struct jtag_tap *tap, int flush, uint32_t opcode)
240 int err;
242 err = dsp563xx_once_ir_exec(tap, flush, DSP563XX_ONCE_OPDBR, 0, 1, 0);
243 if (err != ERROR_OK)
244 return err;
245 err = dsp563xx_write_dr_u32(tap, NULL, opcode, 24, 0);
246 if (err != ERROR_OK)
247 return err;
248 if (flush)
249 err = jtag_execute_queue();
250 return err;
253 /** double word instruction */
254 int dsp563xx_once_execute_dw_ir(struct jtag_tap *tap, int flush, uint32_t opcode, uint32_t operand)
256 int err;
258 err = dsp563xx_once_ir_exec(tap, flush, DSP563XX_ONCE_OPDBR, 0, 0, 0);
259 if (err != ERROR_OK)
260 return err;
261 err = dsp563xx_write_dr_u32(tap, NULL, opcode, 24, 0);
262 if (err != ERROR_OK)
263 return err;
264 if (flush) {
265 err = jtag_execute_queue();
266 if (err != ERROR_OK)
267 return err;
270 err = dsp563xx_once_ir_exec(tap, flush, DSP563XX_ONCE_OPDBR, 0, 1, 0);
271 if (err != ERROR_OK)
272 return err;
273 err = dsp563xx_write_dr_u32(tap, NULL, operand, 24, 0);
274 if (err != ERROR_OK)
275 return err;
276 if (flush) {
277 err = jtag_execute_queue();
278 if (err != ERROR_OK)
279 return err;
282 return ERROR_OK;