1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
// SPDX-License-Identifier: GPL-2.0-or-later
/***************************************************************************
* Copyright (C) 2009 by Mathias Kuester *
* mkdorg@users.sourceforge.net *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <jim.h>
#include "target.h"
#include "target_type.h"
#include "register.h"
#include "dsp563xx.h"
#include "dsp563xx_once.h"
#define JTAG_STATUS_STATIC_MASK 0x03
#define JTAG_STATUS_STATIC_VALUE 0x01
#define JTAG_STATUS_NORMAL 0x01
#define JTAG_STATUS_STOPWAIT 0x05
#define JTAG_STATUS_BUSY 0x09
#define JTAG_STATUS_DEBUG 0x0d
#define JTAG_INSTR_EXTEST 0x00
#define JTAG_INSTR_SAMPLE_PRELOAD 0x01
#define JTAG_INSTR_IDCODE 0x02
#define JTAG_INSTR_HIZ 0x04
#define JTAG_INSTR_CLAMP 0x05
#define JTAG_INSTR_ENABLE_ONCE 0x06
#define JTAG_INSTR_DEBUG_REQUEST 0x07
#define JTAG_INSTR_BYPASS 0x0F
/** */
static inline int dsp563xx_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_len, int rti)
{
jtag_add_plain_dr_scan(dr_len, dr_out, dr_in, TAP_IDLE);
return ERROR_OK;
}
/** */
static inline int dsp563xx_write_dr_u8(struct jtag_tap *tap, uint8_t *dr_in, uint8_t dr_out, int dr_len, int rti)
{
return dsp563xx_write_dr(tap, dr_in, &dr_out, dr_len, rti);
}
/** */
static inline int dsp563xx_write_dr_u32(struct jtag_tap *tap, uint32_t *dr_in, uint32_t dr_out, int dr_len, int rti)
{
return dsp563xx_write_dr(tap, (uint8_t *) dr_in, (uint8_t *) &dr_out, dr_len, rti);
}
/** single word instruction */
static inline int dsp563xx_once_ir_exec(struct jtag_tap *tap, int flush, uint8_t instr,
uint8_t rw, uint8_t go, uint8_t ex)
{
int err;
err = dsp563xx_write_dr_u8(tap, NULL, instr | (ex << 5) | (go << 6) | (rw << 7), 8, 0);
if (err != ERROR_OK)
return err;
if (flush)
err = jtag_execute_queue();
return err;
}
/* IR and DR functions */
static inline int dsp563xx_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len, int rti)
{
jtag_add_plain_ir_scan(tap->ir_length, ir_out, ir_in, TAP_IDLE);
return ERROR_OK;
}
static inline int dsp563xx_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len, int rti)
{
return dsp563xx_write_ir(tap, ir_in, &ir_out, ir_len, rti);
}
static inline int dsp563xx_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
{
return dsp563xx_write_ir_u8(tap, ir_in, ir_out, tap->ir_length, 1);
}
/** */
int dsp563xx_once_target_status(struct jtag_tap *tap)
{
int err;
uint8_t jtag_status;
err = dsp563xx_jtag_sendinstr(tap, &jtag_status, JTAG_INSTR_ENABLE_ONCE);
if (err != ERROR_OK)
return TARGET_UNKNOWN;
err = jtag_execute_queue();
if (err != ERROR_OK)
return TARGET_UNKNOWN;
/* verify correct static status pattern */
if ((jtag_status & JTAG_STATUS_STATIC_MASK) != JTAG_STATUS_STATIC_VALUE)
return TARGET_UNKNOWN;
if (jtag_status != JTAG_STATUS_DEBUG)
return TARGET_RUNNING;
return TARGET_HALTED;
}
/** */
int dsp563xx_once_request_debug(struct jtag_tap *tap, int reset_state)
{
int err;
uint8_t ir_in = 0, pattern = 0;
uint32_t retry = 0;
/* in reset state we only get a ACK
* from the interface */
if (reset_state)
pattern = 1;
else
pattern = JTAG_STATUS_DEBUG;
/* wait until we get the ack */
while (ir_in != pattern) {
err = dsp563xx_jtag_sendinstr(tap, &ir_in, JTAG_INSTR_DEBUG_REQUEST);
if (err != ERROR_OK)
return err;
err = jtag_execute_queue();
if (err != ERROR_OK)
return err;
LOG_DEBUG("debug request: %02X", ir_in);
if (retry++ == 100)
return ERROR_TARGET_FAILURE;
}
/* we cant enable the once in reset state */
if (pattern == 1)
return ERROR_OK;
/* try to enable once */
retry = 0;
ir_in = 0;
while (ir_in != pattern) {
err = dsp563xx_jtag_sendinstr(tap, &ir_in, JTAG_INSTR_ENABLE_ONCE);
if (err != ERROR_OK)
return err;
err = jtag_execute_queue();
if (err != ERROR_OK)
return err;
LOG_DEBUG("enable once: %02X", ir_in);
if (retry++ == 100) {
LOG_DEBUG("error");
return ERROR_TARGET_FAILURE;
}
}
if (ir_in != JTAG_STATUS_DEBUG)
return ERROR_TARGET_FAILURE;
return ERROR_OK;
}
/** once read registers */
int dsp563xx_once_read_register(struct jtag_tap *tap, int flush, struct once_reg *regs, int len)
{
int i;
int err = ERROR_OK;
for (i = 0; i < len; i++) {
err = dsp563xx_once_reg_read_ex(tap, flush, regs[i].addr, regs[i].len, ®s[i].reg);
if (err != ERROR_OK)
return err;
}
if (flush)
err = jtag_execute_queue();
return err;
}
/** once read register with register len */
int dsp563xx_once_reg_read_ex(struct jtag_tap *tap, int flush, uint8_t reg, uint8_t len, uint32_t *data)
{
int err;
err = dsp563xx_once_ir_exec(tap, 1, reg, 1, 0, 0);
if (err != ERROR_OK)
return err;
err = dsp563xx_write_dr_u32(tap, data, 0x00, len, 0);
if (err != ERROR_OK)
return err;
if (flush)
err = jtag_execute_queue();
return err;
}
/** once read register */
int dsp563xx_once_reg_read(struct jtag_tap *tap, int flush, uint8_t reg, uint32_t *data)
{
int err;
err = dsp563xx_once_ir_exec(tap, flush, reg, 1, 0, 0);
if (err != ERROR_OK)
return err;
err = dsp563xx_write_dr_u32(tap, data, 0x00, 24, 0);
if (err != ERROR_OK)
return err;
if (flush)
err = jtag_execute_queue();
return err;
}
/** once write register */
int dsp563xx_once_reg_write(struct jtag_tap *tap, int flush, uint8_t reg, uint32_t data)
{
int err;
err = dsp563xx_once_ir_exec(tap, flush, reg, 0, 0, 0);
if (err != ERROR_OK)
return err;
err = dsp563xx_write_dr_u32(tap, NULL, data, 24, 0);
if (err != ERROR_OK)
return err;
if (flush)
err = jtag_execute_queue();
return err;
}
/** single word instruction */
int dsp563xx_once_execute_sw_ir(struct jtag_tap *tap, int flush, uint32_t opcode)
{
int err;
err = dsp563xx_once_ir_exec(tap, flush, DSP563XX_ONCE_OPDBR, 0, 1, 0);
if (err != ERROR_OK)
return err;
err = dsp563xx_write_dr_u32(tap, NULL, opcode, 24, 0);
if (err != ERROR_OK)
return err;
if (flush)
err = jtag_execute_queue();
return err;
}
/** double word instruction */
int dsp563xx_once_execute_dw_ir(struct jtag_tap *tap, int flush, uint32_t opcode, uint32_t operand)
{
int err;
err = dsp563xx_once_ir_exec(tap, flush, DSP563XX_ONCE_OPDBR, 0, 0, 0);
if (err != ERROR_OK)
return err;
err = dsp563xx_write_dr_u32(tap, NULL, opcode, 24, 0);
if (err != ERROR_OK)
return err;
if (flush) {
err = jtag_execute_queue();
if (err != ERROR_OK)
return err;
}
err = dsp563xx_once_ir_exec(tap, flush, DSP563XX_ONCE_OPDBR, 0, 1, 0);
if (err != ERROR_OK)
return err;
err = dsp563xx_write_dr_u32(tap, NULL, operand, 24, 0);
if (err != ERROR_OK)
return err;
if (flush) {
err = jtag_execute_queue();
if (err != ERROR_OK)
return err;
}
return ERROR_OK;
}
|