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 
37 static int dsp563xx_once_reg_read_ex(struct jtag_tap *tap, int flush, uint8_t reg, uint8_t len, uint32_t *data);
38 
40 static inline int dsp563xx_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_len, int rti)
41 {
42  jtag_add_plain_dr_scan(dr_len, dr_out, dr_in, TAP_IDLE);
43 
44  return ERROR_OK;
45 }
46 
48 static inline int dsp563xx_write_dr_u8(struct jtag_tap *tap, uint8_t *dr_in, uint8_t dr_out, int dr_len, int rti)
49 {
50  return dsp563xx_write_dr(tap, dr_in, &dr_out, dr_len, rti);
51 }
52 
54 static inline int dsp563xx_write_dr_u32(struct jtag_tap *tap, uint32_t *dr_in, uint32_t dr_out, int dr_len, int rti)
55 {
56  return dsp563xx_write_dr(tap, (uint8_t *) dr_in, (uint8_t *) &dr_out, dr_len, rti);
57 }
58 
60 static inline int dsp563xx_once_ir_exec(struct jtag_tap *tap, int flush, uint8_t instr,
61  uint8_t rw, uint8_t go, uint8_t ex)
62 {
63  int err;
64 
65  err = dsp563xx_write_dr_u8(tap, NULL, instr | (ex << 5) | (go << 6) | (rw << 7), 8, 0);
66  if (err != ERROR_OK)
67  return err;
68  if (flush)
69  err = jtag_execute_queue();
70  return err;
71 }
72 
73 /* IR and DR functions */
74 static inline int dsp563xx_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len, int rti)
75 {
76  jtag_add_plain_ir_scan(tap->ir_length, ir_out, ir_in, TAP_IDLE);
77 
78  return ERROR_OK;
79 }
80 
81 static inline int dsp563xx_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len, int rti)
82 {
83  return dsp563xx_write_ir(tap, ir_in, &ir_out, ir_len, rti);
84 }
85 
86 static inline int dsp563xx_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
87 {
88  return dsp563xx_write_ir_u8(tap, ir_in, ir_out, tap->ir_length, 1);
89 }
90 
93 {
94  int err;
95  uint8_t jtag_status;
96 
97  err = dsp563xx_jtag_sendinstr(tap, &jtag_status, JTAG_INSTR_ENABLE_ONCE);
98  if (err != ERROR_OK)
99  return TARGET_UNKNOWN;
100  err = jtag_execute_queue();
101  if (err != ERROR_OK)
102  return TARGET_UNKNOWN;
103 
104  /* verify correct static status pattern */
105  if ((jtag_status & JTAG_STATUS_STATIC_MASK) != JTAG_STATUS_STATIC_VALUE)
106  return TARGET_UNKNOWN;
107 
108  if (jtag_status != JTAG_STATUS_DEBUG)
109  return TARGET_RUNNING;
110 
111  return TARGET_HALTED;
112 }
113 
115 int dsp563xx_once_request_debug(struct jtag_tap *tap, int reset_state)
116 {
117  int err;
118  uint8_t ir_in = 0, pattern = 0;
119  uint32_t retry = 0;
120 
121  /* in reset state we only get a ACK
122  * from the interface */
123  if (reset_state)
124  pattern = 1;
125  else
126  pattern = JTAG_STATUS_DEBUG;
127 
128  /* wait until we get the ack */
129  while (ir_in != pattern) {
131  if (err != ERROR_OK)
132  return err;
133  err = jtag_execute_queue();
134  if (err != ERROR_OK)
135  return err;
136 
137  LOG_DEBUG("debug request: %02X", ir_in);
138 
139  if (retry++ == 100)
140  return ERROR_TARGET_FAILURE;
141  }
142 
143  /* we cant enable the once in reset state */
144  if (pattern == 1)
145  return ERROR_OK;
146 
147  /* try to enable once */
148  retry = 0;
149  ir_in = 0;
150  while (ir_in != pattern) {
152  if (err != ERROR_OK)
153  return err;
154  err = jtag_execute_queue();
155  if (err != ERROR_OK)
156  return err;
157 
158  LOG_DEBUG("enable once: %02X", ir_in);
159 
160  if (retry++ == 100) {
161  LOG_DEBUG("error");
162  return ERROR_TARGET_FAILURE;
163  }
164  }
165 
166  if (ir_in != JTAG_STATUS_DEBUG)
167  return ERROR_TARGET_FAILURE;
168 
169  return ERROR_OK;
170 }
171 
173 int dsp563xx_once_read_register(struct jtag_tap *tap, int flush, struct once_reg *regs, int len)
174 {
175  int i;
176  int err = ERROR_OK;
177 
178  for (i = 0; i < len; i++) {
179  err = dsp563xx_once_reg_read_ex(tap, flush, regs[i].addr, regs[i].len, &regs[i].reg);
180  if (err != ERROR_OK)
181  return err;
182  }
183 
184  if (flush)
185  err = jtag_execute_queue();
186  return err;
187 }
188 
190 static int dsp563xx_once_reg_read_ex(struct jtag_tap *tap, int flush, uint8_t reg, uint8_t len, uint32_t *data)
191 {
192  int err;
193 
194  err = dsp563xx_once_ir_exec(tap, 1, reg, 1, 0, 0);
195  if (err != ERROR_OK)
196  return err;
197  err = dsp563xx_write_dr_u32(tap, data, 0x00, len, 0);
198  if (err != ERROR_OK)
199  return err;
200  if (flush)
201  err = jtag_execute_queue();
202 
203  return err;
204 }
205 
207 int dsp563xx_once_reg_read(struct jtag_tap *tap, int flush, uint8_t reg, uint32_t *data)
208 {
209  int err;
210 
211  err = dsp563xx_once_ir_exec(tap, flush, reg, 1, 0, 0);
212  if (err != ERROR_OK)
213  return err;
214  err = dsp563xx_write_dr_u32(tap, data, 0x00, 24, 0);
215  if (err != ERROR_OK)
216  return err;
217  if (flush)
218  err = jtag_execute_queue();
219 
220  return err;
221 }
222 
224 int dsp563xx_once_reg_write(struct jtag_tap *tap, int flush, uint8_t reg, uint32_t data)
225 {
226  int err;
227 
228  err = dsp563xx_once_ir_exec(tap, flush, reg, 0, 0, 0);
229  if (err != ERROR_OK)
230  return err;
231  err = dsp563xx_write_dr_u32(tap, NULL, data, 24, 0);
232  if (err != ERROR_OK)
233  return err;
234  if (flush)
235  err = jtag_execute_queue();
236  return err;
237 }
238 
240 int dsp563xx_once_execute_sw_ir(struct jtag_tap *tap, int flush, uint32_t opcode)
241 {
242  int err;
243 
244  err = dsp563xx_once_ir_exec(tap, flush, DSP563XX_ONCE_OPDBR, 0, 1, 0);
245  if (err != ERROR_OK)
246  return err;
247  err = dsp563xx_write_dr_u32(tap, NULL, opcode, 24, 0);
248  if (err != ERROR_OK)
249  return err;
250  if (flush)
251  err = jtag_execute_queue();
252  return err;
253 }
254 
256 int dsp563xx_once_execute_dw_ir(struct jtag_tap *tap, int flush, uint32_t opcode, uint32_t operand)
257 {
258  int err;
259 
260  err = dsp563xx_once_ir_exec(tap, flush, DSP563XX_ONCE_OPDBR, 0, 0, 0);
261  if (err != ERROR_OK)
262  return err;
263  err = dsp563xx_write_dr_u32(tap, NULL, opcode, 24, 0);
264  if (err != ERROR_OK)
265  return err;
266  if (flush) {
267  err = jtag_execute_queue();
268  if (err != ERROR_OK)
269  return err;
270  }
271 
272  err = dsp563xx_once_ir_exec(tap, flush, DSP563XX_ONCE_OPDBR, 0, 1, 0);
273  if (err != ERROR_OK)
274  return err;
275  err = dsp563xx_write_dr_u32(tap, NULL, operand, 24, 0);
276  if (err != ERROR_OK)
277  return err;
278  if (flush) {
279  err = jtag_execute_queue();
280  if (err != ERROR_OK)
281  return err;
282  }
283 
284  return ERROR_OK;
285 }
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:81
#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:60
#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:92
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:54
#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
static 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
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:48
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:40
static int dsp563xx_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
Definition: dsp563xx_once.c:86
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:74
#define JTAG_STATUS_DEBUG
Definition: dsp563xx_once.c:26
#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:471
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:398
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
Definition: jtag/core.c:1043
@ TAP_IDLE
Definition: jtag.h:53
static const struct @109 regs[]
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:164
target_addr_t addr
Start address to search for the control block.
Definition: rtt/rtt.c:28
Definition: jtag.h:101
unsigned int ir_length
size of instruction register
Definition: jtag.h:110
Definition: register.h:111
@ TARGET_UNKNOWN
Definition: target.h:54
@ TARGET_HALTED
Definition: target.h:56
@ TARGET_RUNNING
Definition: target.h:55
#define ERROR_TARGET_FAILURE
Definition: target.h:791
#define NULL
Definition: usb.h:16