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 "bitbang.h"
19 #include <jtag/interface.h>
20 #include <jtag/commands.h>
21 
30 static int bitbang_stableclocks(int num_cycles);
31 
32 static void bitbang_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk);
33 
35 
36 /* DANGER!!!! clock absolutely *MUST* be 0 in idle or reset won't work!
37  *
38  * Set this to 1 and str912 reset halt will fail.
39  *
40  * If someone can submit a patch with an explanation it will be greatly
41  * appreciated, but as far as I can tell (ØH) DCLK is generated upon
42  * clk = 0 in TAP_IDLE. Good luck deducing that from the ARM documentation!
43  * The ARM documentation uses the term "DCLK is asserted while in the TAP_IDLE
44  * state". With hardware there is no such thing as *while* in a state. There
45  * are only edges. So clk => 0 is in fact a very subtle state transition that
46  * happens *while* in the TAP_IDLE state. "#&¤"#¤&"#&"#&
47  *
48  * For "reset halt" the last thing that happens before srst is asserted
49  * is that the breakpoint is set up. If DCLK is not wiggled one last
50  * time before the reset, then the breakpoint is not set up and
51  * "reset halt" will fail to halt.
52  *
53  */
54 #define CLOCK_IDLE() 0
55 
56 /* The bitbang driver leaves the TCK 0 when in idle */
58 {
59  assert(tap_is_state_stable(state));
61 }
62 
63 static int bitbang_state_move(int skip)
64 {
65  int i = 0, tms = 0;
66  uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
68 
69  for (i = skip; i < tms_count; i++) {
70  tms = (tms_scan >> i) & 1;
71  if (bitbang_interface->write(0, tms, 0) != ERROR_OK)
72  return ERROR_FAIL;
73  if (bitbang_interface->write(1, tms, 0) != ERROR_OK)
74  return ERROR_FAIL;
75  }
76  if (bitbang_interface->write(CLOCK_IDLE(), tms, 0) != ERROR_OK)
77  return ERROR_FAIL;
78 
80  return ERROR_OK;
81 }
82 
88 {
89  unsigned num_bits = cmd->cmd.tms->num_bits;
90  const uint8_t *bits = cmd->cmd.tms->bits;
91 
92  LOG_DEBUG_IO("TMS: %d bits", num_bits);
93 
94  int tms = 0;
95  for (unsigned i = 0; i < num_bits; i++) {
96  tms = ((bits[i/8] >> (i % 8)) & 1);
97  if (bitbang_interface->write(0, tms, 0) != ERROR_OK)
98  return ERROR_FAIL;
99  if (bitbang_interface->write(1, tms, 0) != ERROR_OK)
100  return ERROR_FAIL;
101  }
102  if (bitbang_interface->write(CLOCK_IDLE(), tms, 0) != ERROR_OK)
103  return ERROR_FAIL;
104 
105  return ERROR_OK;
106 }
107 
109 {
110  int num_states = cmd->num_states;
111  int state_count;
112  int tms = 0;
113 
114  state_count = 0;
115  while (num_states) {
116  if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count])
117  tms = 0;
118  else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count])
119  tms = 1;
120  else {
121  LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
123  tap_state_name(cmd->path[state_count]));
124  exit(-1);
125  }
126 
127  if (bitbang_interface->write(0, tms, 0) != ERROR_OK)
128  return ERROR_FAIL;
129  if (bitbang_interface->write(1, tms, 0) != ERROR_OK)
130  return ERROR_FAIL;
131 
132  tap_set_state(cmd->path[state_count]);
133  state_count++;
134  num_states--;
135  }
136 
137  if (bitbang_interface->write(CLOCK_IDLE(), tms, 0) != ERROR_OK)
138  return ERROR_FAIL;
139 
141  return ERROR_OK;
142 }
143 
144 static int bitbang_runtest(int num_cycles)
145 {
146  int i;
147 
148  tap_state_t saved_end_state = tap_get_end_state();
149 
150  /* only do a state_move when we're not already in IDLE */
151  if (tap_get_state() != TAP_IDLE) {
153  if (bitbang_state_move(0) != ERROR_OK)
154  return ERROR_FAIL;
155  }
156 
157  /* execute num_cycles */
158  for (i = 0; i < num_cycles; i++) {
159  if (bitbang_interface->write(0, 0, 0) != ERROR_OK)
160  return ERROR_FAIL;
161  if (bitbang_interface->write(1, 0, 0) != ERROR_OK)
162  return ERROR_FAIL;
163  }
164  if (bitbang_interface->write(CLOCK_IDLE(), 0, 0) != ERROR_OK)
165  return ERROR_FAIL;
166 
167  /* finish in end_state */
168  bitbang_end_state(saved_end_state);
169  if (tap_get_state() != tap_get_end_state())
170  if (bitbang_state_move(0) != ERROR_OK)
171  return ERROR_FAIL;
172 
173  return ERROR_OK;
174 }
175 
176 static int bitbang_stableclocks(int num_cycles)
177 {
178  int tms = (tap_get_state() == TAP_RESET ? 1 : 0);
179  int i;
180 
181  /* send num_cycles clocks onto the cable */
182  for (i = 0; i < num_cycles; i++) {
183  if (bitbang_interface->write(1, tms, 0) != ERROR_OK)
184  return ERROR_FAIL;
185  if (bitbang_interface->write(0, tms, 0) != ERROR_OK)
186  return ERROR_FAIL;
187  }
188 
189  return ERROR_OK;
190 }
191 
192 static int bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer,
193  unsigned scan_size)
194 {
195  tap_state_t saved_end_state = tap_get_end_state();
196  unsigned bit_cnt;
197 
198  if (!((!ir_scan &&
199  (tap_get_state() == TAP_DRSHIFT)) ||
200  (ir_scan && (tap_get_state() == TAP_IRSHIFT)))) {
201  if (ir_scan)
203  else
205 
206  if (bitbang_state_move(0) != ERROR_OK)
207  return ERROR_FAIL;
208  bitbang_end_state(saved_end_state);
209  }
210 
211  size_t buffered = 0;
212  for (bit_cnt = 0; bit_cnt < scan_size; bit_cnt++) {
213  int tms = (bit_cnt == scan_size-1) ? 1 : 0;
214  int tdi;
215  int bytec = bit_cnt/8;
216  int bcval = 1 << (bit_cnt % 8);
217 
218  /* if we're just reading the scan, but don't care about the output
219  * default to outputting 'low', this also makes valgrind traces more readable,
220  * as it removes the dependency on an uninitialised value
221  */
222  tdi = 0;
223  if ((type != SCAN_IN) && (buffer[bytec] & bcval))
224  tdi = 1;
225 
226  if (bitbang_interface->write(0, tms, tdi) != ERROR_OK)
227  return ERROR_FAIL;
228 
229  if (type != SCAN_OUT) {
232  return ERROR_FAIL;
233  buffered++;
234  } else {
235  switch (bitbang_interface->read()) {
236  case BB_LOW:
237  buffer[bytec] &= ~bcval;
238  break;
239  case BB_HIGH:
240  buffer[bytec] |= bcval;
241  break;
242  default:
243  return ERROR_FAIL;
244  }
245  }
246  }
247 
248  if (bitbang_interface->write(1, tms, tdi) != ERROR_OK)
249  return ERROR_FAIL;
250 
252  (buffered == bitbang_interface->buf_size ||
253  bit_cnt == scan_size - 1)) {
254  for (unsigned i = bit_cnt + 1 - buffered; i <= bit_cnt; i++) {
255  switch (bitbang_interface->read_sample()) {
256  case BB_LOW:
257  buffer[i/8] &= ~(1 << (i % 8));
258  break;
259  case BB_HIGH:
260  buffer[i/8] |= 1 << (i % 8);
261  break;
262  default:
263  return ERROR_FAIL;
264  }
265  }
266  buffered = 0;
267  }
268  }
269 
270  if (tap_get_state() != tap_get_end_state()) {
271  /* we *KNOW* the above loop transitioned out of
272  * the shift state, so we skip the first state
273  * and move directly to the end state.
274  */
275  if (bitbang_state_move(1) != ERROR_OK)
276  return ERROR_FAIL;
277  }
278  return ERROR_OK;
279 }
280 
282 {
283  struct jtag_command *cmd = jtag_command_queue; /* currently processed command */
284  int scan_size;
285  enum scan_type type;
286  uint8_t *buffer;
287  int retval;
288 
289  if (!bitbang_interface) {
290  LOG_ERROR("BUG: Bitbang interface called, but not yet initialized");
291  exit(-1);
292  }
293 
294  /* return ERROR_OK, unless a jtag_read_buffer returns a failed check
295  * that wasn't handled by a caller-provided error handler
296  */
297  retval = ERROR_OK;
298 
299  if (bitbang_interface->blink) {
300  if (bitbang_interface->blink(1) != ERROR_OK)
301  return ERROR_FAIL;
302  }
303 
304  while (cmd) {
305  switch (cmd->type) {
306  case JTAG_RUNTEST:
307  LOG_DEBUG_IO("runtest %i cycles, end in %s",
308  cmd->cmd.runtest->num_cycles,
309  tap_state_name(cmd->cmd.runtest->end_state));
310  bitbang_end_state(cmd->cmd.runtest->end_state);
311  if (bitbang_runtest(cmd->cmd.runtest->num_cycles) != ERROR_OK)
312  return ERROR_FAIL;
313  break;
314 
315  case JTAG_STABLECLOCKS:
316  /* this is only allowed while in a stable state. A check for a stable
317  * state was done in jtag_add_clocks()
318  */
319  if (bitbang_stableclocks(cmd->cmd.stableclocks->num_cycles) != ERROR_OK)
320  return ERROR_FAIL;
321  break;
322 
323  case JTAG_TLR_RESET:
324  LOG_DEBUG_IO("statemove end in %s",
325  tap_state_name(cmd->cmd.statemove->end_state));
326  bitbang_end_state(cmd->cmd.statemove->end_state);
327  if (bitbang_state_move(0) != ERROR_OK)
328  return ERROR_FAIL;
329  break;
330  case JTAG_PATHMOVE:
331  LOG_DEBUG_IO("pathmove: %i states, end in %s",
332  cmd->cmd.pathmove->num_states,
333  tap_state_name(cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]));
334  if (bitbang_path_move(cmd->cmd.pathmove) != ERROR_OK)
335  return ERROR_FAIL;
336  break;
337  case JTAG_SCAN:
338  bitbang_end_state(cmd->cmd.scan->end_state);
339  scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
340  LOG_DEBUG_IO("%s scan %d bits; end in %s",
341  (cmd->cmd.scan->ir_scan) ? "IR" : "DR",
342  scan_size,
343  tap_state_name(cmd->cmd.scan->end_state));
344  type = jtag_scan_type(cmd->cmd.scan);
345  if (bitbang_scan(cmd->cmd.scan->ir_scan, type, buffer,
346  scan_size) != ERROR_OK)
347  return ERROR_FAIL;
348  if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
349  retval = ERROR_JTAG_QUEUE_FAILED;
350  free(buffer);
351  break;
352  case JTAG_SLEEP:
353  LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
354  jtag_sleep(cmd->cmd.sleep->us);
355  break;
356  case JTAG_TMS:
357  retval = bitbang_execute_tms(cmd);
358  break;
359  default:
360  LOG_ERROR("BUG: unknown JTAG command type encountered");
361  exit(-1);
362  }
363  cmd = cmd->next;
364  }
365  if (bitbang_interface->blink) {
366  if (bitbang_interface->blink(0) != ERROR_OK)
367  return ERROR_FAIL;
368  }
369 
370  return retval;
371 }
372 
373 static int queued_retval;
374 
375 static int bitbang_swd_init(void)
376 {
377  LOG_DEBUG("bitbang_swd_init");
378  return ERROR_OK;
379 }
380 
381 static void bitbang_swd_exchange(bool rnw, uint8_t buf[], unsigned int offset, unsigned int bit_cnt)
382 {
383  if (bitbang_interface->blink) {
384  /* FIXME: we should manage errors */
386  }
387 
388  for (unsigned int i = offset; i < bit_cnt + offset; i++) {
389  int bytec = i/8;
390  int bcval = 1 << (i % 8);
391  int swdio = !rnw && (buf[bytec] & bcval);
392 
393  bitbang_interface->swd_write(0, swdio);
394 
395  if (rnw && buf) {
397  buf[bytec] |= bcval;
398  else
399  buf[bytec] &= ~bcval;
400  }
401 
402  bitbang_interface->swd_write(1, swdio);
403  }
404 
405  if (bitbang_interface->blink) {
406  /* FIXME: we should manage errors */
408  }
409 }
410 
412 {
413  switch (seq) {
414  case LINE_RESET:
415  LOG_DEBUG_IO("SWD line reset");
417  break;
418  case JTAG_TO_SWD:
419  LOG_DEBUG("JTAG-to-SWD");
421  break;
422  case JTAG_TO_DORMANT:
423  LOG_DEBUG("JTAG-to-DORMANT");
425  break;
426  case SWD_TO_JTAG:
427  LOG_DEBUG("SWD-to-JTAG");
429  break;
430  case SWD_TO_DORMANT:
431  LOG_DEBUG("SWD-to-DORMANT");
433  break;
434  case DORMANT_TO_SWD:
435  LOG_DEBUG("DORMANT-to-SWD");
437  break;
438  case DORMANT_TO_JTAG:
439  LOG_DEBUG("DORMANT-to-JTAG");
441  break;
442  default:
443  LOG_ERROR("Sequence %d not supported", seq);
444  return ERROR_FAIL;
445  }
446 
447  return ERROR_OK;
448 }
449 
450 static void swd_clear_sticky_errors(void)
451 {
452  bitbang_swd_write_reg(swd_cmd(false, false, DP_ABORT),
454 }
455 
456 static void bitbang_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
457 {
458  assert(cmd & SWD_CMD_RNW);
459 
460  if (queued_retval != ERROR_OK) {
461  LOG_DEBUG("Skip bitbang_swd_read_reg because queued_retval=%d", queued_retval);
462  return;
463  }
464 
465  for (;;) {
466  uint8_t trn_ack_data_parity_trn[DIV_ROUND_UP(4 + 3 + 32 + 1 + 4, 8)];
467 
469  bitbang_swd_exchange(false, &cmd, 0, 8);
470 
472  bitbang_swd_exchange(true, trn_ack_data_parity_trn, 0, 1 + 3 + 32 + 1 + 1);
474 
475  int ack = buf_get_u32(trn_ack_data_parity_trn, 1, 3);
476  uint32_t data = buf_get_u32(trn_ack_data_parity_trn, 1 + 3, 32);
477  int parity = buf_get_u32(trn_ack_data_parity_trn, 1 + 3 + 32, 1);
478 
479  LOG_DEBUG_IO("%s %s read reg %X = %08" PRIx32,
480  ack == SWD_ACK_OK ? "OK" : ack == SWD_ACK_WAIT ? "WAIT" : ack == SWD_ACK_FAULT ? "FAULT" : "JUNK",
481  cmd & SWD_CMD_APNDP ? "AP" : "DP",
482  (cmd & SWD_CMD_A32) >> 1,
483  data);
484 
485  if (ack == SWD_ACK_WAIT) {
487  continue;
488  } else if (ack != SWD_ACK_OK) {
490  return;
491  }
492 
493  if (parity != parity_u32(data)) {
494  LOG_ERROR("Wrong parity detected");
496  return;
497  }
498  if (value)
499  *value = data;
500  if (cmd & SWD_CMD_APNDP)
501  bitbang_swd_exchange(true, NULL, 0, ap_delay_clk);
502  return;
503  }
504 }
505 
506 static void bitbang_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
507 {
508  assert(!(cmd & SWD_CMD_RNW));
509 
510  if (queued_retval != ERROR_OK) {
511  LOG_DEBUG("Skip bitbang_swd_write_reg because queued_retval=%d", queued_retval);
512  return;
513  }
514 
515  /* Devices do not reply to DP_TARGETSEL write cmd, ignore received ack */
516  bool check_ack = swd_cmd_returns_ack(cmd);
517 
518  /* init the array to silence scan-build */
519  uint8_t trn_ack_data_parity_trn[DIV_ROUND_UP(4 + 3 + 32 + 1 + 4, 8)] = {0};
520  for (;;) {
521  buf_set_u32(trn_ack_data_parity_trn, 1 + 3 + 1, 32, value);
522  buf_set_u32(trn_ack_data_parity_trn, 1 + 3 + 1 + 32, 1, parity_u32(value));
523 
525  bitbang_swd_exchange(false, &cmd, 0, 8);
526 
528  bitbang_swd_exchange(true, trn_ack_data_parity_trn, 0, 1 + 3 + 1);
530  bitbang_swd_exchange(false, trn_ack_data_parity_trn, 1 + 3 + 1, 32 + 1);
531 
532  int ack = buf_get_u32(trn_ack_data_parity_trn, 1, 3);
533 
534  LOG_DEBUG_IO("%s%s %s write reg %X = %08" PRIx32,
535  check_ack ? "" : "ack ignored ",
536  ack == SWD_ACK_OK ? "OK" : ack == SWD_ACK_WAIT ? "WAIT" : ack == SWD_ACK_FAULT ? "FAULT" : "JUNK",
537  cmd & SWD_CMD_APNDP ? "AP" : "DP",
538  (cmd & SWD_CMD_A32) >> 1,
539  buf_get_u32(trn_ack_data_parity_trn, 1 + 3 + 1, 32));
540 
541  if (check_ack) {
542  if (ack == SWD_ACK_WAIT) {
544  continue;
545  } else if (ack != SWD_ACK_OK) {
547  return;
548  }
549  }
550 
551  if (cmd & SWD_CMD_APNDP)
552  bitbang_swd_exchange(true, NULL, 0, ap_delay_clk);
553  return;
554  }
555 }
556 
557 static int bitbang_swd_run_queue(void)
558 {
559  /* A transaction must be followed by another transaction or at least 8 idle cycles to
560  * ensure that data is clocked through the AP. */
561  bitbang_swd_exchange(true, NULL, 0, 8);
562 
563  int retval = queued_retval;
565  LOG_DEBUG_IO("SWD queue return value: %02x", retval);
566  return retval;
567 }
568 
569 const struct swd_driver bitbang_swd = {
571  .switch_seq = bitbang_swd_switch_seq,
572  .read_reg = bitbang_swd_read_reg,
573  .write_reg = bitbang_swd_write_reg,
574  .run = bitbang_swd_run_queue,
575 };
#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:229
@ DORMANT_TO_JTAG
Definition: arm_adi_v5.h:236
@ JTAG_TO_SWD
Definition: arm_adi_v5.h:231
@ DORMANT_TO_SWD
Definition: arm_adi_v5.h:235
@ LINE_RESET
Definition: arm_adi_v5.h:230
@ JTAG_TO_DORMANT
Definition: arm_adi_v5.h:232
@ SWD_TO_DORMANT
Definition: arm_adi_v5.h:234
@ SWD_TO_JTAG
Definition: arm_adi_v5.h:233
#define SWD_ACK_WAIT
Definition: arm_adi_v5.h:32
#define SWD_ACK_OK
Definition: arm_adi_v5.h:31
uint32_t bits
Definition: armv4_5.c:359
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
Definition: binarybuffer.h:98
static void buf_set_u32(uint8_t *_buffer, unsigned first, unsigned num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:30
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:87
static int queued_retval
Definition: bitbang.c:373
struct bitbang_interface * bitbang_interface
Definition: bitbang.c:34
static int bitbang_path_move(struct pathmove_command *cmd)
Definition: bitbang.c:108
int bitbang_execute_queue(void)
Definition: bitbang.c:281
static int bitbang_swd_init(void)
Definition: bitbang.c:375
static void bitbang_swd_exchange(bool rnw, uint8_t buf[], unsigned int offset, unsigned int bit_cnt)
Definition: bitbang.c:381
static void bitbang_end_state(tap_state_t state)
Definition: bitbang.c:57
static int bitbang_runtest(int num_cycles)
Definition: bitbang.c:144
static void bitbang_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
Definition: bitbang.c:506
static int bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, unsigned scan_size)
Definition: bitbang.c:192
static int bitbang_swd_switch_seq(enum swd_special_seq seq)
Definition: bitbang.c:411
static void swd_clear_sticky_errors(void)
Definition: bitbang.c:450
#define CLOCK_IDLE()
Definition: bitbang.c:54
static int bitbang_stableclocks(int num_cycles)
Function bitbang_stableclocks issues a number of clock cycles while staying in a stable state.
Definition: bitbang.c:176
const struct swd_driver bitbang_swd
Definition: bitbang.c:569
static int bitbang_state_move(int skip)
Definition: bitbang.c:63
static void bitbang_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
Definition: bitbang.c:456
static int bitbang_swd_run_queue(void)
Definition: bitbang.c:557
@ BB_LOW
Definition: bitbang.h:17
@ BB_HIGH
Definition: bitbang.h:18
struct jtag_command * jtag_command_queue
The current queue of jtag_command_s structures.
Definition: commands.c:36
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
Definition: commands.c:189
enum scan_type jtag_scan_type(const struct scan_command *cmd)
Definition: commands.c:162
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_s structure, indicating whether the command has the host scan in ...
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
uint8_t type
Definition: esp_usb_jtag.c:0
bool tap_is_state_stable(tap_state_t astate)
Function tap_is_state_stable returns true if the astate is stable.
Definition: interface.c:200
tap_state_t tap_state_transition(tap_state_t 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(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
Definition: interface.c:344
void tap_set_end_state(tap_state_t 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
tap_state_t tap_get_end_state(void)
For more information,.
Definition: interface.c:56
int tap_get_tms_path(tap_state_t from, tap_state_t to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
Definition: interface.c:190
int tap_get_tms_path_len(tap_state_t from, tap_state_t to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
Definition: interface.c:195
tap_state_t 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
#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:49
void jtag_sleep(uint32_t us)
Definition: jtag/core.c:1062
@ TAP_RESET
Definition: jtag.h:55
@ TAP_IRSHIFT
Definition: jtag.h:50
@ TAP_IDLE
Definition: jtag.h:52
@ TAP_DRSHIFT
Definition: jtag.h:42
#define ERROR_JTAG_QUEUE_FAILED
Definition: jtag.h:553
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
#define LOG_DEBUG_IO(expr ...)
Definition: log.h:101
#define ERROR_FAIL
Definition: log.h:161
#define LOG_ERROR(expr ...)
Definition: log.h:123
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:155
Low level callbacks (for bitbang).
Definition: bitbang.h:29
int(* swdio_read)(void)
Sample SWDIO and return the value.
Definition: bitbang.h:50
int(* swd_write)(int swclk, int swdio)
Set SWCLK and SWDIO to the given value.
Definition: bitbang.h:56
int(* sample)(void)
Sample TDO and put the result in a buffer.
Definition: bitbang.h:38
bb_value_t(* read)(void)
Sample TDO and return the value.
Definition: bitbang.h:31
bb_value_t(* read_sample)(void)
Return the next unread value from the buffer.
Definition: bitbang.h:41
int(* write)(int tck, int tms, int tdi)
Set TCK, TMS, and TDI to the given values.
Definition: bitbang.h:44
void(* swdio_drive)(bool on)
Set direction of SWDIO.
Definition: bitbang.h:53
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:35
int(* blink)(int on)
Blink led (optional).
Definition: bitbang.h:47
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
Definition: swd.h:255
static const unsigned swd_seq_swd_to_jtag_len
Definition: swd.h:144
static const unsigned swd_seq_jtag_to_swd_len
Definition: swd.h:125
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 const unsigned swd_seq_dormant_to_swd_len
Definition: swd.h:190
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
#define SWD_CMD_APNDP
Definition: swd.h:17
static const unsigned swd_seq_jtag_to_dormant_len
Definition: swd.h:211
#define SWD_CMD_START
Definition: swd.h:16
#define SWD_CMD_RNW
Definition: swd.h:18
static const unsigned swd_seq_dormant_to_jtag_len
Definition: swd.h:244
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
Definition: swd.h:98
static const unsigned swd_seq_line_reset_len
Definition: swd.h:104
static const unsigned swd_seq_swd_to_dormant_len
Definition: swd.h:159
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 uint8_t swd_seq_swd_to_dormant[]
SWD-to-dormant sequence.
Definition: swd.h:153
#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:623