jtag: linuxgpiod: drop extra parenthesis
[openocd.git] / src / target / adi_v5_jtag.c
1 /***************************************************************************
2 * Copyright (C) 2006 by Magnus Lundin
3 * lundin@mlu.mine.nu
4 *
5 * Copyright (C) 2008 by Spencer Oliver
6 * spen@spen-soft.co.uk
7 *
8 * Copyright (C) 2009 by Oyvind Harboe
9 * oyvind.harboe@zylin.com
10 *
11 * Copyright (C) 2009-2010 by David Brownell
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ***************************************************************************/
26
27 /**
28 * @file
29 * This file implements JTAG transport support for cores implementing
30 the ARM Debug Interface version 5 (ADIv5).
31 */
32
33 #ifdef HAVE_CONFIG_H
34 #include "config.h"
35 #endif
36
37 #include "arm.h"
38 #include "arm_adi_v5.h"
39 #include <helper/time_support.h>
40 #include <helper/list.h>
41
42 /*#define DEBUG_WAIT*/
43
44 /* JTAG instructions/registers for JTAG-DP and SWJ-DP */
45 #define JTAG_DP_ABORT 0x8
46 #define JTAG_DP_DPACC 0xA
47 #define JTAG_DP_APACC 0xB
48 #define JTAG_DP_IDCODE 0xE
49
50 /* three-bit ACK values for DPACC and APACC reads */
51 #define JTAG_ACK_OK_FAULT 0x2
52 #define JTAG_ACK_WAIT 0x1
53
54 static int jtag_ap_q_abort(struct adiv5_dap *dap, uint8_t *ack);
55
56 #ifdef DEBUG_WAIT
57 static const char *dap_reg_name(int instr, int reg_addr)
58 {
59 char *reg_name = "UNK";
60
61 if (instr == JTAG_DP_DPACC) {
62 switch (reg_addr) {
63 case DP_ABORT:
64 reg_name = "ABORT";
65 break;
66 case DP_CTRL_STAT:
67 reg_name = "CTRL/STAT";
68 break;
69 case DP_SELECT:
70 reg_name = "SELECT";
71 break;
72 case DP_RDBUFF:
73 reg_name = "RDBUFF";
74 break;
75 case DP_DLCR:
76 reg_name = "DLCR";
77 break;
78 default:
79 reg_name = "UNK";
80 break;
81 }
82 }
83
84 if (instr == JTAG_DP_APACC) {
85 switch (reg_addr) {
86 case MEM_AP_REG_CSW:
87 reg_name = "CSW";
88 break;
89 case MEM_AP_REG_TAR:
90 reg_name = "TAR";
91 break;
92 case MEM_AP_REG_DRW:
93 reg_name = "DRW";
94 break;
95 case MEM_AP_REG_BD0:
96 reg_name = "BD0";
97 break;
98 case MEM_AP_REG_BD1:
99 reg_name = "BD1";
100 break;
101 case MEM_AP_REG_BD2:
102 reg_name = "BD2";
103 break;
104 case MEM_AP_REG_BD3:
105 reg_name = "BD3";
106 break;
107 case MEM_AP_REG_CFG:
108 reg_name = "CFG";
109 break;
110 case MEM_AP_REG_BASE:
111 reg_name = "BASE";
112 break;
113 case AP_REG_IDR:
114 reg_name = "IDR";
115 break;
116 default:
117 reg_name = "UNK";
118 break;
119 }
120 }
121
122 return reg_name;
123 }
124 #endif
125
126 struct dap_cmd {
127 struct list_head lh;
128 uint8_t instr;
129 uint8_t reg_addr;
130 uint8_t RnW;
131 uint8_t *invalue;
132 uint8_t ack;
133 uint32_t memaccess_tck;
134 uint32_t dp_select;
135
136 struct scan_field fields[2];
137 uint8_t out_addr_buf;
138 uint8_t invalue_buf[4];
139 uint8_t outvalue_buf[4];
140 };
141
142 #define MAX_DAP_COMMAND_NUM 65536
143
144 struct dap_cmd_pool {
145 struct list_head lh;
146 struct dap_cmd cmd;
147 } dap_cmd_pool;
148
149 static void log_dap_cmd(const char *header, struct dap_cmd *el)
150 {
151 #ifdef DEBUG_WAIT
152 LOG_DEBUG("%s: %2s %6s %5s 0x%08x 0x%08x %2s", header,
153 el->instr == JTAG_DP_APACC ? "AP" : "DP",
154 dap_reg_name(el->instr, el->reg_addr),
155 el->RnW == DPAP_READ ? "READ" : "WRITE",
156 buf_get_u32(el->outvalue_buf, 0, 32),
157 buf_get_u32(el->invalue, 0, 32),
158 el->ack == JTAG_ACK_OK_FAULT ? "OK" :
159 (el->ack == JTAG_ACK_WAIT ? "WAIT" : "INVAL"));
160 #endif
161 }
162
163 static int jtag_limit_queue_size(struct adiv5_dap *dap)
164 {
165 if (dap->cmd_pool_size < MAX_DAP_COMMAND_NUM)
166 return ERROR_OK;
167
168 return dap_run(dap);
169 }
170
171 static struct dap_cmd *dap_cmd_new(struct adiv5_dap *dap, uint8_t instr,
172 uint8_t reg_addr, uint8_t RnW,
173 uint8_t *outvalue, uint8_t *invalue,
174 uint32_t memaccess_tck)
175 {
176
177 struct dap_cmd_pool *pool = NULL;
178
179 if (list_empty(&dap->cmd_pool)) {
180 pool = calloc(1, sizeof(struct dap_cmd_pool));
181 if (pool == NULL)
182 return NULL;
183 } else {
184 pool = list_first_entry(&dap->cmd_pool, struct dap_cmd_pool, lh);
185 list_del(&pool->lh);
186 }
187
188 INIT_LIST_HEAD(&pool->lh);
189 dap->cmd_pool_size++;
190
191 struct dap_cmd *cmd = &pool->cmd;
192 INIT_LIST_HEAD(&cmd->lh);
193 cmd->instr = instr;
194 cmd->reg_addr = reg_addr;
195 cmd->RnW = RnW;
196 if (outvalue != NULL)
197 memcpy(cmd->outvalue_buf, outvalue, 4);
198 cmd->invalue = (invalue != NULL) ? invalue : cmd->invalue_buf;
199 cmd->memaccess_tck = memaccess_tck;
200
201 return cmd;
202 }
203
204 static void dap_cmd_release(struct adiv5_dap *dap, struct dap_cmd *cmd)
205 {
206 struct dap_cmd_pool *pool = container_of(cmd, struct dap_cmd_pool, cmd);
207 if (dap->cmd_pool_size > MAX_DAP_COMMAND_NUM)
208 free(pool);
209 else
210 list_add(&pool->lh, &dap->cmd_pool);
211
212 dap->cmd_pool_size--;
213 }
214
215 static void flush_journal(struct adiv5_dap *dap, struct list_head *lh)
216 {
217 struct dap_cmd *el, *tmp;
218
219 list_for_each_entry_safe(el, tmp, lh, lh) {
220 list_del(&el->lh);
221 dap_cmd_release(dap, el);
222 }
223 }
224
225 static void jtag_quit(struct adiv5_dap *dap)
226 {
227 struct dap_cmd_pool *el, *tmp;
228 struct list_head *lh = &dap->cmd_pool;
229
230 list_for_each_entry_safe(el, tmp, lh, lh) {
231 list_del(&el->lh);
232 free(el);
233 }
234 }
235
236 /***************************************************************************
237 *
238 * DPACC and APACC scanchain access through JTAG-DP (or SWJ-DP)
239 *
240 ***************************************************************************/
241
242 static int adi_jtag_dp_scan_cmd(struct adiv5_dap *dap, struct dap_cmd *cmd, uint8_t *ack)
243 {
244 struct jtag_tap *tap = dap->tap;
245 int retval;
246
247 retval = arm_jtag_set_instr(tap, cmd->instr, NULL, TAP_IDLE);
248 if (retval != ERROR_OK)
249 return retval;
250
251 /* Scan out a read or write operation using some DP or AP register.
252 * For APACC access with any sticky error flag set, this is discarded.
253 */
254 cmd->fields[0].num_bits = 3;
255 buf_set_u32(&cmd->out_addr_buf, 0, 3, ((cmd->reg_addr >> 1) & 0x6) | (cmd->RnW & 0x1));
256 cmd->fields[0].out_value = &cmd->out_addr_buf;
257 cmd->fields[0].in_value = (ack != NULL) ? ack : &cmd->ack;
258
259 /* NOTE: if we receive JTAG_ACK_WAIT, the previous operation did not
260 * complete; data we write is discarded, data we read is unpredictable.
261 * When overrun detect is active, STICKYORUN is set.
262 */
263
264 cmd->fields[1].num_bits = 32;
265 cmd->fields[1].out_value = cmd->outvalue_buf;
266 cmd->fields[1].in_value = cmd->invalue;
267
268 jtag_add_dr_scan(tap, 2, cmd->fields, TAP_IDLE);
269
270 /* Add specified number of tck clocks after starting memory bus
271 * access, giving the hardware time to complete the access.
272 * They provide more time for the (MEM) AP to complete the read ...
273 * See "Minimum Response Time" for JTAG-DP, in the ADIv5 spec.
274 */
275 if (cmd->instr == JTAG_DP_APACC) {
276 if (((cmd->reg_addr == MEM_AP_REG_DRW)
277 || ((cmd->reg_addr & 0xF0) == MEM_AP_REG_BD0))
278 && (cmd->memaccess_tck != 0))
279 jtag_add_runtest(cmd->memaccess_tck, TAP_IDLE);
280 }
281
282 return ERROR_OK;
283 }
284
285 static int adi_jtag_dp_scan_cmd_sync(struct adiv5_dap *dap, struct dap_cmd *cmd, uint8_t *ack)
286 {
287 int retval;
288
289 retval = adi_jtag_dp_scan_cmd(dap, cmd, ack);
290 if (retval != ERROR_OK)
291 return retval;
292
293 return jtag_execute_queue();
294 }
295
296 /**
297 * Scan DPACC or APACC using target ordered uint8_t buffers. No endianness
298 * conversions are performed. See section 4.4.3 of the ADIv5 spec, which
299 * discusses operations which access these registers.
300 *
301 * Note that only one scan is performed. If RnW is set, a separate scan
302 * will be needed to collect the data which was read; the "invalue" collects
303 * the posted result of a preceding operation, not the current one.
304 *
305 * @param dap the DAP
306 * @param instr JTAG_DP_APACC (AP access) or JTAG_DP_DPACC (DP access)
307 * @param reg_addr two significant bits; A[3:2]; for APACC access, the
308 * SELECT register has more addressing bits.
309 * @param RnW false iff outvalue will be written to the DP or AP
310 * @param outvalue points to a 32-bit (little-endian) integer
311 * @param invalue NULL, or points to a 32-bit (little-endian) integer
312 * @param ack points to where the three bit JTAG_ACK_* code will be stored
313 * @param memaccess_tck number of idle cycles to add after AP access
314 */
315
316 static int adi_jtag_dp_scan(struct adiv5_dap *dap,
317 uint8_t instr, uint8_t reg_addr, uint8_t RnW,
318 uint8_t *outvalue, uint8_t *invalue,
319 uint32_t memaccess_tck, uint8_t *ack)
320 {
321 struct dap_cmd *cmd;
322 int retval;
323
324 cmd = dap_cmd_new(dap, instr, reg_addr, RnW, outvalue, invalue, memaccess_tck);
325 if (cmd != NULL)
326 cmd->dp_select = dap->select;
327 else
328 return ERROR_JTAG_DEVICE_ERROR;
329
330 retval = adi_jtag_dp_scan_cmd(dap, cmd, ack);
331 if (retval == ERROR_OK)
332 list_add_tail(&cmd->lh, &dap->cmd_journal);
333
334 return retval;
335 }
336
337 /**
338 * Scan DPACC or APACC out and in from host ordered uint32_t buffers.
339 * This is exactly like adi_jtag_dp_scan(), except that endianness
340 * conversions are performed (so the types of invalue and outvalue
341 * must be different).
342 */
343 static int adi_jtag_dp_scan_u32(struct adiv5_dap *dap,
344 uint8_t instr, uint8_t reg_addr, uint8_t RnW,
345 uint32_t outvalue, uint32_t *invalue,
346 uint32_t memaccess_tck, uint8_t *ack)
347 {
348 uint8_t out_value_buf[4];
349 int retval;
350
351 buf_set_u32(out_value_buf, 0, 32, outvalue);
352
353 retval = adi_jtag_dp_scan(dap, instr, reg_addr, RnW,
354 out_value_buf, (uint8_t *)invalue, memaccess_tck, ack);
355 if (retval != ERROR_OK)
356 return retval;
357
358 if (invalue)
359 jtag_add_callback(arm_le_to_h_u32,
360 (jtag_callback_data_t) invalue);
361
362 return retval;
363 }
364
365 static int adi_jtag_finish_read(struct adiv5_dap *dap)
366 {
367 int retval = ERROR_OK;
368
369 if (dap->last_read != NULL) {
370 retval = adi_jtag_dp_scan_u32(dap, JTAG_DP_DPACC,
371 DP_RDBUFF, DPAP_READ, 0, dap->last_read, 0, NULL);
372 dap->last_read = NULL;
373 }
374
375 return retval;
376 }
377
378 static int adi_jtag_scan_inout_check_u32(struct adiv5_dap *dap,
379 uint8_t instr, uint8_t reg_addr, uint8_t RnW,
380 uint32_t outvalue, uint32_t *invalue, uint32_t memaccess_tck)
381 {
382 int retval;
383
384 /* Issue the read or write */
385 retval = adi_jtag_dp_scan_u32(dap, instr, reg_addr,
386 RnW, outvalue, NULL, memaccess_tck, NULL);
387 if (retval != ERROR_OK)
388 return retval;
389
390 /* For reads, collect posted value; RDBUFF has no other effect.
391 * Assumes read gets acked with OK/FAULT, and CTRL_STAT says "OK".
392 */
393 if ((RnW == DPAP_READ) && (invalue != NULL)) {
394 retval = adi_jtag_dp_scan_u32(dap, JTAG_DP_DPACC,
395 DP_RDBUFF, DPAP_READ, 0, invalue, 0, NULL);
396 if (retval != ERROR_OK)
397 return retval;
398 }
399
400 return jtag_execute_queue();
401 }
402
403 static int jtagdp_overrun_check(struct adiv5_dap *dap)
404 {
405 int retval;
406 struct dap_cmd *el, *tmp, *prev = NULL;
407 int found_wait = 0;
408 int64_t time_now;
409 LIST_HEAD(replay_list);
410
411 /* make sure all queued transactions are complete */
412 retval = jtag_execute_queue();
413 if (retval != ERROR_OK)
414 goto done;
415
416 /* skip all completed transactions up to the first WAIT */
417 list_for_each_entry(el, &dap->cmd_journal, lh) {
418 if (el->ack == JTAG_ACK_OK_FAULT) {
419 log_dap_cmd("LOG", el);
420 } else if (el->ack == JTAG_ACK_WAIT) {
421 found_wait = 1;
422 break;
423 } else {
424 LOG_ERROR("Invalid ACK (%1x) in DAP response", el->ack);
425 log_dap_cmd("ERR", el);
426 retval = ERROR_JTAG_DEVICE_ERROR;
427 goto done;
428 }
429 }
430
431 /*
432 * If we found a stalled transaction and a previous transaction
433 * exists, check if it's a READ access.
434 */
435 if (found_wait && el != list_first_entry(&dap->cmd_journal, struct dap_cmd, lh)) {
436 prev = list_entry(el->lh.prev, struct dap_cmd, lh);
437 if (prev->RnW == DPAP_READ) {
438 log_dap_cmd("PND", prev);
439 /* search for the next OK transaction, it contains
440 * the result of the previous READ */
441 tmp = el;
442 list_for_each_entry_from(tmp, &dap->cmd_journal, lh) {
443 if (tmp->ack == JTAG_ACK_OK_FAULT) {
444 /* recover the read value */
445 log_dap_cmd("FND", tmp);
446 if (el->invalue != el->invalue_buf) {
447 uint32_t invalue = le_to_h_u32(tmp->invalue);
448 memcpy(el->invalue, &invalue, sizeof(uint32_t));
449 }
450 prev = NULL;
451 break;
452 }
453 }
454
455 if (prev != NULL) {
456 log_dap_cmd("LST", el);
457
458 /*
459 * At this point we're sure that no previous
460 * transaction completed and the DAP/AP is still
461 * in busy state. We know that the next "OK" scan
462 * will return the READ result we need to recover.
463 * To complete the READ, we just keep polling RDBUFF
464 * until the WAIT condition clears
465 */
466 tmp = dap_cmd_new(dap, JTAG_DP_DPACC,
467 DP_RDBUFF, DPAP_READ, NULL, NULL, 0);
468 if (tmp == NULL) {
469 retval = ERROR_JTAG_DEVICE_ERROR;
470 goto done;
471 }
472 /* synchronously retry the command until it succeeds */
473 time_now = timeval_ms();
474 do {
475 retval = adi_jtag_dp_scan_cmd_sync(dap, tmp, NULL);
476 if (retval != ERROR_OK)
477 break;
478 if (tmp->ack == JTAG_ACK_OK_FAULT) {
479 log_dap_cmd("FND", tmp);
480 if (el->invalue != el->invalue_buf) {
481 uint32_t invalue = le_to_h_u32(tmp->invalue);
482 memcpy(el->invalue, &invalue, sizeof(uint32_t));
483 }
484 break;
485 }
486 if (tmp->ack != JTAG_ACK_WAIT) {
487 LOG_ERROR("Invalid ACK (%1x) in DAP response", tmp->ack);
488 log_dap_cmd("ERR", tmp);
489 retval = ERROR_JTAG_DEVICE_ERROR;
490 break;
491 }
492
493 } while (timeval_ms() - time_now < 1000);
494
495 if (retval == ERROR_OK) {
496 /* timeout happened */
497 if (tmp->ack != JTAG_ACK_OK_FAULT) {
498 LOG_ERROR("Timeout during WAIT recovery");
499 dap->select = DP_SELECT_INVALID;
500 jtag_ap_q_abort(dap, NULL);
501 /* clear the sticky overrun condition */
502 adi_jtag_scan_inout_check_u32(dap, JTAG_DP_DPACC,
503 DP_CTRL_STAT, DPAP_WRITE,
504 dap->dp_ctrl_stat | SSTICKYORUN, NULL, 0);
505 retval = ERROR_JTAG_DEVICE_ERROR;
506 }
507 }
508
509 /* we're done with this command, release it */
510 dap_cmd_release(dap, tmp);
511
512 if (retval != ERROR_OK)
513 goto done;
514
515 }
516 /* make el->invalue point to the default invalue
517 * so that we can safely retry it without clobbering
518 * the result we just recovered */
519 el->invalue = el->invalue_buf;
520 }
521 }
522
523 /* move all remaining transactions over to the replay list */
524 list_for_each_entry_safe_from(el, tmp, &dap->cmd_journal, lh) {
525 log_dap_cmd("REP", el);
526 list_move_tail(&el->lh, &replay_list);
527 }
528
529 /* we're done with the journal, flush it */
530 flush_journal(dap, &dap->cmd_journal);
531
532 /* check for overrun condition in the last batch of transactions */
533 if (found_wait) {
534 LOG_INFO("DAP transaction stalled (WAIT) - slowing down");
535 /* clear the sticky overrun condition */
536 retval = adi_jtag_scan_inout_check_u32(dap, JTAG_DP_DPACC,
537 DP_CTRL_STAT, DPAP_WRITE,
538 dap->dp_ctrl_stat | SSTICKYORUN, NULL, 0);
539 if (retval != ERROR_OK)
540 goto done;
541
542 /* restore SELECT register first */
543 if (!list_empty(&replay_list)) {
544 el = list_first_entry(&replay_list, struct dap_cmd, lh);
545 tmp = dap_cmd_new(dap, JTAG_DP_DPACC,
546 DP_SELECT, DPAP_WRITE, (uint8_t *)&el->dp_select, NULL, 0);
547 if (tmp == NULL) {
548 retval = ERROR_JTAG_DEVICE_ERROR;
549 goto done;
550 }
551 list_add(&tmp->lh, &replay_list);
552
553 dap->select = DP_SELECT_INVALID;
554 }
555
556 list_for_each_entry_safe(el, tmp, &replay_list, lh) {
557 time_now = timeval_ms();
558 do {
559 retval = adi_jtag_dp_scan_cmd_sync(dap, el, NULL);
560 if (retval != ERROR_OK)
561 break;
562 log_dap_cmd("REC", el);
563 if (el->ack == JTAG_ACK_OK_FAULT) {
564 if (el->invalue != el->invalue_buf) {
565 uint32_t invalue = le_to_h_u32(el->invalue);
566 memcpy(el->invalue, &invalue, sizeof(uint32_t));
567 }
568 break;
569 }
570 if (el->ack != JTAG_ACK_WAIT) {
571 LOG_ERROR("Invalid ACK (%1x) in DAP response", el->ack);
572 log_dap_cmd("ERR", el);
573 retval = ERROR_JTAG_DEVICE_ERROR;
574 break;
575 }
576 } while (timeval_ms() - time_now < 1000);
577
578 if (retval == ERROR_OK) {
579 if (el->ack != JTAG_ACK_OK_FAULT) {
580 LOG_ERROR("Timeout during WAIT recovery");
581 dap->select = DP_SELECT_INVALID;
582 jtag_ap_q_abort(dap, NULL);
583 /* clear the sticky overrun condition */
584 adi_jtag_scan_inout_check_u32(dap, JTAG_DP_DPACC,
585 DP_CTRL_STAT, DPAP_WRITE,
586 dap->dp_ctrl_stat | SSTICKYORUN, NULL, 0);
587 retval = ERROR_JTAG_DEVICE_ERROR;
588 break;
589 }
590 } else
591 break;
592 }
593 }
594
595 done:
596 flush_journal(dap, &replay_list);
597 flush_journal(dap, &dap->cmd_journal);
598 return retval;
599 }
600
601 static int jtagdp_transaction_endcheck(struct adiv5_dap *dap)
602 {
603 int retval;
604 uint32_t ctrlstat, pwrmask;
605
606 /* too expensive to call keep_alive() here */
607
608 /* Post CTRL/STAT read; discard any previous posted read value
609 * but collect its ACK status.
610 */
611 retval = adi_jtag_scan_inout_check_u32(dap, JTAG_DP_DPACC,
612 DP_CTRL_STAT, DPAP_READ, 0, &ctrlstat, 0);
613 if (retval != ERROR_OK)
614 goto done;
615
616 /* REVISIT also STICKYCMP, for pushed comparisons (nyet used) */
617
618 /* Check for STICKYERR */
619 if (ctrlstat & SSTICKYERR) {
620 LOG_DEBUG("jtag-dp: CTRL/STAT 0x%" PRIx32, ctrlstat);
621 /* Check power to debug regions */
622 pwrmask = CDBGPWRUPREQ | CDBGPWRUPACK | CSYSPWRUPREQ;
623 if (!dap->ignore_syspwrupack)
624 pwrmask |= CSYSPWRUPACK;
625 if ((ctrlstat & pwrmask) != pwrmask) {
626 LOG_ERROR("Debug regions are unpowered, an unexpected reset might have happened");
627 dap->do_reconnect = true;
628 }
629
630 if (ctrlstat & SSTICKYERR)
631 LOG_ERROR("JTAG-DP STICKY ERROR");
632 if (ctrlstat & SSTICKYORUN)
633 LOG_DEBUG("JTAG-DP STICKY OVERRUN");
634
635 /* Clear Sticky Error Bits */
636 retval = adi_jtag_scan_inout_check_u32(dap, JTAG_DP_DPACC,
637 DP_CTRL_STAT, DPAP_WRITE,
638 dap->dp_ctrl_stat | SSTICKYERR, NULL, 0);
639 if (retval != ERROR_OK)
640 goto done;
641
642 retval = ERROR_JTAG_DEVICE_ERROR;
643 }
644
645 done:
646 flush_journal(dap, &dap->cmd_journal);
647 return retval;
648 }
649
650 /*--------------------------------------------------------------------------*/
651
652 static int jtag_connect(struct adiv5_dap *dap)
653 {
654 dap->do_reconnect = false;
655 return dap_dp_init(dap);
656 }
657
658 static int jtag_check_reconnect(struct adiv5_dap *dap)
659 {
660 if (dap->do_reconnect)
661 return jtag_connect(dap);
662
663 return ERROR_OK;
664 }
665
666 static int jtag_dp_q_read(struct adiv5_dap *dap, unsigned reg,
667 uint32_t *data)
668 {
669 int retval = jtag_limit_queue_size(dap);
670 if (retval != ERROR_OK)
671 return retval;
672
673 retval = adi_jtag_dp_scan_u32(dap, JTAG_DP_DPACC, reg,
674 DPAP_READ, 0, dap->last_read, 0, NULL);
675 dap->last_read = data;
676 return retval;
677 }
678
679 static int jtag_dp_q_write(struct adiv5_dap *dap, unsigned reg,
680 uint32_t data)
681 {
682 int retval = jtag_limit_queue_size(dap);
683 if (retval != ERROR_OK)
684 return retval;
685
686 retval = adi_jtag_dp_scan_u32(dap, JTAG_DP_DPACC,
687 reg, DPAP_WRITE, data, dap->last_read, 0, NULL);
688 dap->last_read = NULL;
689 return retval;
690 }
691
692 /** Select the AP register bank matching bits 7:4 of reg. */
693 static int jtag_ap_q_bankselect(struct adiv5_ap *ap, unsigned reg)
694 {
695 struct adiv5_dap *dap = ap->dap;
696 uint32_t sel = ((uint32_t)ap->ap_num << 24) | (reg & 0x000000F0);
697
698 if (sel == dap->select)
699 return ERROR_OK;
700
701 dap->select = sel;
702
703 return jtag_dp_q_write(dap, DP_SELECT, sel);
704 }
705
706 static int jtag_ap_q_read(struct adiv5_ap *ap, unsigned reg,
707 uint32_t *data)
708 {
709 int retval = jtag_limit_queue_size(ap->dap);
710 if (retval != ERROR_OK)
711 return retval;
712
713 retval = jtag_check_reconnect(ap->dap);
714 if (retval != ERROR_OK)
715 return retval;
716
717 retval = jtag_ap_q_bankselect(ap, reg);
718 if (retval != ERROR_OK)
719 return retval;
720
721 retval = adi_jtag_dp_scan_u32(ap->dap, JTAG_DP_APACC, reg,
722 DPAP_READ, 0, ap->dap->last_read, ap->memaccess_tck, NULL);
723 ap->dap->last_read = data;
724
725 return retval;
726 }
727
728 static int jtag_ap_q_write(struct adiv5_ap *ap, unsigned reg,
729 uint32_t data)
730 {
731 int retval = jtag_limit_queue_size(ap->dap);
732 if (retval != ERROR_OK)
733 return retval;
734
735 retval = jtag_check_reconnect(ap->dap);
736 if (retval != ERROR_OK)
737 return retval;
738
739 retval = jtag_ap_q_bankselect(ap, reg);
740 if (retval != ERROR_OK)
741 return retval;
742
743 retval = adi_jtag_dp_scan_u32(ap->dap, JTAG_DP_APACC, reg,
744 DPAP_WRITE, data, ap->dap->last_read, ap->memaccess_tck, NULL);
745 ap->dap->last_read = NULL;
746 return retval;
747 }
748
749 static int jtag_ap_q_abort(struct adiv5_dap *dap, uint8_t *ack)
750 {
751 /* for JTAG, this is the only valid ABORT register operation */
752 int retval = adi_jtag_dp_scan_u32(dap, JTAG_DP_ABORT,
753 0, DPAP_WRITE, 1, NULL, 0, NULL);
754 if (retval != ERROR_OK)
755 return retval;
756
757 return jtag_execute_queue();
758 }
759
760 static int jtag_dp_run(struct adiv5_dap *dap)
761 {
762 int retval;
763 int retval2 = ERROR_OK;
764
765 retval = adi_jtag_finish_read(dap);
766 if (retval != ERROR_OK)
767 goto done;
768 retval2 = jtagdp_overrun_check(dap);
769 retval = jtagdp_transaction_endcheck(dap);
770
771 done:
772 return (retval2 != ERROR_OK) ? retval2 : retval;
773 }
774
775 static int jtag_dp_sync(struct adiv5_dap *dap)
776 {
777 return jtagdp_overrun_check(dap);
778 }
779
780 /* FIXME don't export ... just initialize as
781 * part of DAP setup
782 */
783 const struct dap_ops jtag_dp_ops = {
784 .connect = jtag_connect,
785 .queue_dp_read = jtag_dp_q_read,
786 .queue_dp_write = jtag_dp_q_write,
787 .queue_ap_read = jtag_ap_q_read,
788 .queue_ap_write = jtag_ap_q_write,
789 .queue_ap_abort = jtag_ap_q_abort,
790 .run = jtag_dp_run,
791 .sync = jtag_dp_sync,
792 .quit = jtag_quit,
793 };

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)