OpenOCD
bitbang.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2005 by Dominic Rath *
5  * Dominic.Rath@gmx.de *
6  * *
7  * Copyright (C) 2007,2008 Øyvind Harboe *
8  * oyvind.harboe@zylin.com *
9  ***************************************************************************/
10 
11 /* 2014-12: Addition of the SWD protocol support is based on the initial work
12  * by Paul Fertser and modifications by Jean-Christian de Rivaz. */
13 
14 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
17 
18 #include <jtag/jtag.h> /* Added to avoid include loop in commands.h */
19 #include "bitbang.h"
20 #include <jtag/interface.h>
21 #include <jtag/commands.h>
22 
23 #include <helper/time_support.h>
24 
25 /* Timeout for retrying on SWD WAIT in msec */
26 #define SWD_WAIT_TIMEOUT 500
27 
36 static int bitbang_stableclocks(unsigned int num_cycles);
37 
38 static void bitbang_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk);
39 
41 
42 /* DANGER!!!! clock absolutely *MUST* be 0 in idle or reset won't work!
43  *
44  * Set this to 1 and str912 reset halt will fail.
45  *
46  * If someone can submit a patch with an explanation it will be greatly
47  * appreciated, but as far as I can tell (ØH) DCLK is generated upon
48  * clk = 0 in TAP_IDLE. Good luck deducing that from the ARM documentation!
49  * The ARM documentation uses the term "DCLK is asserted while in the TAP_IDLE
50  * state". With hardware there is no such thing as *while* in a state. There
51  * are only edges. So clk => 0 is in fact a very subtle state transition that
52  * happens *while* in the TAP_IDLE state. "#&¤"#¤&"#&"#&
53  *
54  * For "reset halt" the last thing that happens before srst is asserted
55  * is that the breakpoint is set up. If DCLK is not wiggled one last
56  * time before the reset, then the breakpoint is not set up and
57  * "reset halt" will fail to halt.
58  *
59  */
60 #define CLOCK_IDLE() 0
61 
62 /* The bitbang driver leaves the TCK 0 when in idle */
64 {
65  assert(tap_is_state_stable(state));
67 }
68 
69 static int bitbang_state_move(int skip)
70 {
71  int i = 0, tms = 0;
72  uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
74 
75  for (i = skip; i < tms_count; i++) {
76  tms = (tms_scan >> i) & 1;
77  if (bitbang_interface->write(0, tms, 0) != ERROR_OK)
78  return ERROR_FAIL;
79  if (bitbang_interface->write(1, tms, 0) != ERROR_OK)
80  return ERROR_FAIL;
81  }
82  if (bitbang_interface->write(CLOCK_IDLE(), tms, 0) != ERROR_OK)
83  return ERROR_FAIL;
84 
86  return ERROR_OK;
87 }
88 
94 {
95  unsigned int num_bits = cmd->cmd.tms->num_bits;
96  const uint8_t *bits = cmd->cmd.tms->bits;
97 
98  LOG_DEBUG_IO("TMS: %u bits", num_bits);
99 
100  int tms = 0;
101  for (unsigned int i = 0; i < num_bits; i++) {
102  tms = ((bits[i/8] >> (i % 8)) & 1);
103  if (bitbang_interface->write(0, tms, 0) != ERROR_OK)
104  return ERROR_FAIL;
105  if (bitbang_interface->write(1, tms, 0) != ERROR_OK)
106  return ERROR_FAIL;
107  }
108  if (bitbang_interface->write(CLOCK_IDLE(), tms, 0) != ERROR_OK)
109  return ERROR_FAIL;
110 
111  return ERROR_OK;
112 }
113 
115 {
116  unsigned int num_states = cmd->num_states;
117  int state_count;
118  int tms = 0;
119 
120  state_count = 0;
121  while (num_states) {
122  if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count])
123  tms = 0;
124  else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count])
125  tms = 1;
126  else {
127  LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
129  tap_state_name(cmd->path[state_count]));
130  exit(-1);
131  }
132 
133  if (bitbang_interface->write(0, tms, 0) != ERROR_OK)
134  return ERROR_FAIL;
135  if (bitbang_interface->write(1, tms, 0) != ERROR_OK)
136  return ERROR_FAIL;
137 
138  tap_set_state(cmd->path[state_count]);
139  state_count++;
140  num_states--;
141  }
142 
143  if (bitbang_interface->write(CLOCK_IDLE(), tms, 0) != ERROR_OK)
144  return ERROR_FAIL;
145 
147  return ERROR_OK;
148 }
149 
150 static int bitbang_runtest(unsigned int num_cycles)
151 {
152  enum tap_state saved_end_state = tap_get_end_state();
153 
154  /* only do a state_move when we're not already in IDLE */
155  if (tap_get_state() != TAP_IDLE) {
157  if (bitbang_state_move(0) != ERROR_OK)
158  return ERROR_FAIL;
159  }
160 
161  /* execute num_cycles */
162  for (unsigned int i = 0; i < num_cycles; i++) {
163  if (bitbang_interface->write(0, 0, 0) != ERROR_OK)
164  return ERROR_FAIL;
165  if (bitbang_interface->write(1, 0, 0) != ERROR_OK)
166  return ERROR_FAIL;
167  }
168  if (bitbang_interface->write(CLOCK_IDLE(), 0, 0) != ERROR_OK)
169  return ERROR_FAIL;
170 
171  /* finish in end_state */
172  bitbang_end_state(saved_end_state);
173  if (tap_get_state() != tap_get_end_state())
174  if (bitbang_state_move(0) != ERROR_OK)
175  return ERROR_FAIL;
176 
177  return ERROR_OK;
178 }
179 
180 static int bitbang_stableclocks(unsigned int num_cycles)
181 {
182  int tms = (tap_get_state() == TAP_RESET ? 1 : 0);
183 
184  /* send num_cycles clocks onto the cable */
185  for (unsigned int i = 0; i < num_cycles; i++) {
186  if (bitbang_interface->write(1, tms, 0) != ERROR_OK)
187  return ERROR_FAIL;
188  if (bitbang_interface->write(0, tms, 0) != ERROR_OK)
189  return ERROR_FAIL;
190  }
191 
192  return ERROR_OK;
193 }
194 
195 static int bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer,
196  unsigned int scan_size)
197 {
198  enum tap_state saved_end_state = tap_get_end_state();
199  unsigned int bit_cnt;
200 
201  if (!((!ir_scan &&
202  (tap_get_state() == TAP_DRSHIFT)) ||
203  (ir_scan && (tap_get_state() == TAP_IRSHIFT)))) {
204  if (ir_scan)
206  else
208 
209  if (bitbang_state_move(0) != ERROR_OK)
210  return ERROR_FAIL;
211  bitbang_end_state(saved_end_state);
212  }
213 
214  size_t buffered = 0;
215  for (bit_cnt = 0; bit_cnt < scan_size; bit_cnt++) {
216  int tms = (bit_cnt == scan_size-1) ? 1 : 0;
217  int tdi;
218  int bytec = bit_cnt/8;
219  int bcval = 1 << (bit_cnt % 8);
220 
221  /* if we're just reading the scan, but don't care about the output
222  * default to outputting 'low', this also makes valgrind traces more readable,
223  * as it removes the dependency on an uninitialised value
224  */
225  tdi = 0;
226  if ((type != SCAN_IN) && (buffer[bytec] & bcval))
227  tdi = 1;
228 
229  if (bitbang_interface->write(0, tms, tdi) != ERROR_OK)
230  return ERROR_FAIL;
231 
232  if (type != SCAN_OUT) {
235  return ERROR_FAIL;
236  buffered++;
237  } else {
238  switch (bitbang_interface->read()) {
239  case BB_LOW:
240  buffer[bytec] &= ~bcval;
241  break;
242  case BB_HIGH:
243  buffer[bytec] |= bcval;
244  break;
245  default:
246  return ERROR_FAIL;
247  }
248  }
249  }
250 
251  if (bitbang_interface->write(1, tms, tdi) != ERROR_OK)
252  return ERROR_FAIL;
253 
255  (buffered == bitbang_interface->buf_size ||
256  bit_cnt == scan_size - 1)) {
257  for (unsigned int i = bit_cnt + 1 - buffered; i <= bit_cnt; i++) {
258  switch (bitbang_interface->read_sample()) {
259  case BB_LOW:
260  buffer[i / 8] &= ~(1 << (i % 8));
261  break;
262  case BB_HIGH:
263  buffer[i / 8] |= 1 << (i % 8);
264  break;
265  default:
266  return ERROR_FAIL;
267  }
268  }
269  buffered = 0;
270  }
271  }
272 
273  if (tap_get_state() != tap_get_end_state()) {
274  /* we *KNOW* the above loop transitioned out of
275  * the shift state, so we skip the first state
276  * and move directly to the end state.
277  */
278  if (bitbang_state_move(1) != ERROR_OK)
279  return ERROR_FAIL;
280  }
281  return ERROR_OK;
282 }
283 
284 static void bitbang_sleep(unsigned int microseconds)
285 {
286  if (bitbang_interface->sleep) {
287  bitbang_interface->sleep(microseconds);
288  } else {
289  jtag_sleep(microseconds);
290  }
291 }
292 
293 int bitbang_execute_queue(struct jtag_command *cmd_queue)
294 {
295  struct jtag_command *cmd = cmd_queue; /* currently processed command */
296  int scan_size;
297  enum scan_type type;
298  uint8_t *buffer;
299  int retval;
300 
301  if (!bitbang_interface) {
302  LOG_ERROR("BUG: Bitbang interface called, but not yet initialized");
303  exit(-1);
304  }
305 
306  /* return ERROR_OK, unless a jtag_read_buffer returns a failed check
307  * that wasn't handled by a caller-provided error handler
308  */
309  retval = ERROR_OK;
310 
311  if (bitbang_interface->blink) {
312  if (bitbang_interface->blink(true) != ERROR_OK)
313  return ERROR_FAIL;
314  }
315 
316  while (cmd) {
317  switch (cmd->type) {
318  case JTAG_RUNTEST:
319  LOG_DEBUG_IO("runtest %u cycles, end in %s",
320  cmd->cmd.runtest->num_cycles,
321  tap_state_name(cmd->cmd.runtest->end_state));
322  bitbang_end_state(cmd->cmd.runtest->end_state);
323  if (bitbang_runtest(cmd->cmd.runtest->num_cycles) != ERROR_OK)
324  return ERROR_FAIL;
325  break;
326 
327  case JTAG_STABLECLOCKS:
328  /* this is only allowed while in a stable state. A check for a stable
329  * state was done in jtag_add_clocks()
330  */
331  if (bitbang_stableclocks(cmd->cmd.stableclocks->num_cycles) != ERROR_OK)
332  return ERROR_FAIL;
333  break;
334 
335  case JTAG_TLR_RESET:
336  LOG_DEBUG_IO("statemove end in %s",
337  tap_state_name(cmd->cmd.statemove->end_state));
338  bitbang_end_state(cmd->cmd.statemove->end_state);
339  if (bitbang_state_move(0) != ERROR_OK)
340  return ERROR_FAIL;
341  break;
342  case JTAG_PATHMOVE:
343  LOG_DEBUG_IO("pathmove: %u states, end in %s",
344  cmd->cmd.pathmove->num_states,
345  tap_state_name(cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]));
346  if (bitbang_path_move(cmd->cmd.pathmove) != ERROR_OK)
347  return ERROR_FAIL;
348  break;
349  case JTAG_SCAN:
350  bitbang_end_state(cmd->cmd.scan->end_state);
351  scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
352  LOG_DEBUG_IO("%s scan %d bits; end in %s",
353  (cmd->cmd.scan->ir_scan) ? "IR" : "DR",
354  scan_size,
355  tap_state_name(cmd->cmd.scan->end_state));
356  type = jtag_scan_type(cmd->cmd.scan);
357  if (bitbang_scan(cmd->cmd.scan->ir_scan, type, buffer,
358  scan_size) != ERROR_OK) {
359  free(buffer);
360  return ERROR_FAIL;
361  }
362  if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
363  retval = ERROR_JTAG_QUEUE_FAILED;
364  free(buffer);
365  break;
366  case JTAG_SLEEP:
367  LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
369  return ERROR_FAIL;
370  bitbang_sleep(cmd->cmd.sleep->us);
371  break;
372  case JTAG_TMS:
373  retval = bitbang_execute_tms(cmd);
374  break;
375  default:
376  LOG_ERROR("BUG: unknown JTAG command type encountered");
377  exit(-1);
378  }
379  cmd = cmd->next;
380  }
381  if (bitbang_interface->blink) {
382  if (bitbang_interface->blink(false) != ERROR_OK)
383  return ERROR_FAIL;
384  }
385 
386  return retval;
387 }
388 
389 static int queued_retval;
390 
391 static int bitbang_swd_init(void)
392 {
393  LOG_DEBUG("bitbang_swd_init");
394  return ERROR_OK;
395 }
396 
397 static void bitbang_swd_exchange(bool rnw, uint8_t buf[], unsigned int offset, unsigned int bit_cnt)
398 {
399  if (bitbang_interface->blink) {
400  /* FIXME: we should manage errors */
401  bitbang_interface->blink(true);
402  }
403 
404  for (unsigned int i = offset; i < bit_cnt + offset; i++) {
405  int bytec = i/8;
406  int bcval = 1 << (i % 8);
407  int swdio = !rnw && (buf[bytec] & bcval);
408 
409  bitbang_interface->swd_write(0, swdio);
410 
411  if (rnw && buf) {
413  buf[bytec] |= bcval;
414  else
415  buf[bytec] &= ~bcval;
416  }
417 
418  bitbang_interface->swd_write(1, swdio);
419  }
420 
421  if (bitbang_interface->blink) {
422  /* FIXME: we should manage errors */
423  bitbang_interface->blink(false);
424  }
425 }
426 
428 {
429  switch (seq) {
430  case LINE_RESET:
431  LOG_DEBUG_IO("SWD line reset");
433  break;
434  case JTAG_TO_SWD:
435  LOG_DEBUG("JTAG-to-SWD");
437  break;
438  case JTAG_TO_DORMANT:
439  LOG_DEBUG("JTAG-to-DORMANT");
441  break;
442  case SWD_TO_JTAG:
443  LOG_DEBUG("SWD-to-JTAG");
445  break;
446  case SWD_TO_DORMANT:
447  LOG_DEBUG("SWD-to-DORMANT");
449  break;
450  case DORMANT_TO_SWD:
451  LOG_DEBUG("DORMANT-to-SWD");
453  break;
454  case DORMANT_TO_JTAG:
455  LOG_DEBUG("DORMANT-to-JTAG");
457  break;
458  default:
459  LOG_ERROR("Sequence %d not supported", seq);
460  return ERROR_FAIL;
461  }
462 
463  return ERROR_OK;
464 }
465 
466 static void swd_clear_sticky_errors(void)
467 {
468  bitbang_swd_write_reg(swd_cmd(false, false, DP_ABORT),
470 }
471 
472 static void bitbang_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
473 {
474  assert(cmd & SWD_CMD_RNW);
475 
476  if (queued_retval != ERROR_OK) {
477  LOG_DEBUG("Skip bitbang_swd_read_reg because queued_retval=%d", queued_retval);
478  return;
479  }
480 
481  int64_t timeout = timeval_ms() + SWD_WAIT_TIMEOUT;
482  for (unsigned int retry = 0;; retry++) {
483  uint8_t trn_ack_data_parity_trn[DIV_ROUND_UP(4 + 3 + 32 + 1 + 4, 8)];
484 
486  bitbang_swd_exchange(false, &cmd, 0, 8);
487 
489  bitbang_swd_exchange(true, trn_ack_data_parity_trn, 0, 1 + 3 + 32 + 1 + 1);
491 
492  int ack = buf_get_u32(trn_ack_data_parity_trn, 1, 3);
493  uint32_t data = buf_get_u32(trn_ack_data_parity_trn, 1 + 3, 32);
494  int parity = buf_get_u32(trn_ack_data_parity_trn, 1 + 3 + 32, 1);
495 
496  LOG_CUSTOM_LEVEL((ack != SWD_ACK_OK && (retry == 0 || ack != SWD_ACK_WAIT))
498  "%s %s read reg %X = %08" PRIx32,
499  ack == SWD_ACK_OK ? "OK" : ack == SWD_ACK_WAIT ? "WAIT" : ack == SWD_ACK_FAULT ? "FAULT" : "JUNK",
500  cmd & SWD_CMD_APNDP ? "AP" : "DP",
501  (cmd & SWD_CMD_A32) >> 1,
502  data);
503 
504  if (ack == SWD_ACK_WAIT && timeval_ms() <= timeout) {
506  if (retry > 20)
507  alive_sleep(1);
508 
509  continue;
510  }
511  if (retry > 1)
512  LOG_DEBUG("SWD WAIT: retried %u times", retry);
513 
514  if (ack != SWD_ACK_OK) {
516  return;
517  }
518 
519  if (parity != parity_u32(data)) {
520  LOG_ERROR("Wrong parity detected");
522  return;
523  }
524  if (value)
525  *value = data;
526  if (cmd & SWD_CMD_APNDP)
527  bitbang_swd_exchange(true, NULL, 0, ap_delay_clk);
528  return;
529  }
530 }
531 
532 static void bitbang_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
533 {
534  assert(!(cmd & SWD_CMD_RNW));
535 
536  if (queued_retval != ERROR_OK) {
537  LOG_DEBUG("Skip bitbang_swd_write_reg because queued_retval=%d", queued_retval);
538  return;
539  }
540 
541  int64_t timeout = timeval_ms() + SWD_WAIT_TIMEOUT;
542 
543  /* Devices do not reply to DP_TARGETSEL write cmd, ignore received ack */
544  bool check_ack = swd_cmd_returns_ack(cmd);
545 
546  /* init the array to silence scan-build */
547  uint8_t trn_ack_data_parity_trn[DIV_ROUND_UP(4 + 3 + 32 + 1 + 4, 8)] = {0};
548  for (unsigned int retry = 0;; retry++) {
549  buf_set_u32(trn_ack_data_parity_trn, 1 + 3 + 1, 32, value);
550  buf_set_u32(trn_ack_data_parity_trn, 1 + 3 + 1 + 32, 1, parity_u32(value));
551 
553  bitbang_swd_exchange(false, &cmd, 0, 8);
554 
556  bitbang_swd_exchange(true, trn_ack_data_parity_trn, 0, 1 + 3);
557 
558  /* Avoid a glitch on SWDIO when changing the direction to output.
559  * To keep performance penalty minimal, pre-write the first data
560  * bit to SWDIO GPIO output buffer while clocking the turnaround bit.
561  * Following swdio_drive(true) outputs the pre-written value
562  * and the same value is rewritten by the next swd_write()
563  * instead of glitching SWDIO
564  * HiZ/pull-up --------------> 0 -------------> 1
565  * swdio_drive(true) swd_write(0,1)
566  * in case of data bit 0 = 1
567  */
568  bitbang_swd_exchange(false, trn_ack_data_parity_trn, 1 + 3 + 1, 1);
570  bitbang_swd_exchange(false, trn_ack_data_parity_trn, 1 + 3 + 1, 32 + 1);
571 
572  int ack = buf_get_u32(trn_ack_data_parity_trn, 1, 3);
573  LOG_CUSTOM_LEVEL((check_ack && ack != SWD_ACK_OK && (retry == 0 || ack != SWD_ACK_WAIT))
575  "%s%s %s write reg %X = %08" PRIx32,
576  check_ack ? "" : "ack ignored ",
577  ack == SWD_ACK_OK ? "OK" : ack == SWD_ACK_WAIT ? "WAIT" : ack == SWD_ACK_FAULT ? "FAULT" : "JUNK",
578  cmd & SWD_CMD_APNDP ? "AP" : "DP",
579  (cmd & SWD_CMD_A32) >> 1,
580  buf_get_u32(trn_ack_data_parity_trn, 1 + 3 + 1, 32));
581 
582  if (check_ack && ack == SWD_ACK_WAIT && timeval_ms() <= timeout) {
584  if (retry > 20)
585  alive_sleep(1);
586 
587  continue;
588  }
589 
590  if (retry > 1)
591  LOG_DEBUG("SWD WAIT: retried %u times", retry);
592 
593  if (check_ack && ack != SWD_ACK_OK) {
595  return;
596  }
597 
598  if (cmd & SWD_CMD_APNDP)
599  bitbang_swd_exchange(true, NULL, 0, ap_delay_clk);
600  return;
601  }
602 }
603 
604 static int bitbang_swd_run_queue(void)
605 {
606  /* A transaction must be followed by another transaction or at least 8 idle cycles to
607  * ensure that data is clocked through the AP. */
608  bitbang_swd_exchange(true, NULL, 0, 8);
609 
610  int retval = queued_retval;
612  LOG_DEBUG_IO("SWD queue return value: %02x", retval);
613  return retval;
614 }
615 
616 const struct swd_driver bitbang_swd = {
618  .switch_seq = bitbang_swd_switch_seq,
619  .read_reg = bitbang_swd_read_reg,
620  .write_reg = bitbang_swd_write_reg,
621  .run = bitbang_swd_run_queue,
622 };
#define SWD_ACK_FAULT
Definition: arm_adi_v5.h:33
#define DP_ABORT
Definition: arm_adi_v5.h:46
#define WDERRCLR
Definition: arm_adi_v5.h:71
#define STKERRCLR
Definition: arm_adi_v5.h:70
#define ORUNERRCLR
Definition: arm_adi_v5.h:72
#define STKCMPCLR
Definition: arm_adi_v5.h:69
swd_special_seq
Definition: arm_adi_v5.h:236
@ DORMANT_TO_JTAG
Definition: arm_adi_v5.h:243
@ JTAG_TO_SWD
Definition: arm_adi_v5.h:238
@ DORMANT_TO_SWD
Definition: arm_adi_v5.h:242
@ LINE_RESET
Definition: arm_adi_v5.h:237
@ JTAG_TO_DORMANT
Definition: arm_adi_v5.h:239
@ SWD_TO_DORMANT
Definition: arm_adi_v5.h:241
@ SWD_TO_JTAG
Definition: arm_adi_v5.h:240
#define SWD_ACK_WAIT
Definition: arm_adi_v5.h:32
#define SWD_ACK_OK
Definition: arm_adi_v5.h:31
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
Definition: binarybuffer.h:104
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:34
static int bitbang_execute_tms(struct jtag_command *cmd)
Clock a bunch of TMS (or SWDIO) transitions, to change the JTAG (or SWD) state machine.
Definition: bitbang.c:93
static int queued_retval
Definition: bitbang.c:389
static int bitbang_stableclocks(unsigned int num_cycles)
Function bitbang_stableclocks issues a number of clock cycles while staying in a stable state.
Definition: bitbang.c:180
static int bitbang_path_move(struct pathmove_command *cmd)
Definition: bitbang.c:114
static int bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, unsigned int scan_size)
Definition: bitbang.c:195
static int bitbang_swd_init(void)
Definition: bitbang.c:391
static void bitbang_swd_exchange(bool rnw, uint8_t buf[], unsigned int offset, unsigned int bit_cnt)
Definition: bitbang.c:397
static int bitbang_runtest(unsigned int num_cycles)
Definition: bitbang.c:150
const struct bitbang_interface * bitbang_interface
Definition: bitbang.c:40
static void bitbang_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
Definition: bitbang.c:532
static int bitbang_swd_switch_seq(enum swd_special_seq seq)
Definition: bitbang.c:427
static void swd_clear_sticky_errors(void)
Definition: bitbang.c:466
#define CLOCK_IDLE()
Definition: bitbang.c:60
int bitbang_execute_queue(struct jtag_command *cmd_queue)
Definition: bitbang.c:293
#define SWD_WAIT_TIMEOUT
Definition: bitbang.c:26
const struct swd_driver bitbang_swd
Definition: bitbang.c:616
static void bitbang_end_state(enum tap_state state)
Definition: bitbang.c:63
static void bitbang_sleep(unsigned int microseconds)
Definition: bitbang.c:284
static int bitbang_state_move(int skip)
Definition: bitbang.c:69
static void bitbang_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
Definition: bitbang.c:472
static int bitbang_swd_run_queue(void)
Definition: bitbang.c:604
@ BB_LOW
Definition: bitbang.h:18
@ BB_HIGH
Definition: bitbang.h:19
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
Definition: commands.c:192
enum scan_type jtag_scan_type(const struct scan_command *cmd)
Definition: commands.c:167
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
Definition: commands.c:230
scan_type
The inferred type of a scan_command structure, indicating whether the command has the host scan in fr...
Definition: commands.h:22
@ SCAN_IN
From device to host,.
Definition: commands.h:24
@ SCAN_OUT
From host to device,.
Definition: commands.h:26
@ JTAG_TLR_RESET
Definition: commands.h:137
@ JTAG_SCAN
Definition: commands.h:129
@ JTAG_PATHMOVE
Definition: commands.h:140
@ JTAG_STABLECLOCKS
Definition: commands.h:142
@ JTAG_RUNTEST
Definition: commands.h:138
@ JTAG_SLEEP
Definition: commands.h:141
@ JTAG_TMS
Definition: commands.h:143
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint8_t type
Definition: esp_usb_jtag.c:0
enum tap_state tap_get_end_state(void)
For more information,.
Definition: interface.c:56
enum tap_state tap_state_transition(enum tap_state cur_state, bool tms)
Function tap_state_transition takes a current TAP state and returns the next state according to the t...
Definition: interface.c:223
const char * tap_state_name(enum tap_state state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
Definition: interface.c:344
int tap_get_tms_path_len(enum tap_state from, enum tap_state to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
Definition: interface.c:195
void tap_set_end_state(enum tap_state new_end_state)
This function sets the state of an "end state follower" which tracks the state that any cable driver ...
Definition: interface.c:48
enum tap_state tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
Definition: interface.c:37
bool tap_is_state_stable(enum tap_state astate)
Function tap_is_state_stable returns true if the astate is stable.
Definition: interface.c:200
int tap_get_tms_path(enum tap_state from, enum tap_state to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
Definition: interface.c:190
#define tap_set_state(new_state)
This function sets the state of a "state follower" which tracks the state of the TAPs connected to th...
Definition: interface.h:50
void jtag_sleep(uint32_t us)
Definition: jtag/core.c:1070
The JTAG interface can be implemented with a software or hardware fifo.
tap_state
Defines JTAG Test Access Port states.
Definition: jtag.h:37
@ TAP_RESET
Definition: jtag.h:56
@ TAP_IRSHIFT
Definition: jtag.h:51
@ TAP_IDLE
Definition: jtag.h:53
@ TAP_DRSHIFT
Definition: jtag.h:43
#define ERROR_JTAG_QUEUE_FAILED
Definition: jtag.h:556
void alive_sleep(uint64_t ms)
Definition: log.c:478
#define LOG_CUSTOM_LEVEL(level, expr ...)
Definition: log.h:132
#define LOG_DEBUG_IO(expr ...)
Definition: log.h:116
#define ERROR_FAIL
Definition: log.h:188
#define LOG_ERROR(expr ...)
Definition: log.h:147
#define LOG_DEBUG(expr ...)
Definition: log.h:124
#define ERROR_OK
Definition: log.h:182
@ LOG_LVL_DEBUG
Definition: log.h:55
@ LOG_LVL_DEBUG_IO
Definition: log.h:56
uint8_t bits[QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
Definition: qn908x.c:0
Low level callbacks (for bitbang).
Definition: bitbang.h:30
int(* sleep)(unsigned int microseconds)
Sleep for some number of microseconds.
Definition: bitbang.h:60
enum bb_value(* read)(void)
Sample TDO and return the value.
Definition: bitbang.h:32
int(* swdio_read)(void)
Sample SWDIO and return the value.
Definition: bitbang.h:51
int(* swd_write)(int swclk, int swdio)
Set SWCLK and SWDIO to the given value.
Definition: bitbang.h:57
int(* sample)(void)
Sample TDO and put the result in a buffer.
Definition: bitbang.h:39
enum bb_value(* read_sample)(void)
Return the next unread value from the buffer.
Definition: bitbang.h:42
int(* flush)(void)
Force a flush.
Definition: bitbang.h:63
int(* write)(int tck, int tms, int tdi)
Set TCK, TMS, and TDI to the given values.
Definition: bitbang.h:45
void(* swdio_drive)(bool on)
Set direction of SWDIO.
Definition: bitbang.h:54
int(* blink)(bool on)
Blink led (optional).
Definition: bitbang.h:48
size_t buf_size
The number of TDO samples that can be buffered up before the caller has to call read_sample.
Definition: bitbang.h:36
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
Definition: swd.h:255
Definition: psoc6.c:83
static const unsigned int swd_seq_dormant_to_swd_len
Definition: swd.h:190
static const uint8_t swd_seq_dormant_to_jtag[]
Dormant-to-JTAG sequence.
Definition: swd.h:230
#define SWD_CMD_A32
Definition: swd.h:19
static const uint8_t swd_seq_dormant_to_swd[]
Dormant-to-SWD sequence.
Definition: swd.h:171
static const uint8_t swd_seq_jtag_to_dormant[]
JTAG-to-dormant sequence.
Definition: swd.h:199
static bool swd_cmd_returns_ack(uint8_t cmd)
Test if we can rely on ACK returned by SWD command.
Definition: swd.h:58
#define SWD_CMD_PARK
Definition: swd.h:22
static int swd_ack_to_error_code(uint8_t ack)
Convert SWD ACK value returned from DP to OpenOCD error code.
Definition: swd.h:72
static uint8_t swd_cmd(bool is_read, bool is_ap, uint8_t regnum)
Construct a "cmd" byte, in lSB bit order, which swd_driver.read_reg() and swd_driver....
Definition: swd.h:35
static const unsigned int swd_seq_jtag_to_swd_len
Definition: swd.h:125
static const unsigned int swd_seq_line_reset_len
Definition: swd.h:104
static const unsigned int swd_seq_dormant_to_jtag_len
Definition: swd.h:244
#define SWD_CMD_APNDP
Definition: swd.h:17
static const unsigned int swd_seq_swd_to_dormant_len
Definition: swd.h:159
#define SWD_CMD_START
Definition: swd.h:16
#define SWD_CMD_RNW
Definition: swd.h:18
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
Definition: swd.h:98
static const uint8_t swd_seq_jtag_to_swd[]
JTAG-to-SWD sequence.
Definition: swd.h:115
static const uint8_t swd_seq_swd_to_jtag[]
SWD-to-JTAG sequence.
Definition: swd.h:136
static const unsigned int swd_seq_swd_to_jtag_len
Definition: swd.h:144
static const unsigned int swd_seq_jtag_to_dormant_len
Definition: swd.h:211
static const uint8_t swd_seq_swd_to_dormant[]
SWD-to-dormant sequence.
Definition: swd.h:153
int64_t timeval_ms(void)
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
Definition: types.h:79
static int parity_u32(uint32_t x)
Calculate the (even) parity of a 32-bit datum.
Definition: types.h:265
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
uint8_t offset[4]
Definition: vdebug.c:9
uint8_t state[4]
Definition: vdebug.c:21
static unsigned int parity(unsigned int v)
Definition: xscale.c:624