OpenOCD
dsp563xx_once.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2009 by Mathias Kuester *
5  * mkdorg@users.sourceforge.net *
6  ***************************************************************************/
7 
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11 
12 #include <jim.h>
13 
14 #include "target.h"
15 #include "target_type.h"
16 #include "register.h"
17 #include "dsp563xx.h"
18 #include "dsp563xx_once.h"
19 
20 #define JTAG_STATUS_STATIC_MASK 0x03
21 #define JTAG_STATUS_STATIC_VALUE 0x01
22 
23 #define JTAG_STATUS_NORMAL 0x01
24 #define JTAG_STATUS_STOPWAIT 0x05
25 #define JTAG_STATUS_BUSY 0x09
26 #define JTAG_STATUS_DEBUG 0x0d
27 
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
36 
38 static inline int dsp563xx_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_len, int rti)
39 {
40  jtag_add_plain_dr_scan(dr_len, dr_out, dr_in, TAP_IDLE);
41 
42  return ERROR_OK;
43 }
44 
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)
47 {
48  return dsp563xx_write_dr(tap, dr_in, &dr_out, dr_len, rti);
49 }
50 
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)
53 {
54  return dsp563xx_write_dr(tap, (uint8_t *) dr_in, (uint8_t *) &dr_out, dr_len, rti);
55 }
56 
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)
60 {
61  int err;
62 
63  err = dsp563xx_write_dr_u8(tap, 0, 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;
69 }
70 
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)
73 {
74  jtag_add_plain_ir_scan(tap->ir_length, ir_out, ir_in, TAP_IDLE);
75 
76  return ERROR_OK;
77 }
78 
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)
80 {
81  return dsp563xx_write_ir(tap, ir_in, &ir_out, ir_len, rti);
82 }
83 
84 static inline int dsp563xx_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
85 {
86  return dsp563xx_write_ir_u8(tap, ir_in, ir_out, tap->ir_length, 1);
87 }
88 
91 {
92  int err;
93  uint8_t jtag_status;
94 
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;
101 
102  /* verify correct static status pattern */
103  if ((jtag_status & JTAG_STATUS_STATIC_MASK) != JTAG_STATUS_STATIC_VALUE)
104  return TARGET_UNKNOWN;
105 
106  if (jtag_status != JTAG_STATUS_DEBUG)
107  return TARGET_RUNNING;
108 
109  return TARGET_HALTED;
110 }
111 
113 int dsp563xx_once_request_debug(struct jtag_tap *tap, int reset_state)
114 {
115  int err;
116  uint8_t ir_in = 0, pattern = 0;
117  uint32_t retry = 0;
118 
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;
125 
126  /* wait until we get the ack */
127  while (ir_in != pattern) {
129  if (err != ERROR_OK)
130  return err;
131  err = jtag_execute_queue();
132  if (err != ERROR_OK)
133  return err;
134 
135  LOG_DEBUG("debug request: %02X", ir_in);
136 
137  if (retry++ == 100)
138  return ERROR_TARGET_FAILURE;
139  }
140 
141  /* we cant enable the once in reset state */
142  if (pattern == 1)
143  return ERROR_OK;
144 
145  /* try to enable once */
146  retry = 0;
147  ir_in = 0;
148  while (ir_in != pattern) {
150  if (err != ERROR_OK)
151  return err;
152  err = jtag_execute_queue();
153  if (err != ERROR_OK)
154  return err;
155 
156  LOG_DEBUG("enable once: %02X", ir_in);
157 
158  if (retry++ == 100) {
159  LOG_DEBUG("error");
160  return ERROR_TARGET_FAILURE;
161  }
162  }
163 
164  if (ir_in != JTAG_STATUS_DEBUG)
165  return ERROR_TARGET_FAILURE;
166 
167  return ERROR_OK;
168 }
169 
171 int dsp563xx_once_read_register(struct jtag_tap *tap, int flush, struct once_reg *regs, int len)
172 {
173  int i;
174  int err = ERROR_OK;
175 
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;
180  }
181 
182  if (flush)
183  err = jtag_execute_queue();
184  return err;
185 }
186 
188 int dsp563xx_once_reg_read_ex(struct jtag_tap *tap, int flush, uint8_t reg, uint8_t len, uint32_t *data)
189 {
190  int err;
191 
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();
200 
201  return err;
202 }
203 
205 int dsp563xx_once_reg_read(struct jtag_tap *tap, int flush, uint8_t reg, uint32_t *data)
206 {
207  int err;
208 
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();
217 
218  return err;
219 }
220 
222 int dsp563xx_once_reg_write(struct jtag_tap *tap, int flush, uint8_t reg, uint32_t data)
223 {
224  int err;
225 
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, 0x00, data, 24, 0);
230  if (err != ERROR_OK)
231  return err;
232  if (flush)
233  err = jtag_execute_queue();
234  return err;
235 }
236 
238 int dsp563xx_once_execute_sw_ir(struct jtag_tap *tap, int flush, uint32_t opcode)
239 {
240  int err;
241 
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, 0, opcode, 24, 0);
246  if (err != ERROR_OK)
247  return err;
248  if (flush)
249  err = jtag_execute_queue();
250  return err;
251 }
252 
254 int dsp563xx_once_execute_dw_ir(struct jtag_tap *tap, int flush, uint32_t opcode, uint32_t operand)
255 {
256  int err;
257 
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, 0, 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;
268  }
269 
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, 0, 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;
280  }
281 
282  return ERROR_OK;
283 }
int dsp563xx_once_execute_sw_ir(struct jtag_tap *tap, int flush, uint32_t opcode)
single word instruction
static int dsp563xx_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len, int rti)
Definition: dsp563xx_once.c:79
#define JTAG_STATUS_STATIC_MASK
Definition: dsp563xx_once.c:20
static int dsp563xx_once_ir_exec(struct jtag_tap *tap, int flush, uint8_t instr, uint8_t rw, uint8_t go, uint8_t ex)
single word instruction
Definition: dsp563xx_once.c:58
#define JTAG_INSTR_ENABLE_ONCE
Definition: dsp563xx_once.c:33
int dsp563xx_once_reg_write(struct jtag_tap *tap, int flush, uint8_t reg, uint32_t data)
once write register
int dsp563xx_once_execute_dw_ir(struct jtag_tap *tap, int flush, uint32_t opcode, uint32_t operand)
double word instruction
int dsp563xx_once_target_status(struct jtag_tap *tap)
Definition: dsp563xx_once.c:90
int dsp563xx_once_reg_read(struct jtag_tap *tap, int flush, uint8_t reg, uint32_t *data)
once read register
static int dsp563xx_write_dr_u32(struct jtag_tap *tap, uint32_t *dr_in, uint32_t dr_out, int dr_len, int rti)
Definition: dsp563xx_once.c:52
#define JTAG_STATUS_STATIC_VALUE
Definition: dsp563xx_once.c:21
int dsp563xx_once_read_register(struct jtag_tap *tap, int flush, struct once_reg *regs, int len)
once read registers
int dsp563xx_once_request_debug(struct jtag_tap *tap, int reset_state)
static int dsp563xx_write_dr_u8(struct jtag_tap *tap, uint8_t *dr_in, uint8_t dr_out, int dr_len, int rti)
Definition: dsp563xx_once.c:46
static int dsp563xx_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_len, int rti)
Definition: dsp563xx_once.c:38
static int dsp563xx_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
Definition: dsp563xx_once.c:84
static int dsp563xx_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len, int rti)
Definition: dsp563xx_once.c:72
#define JTAG_STATUS_DEBUG
Definition: dsp563xx_once.c:26
int dsp563xx_once_reg_read_ex(struct jtag_tap *tap, int flush, uint8_t reg, uint8_t len, uint32_t *data)
once read register with register len
#define JTAG_INSTR_DEBUG_REQUEST
Definition: dsp563xx_once.c:34
#define DSP563XX_ONCE_OPDBR
Definition: dsp563xx_once.h:41
void jtag_add_plain_dr_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, tap_state_t state)
Scan out the bits in ir scan mode.
Definition: jtag/core.c:465
void jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, tap_state_t state)
Scan out the bits in ir scan mode.
Definition: jtag/core.c:392
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
Definition: jtag/core.c:1037
@ TAP_IDLE
Definition: jtag.h:52
static const struct @101 regs[]
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:155
uint32_t addr
Definition: nuttx.c:65
Definition: jtag.h:100
int ir_length
size of instruction register
Definition: jtag.h:109
Definition: register.h:111
@ TARGET_UNKNOWN
Definition: target.h:53
@ TARGET_HALTED
Definition: target.h:55
@ TARGET_RUNNING
Definition: target.h:54
#define ERROR_TARGET_FAILURE
Definition: target.h:793