OpenOCD
adapter.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2005 by Dominic Rath <Dominic.Rath@gmx.de>
4  * Copyright (C) 2007-2010 Øyvind Harboe <oyvind.harboe@zylin.com>
5  * Copyright (C) 2009 SoftPLC Corporation, http://softplc.com, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2009 Zachary T Welch <zw@superlucidity.net>
7  * Copyright (C) 2018 Pengutronix, Oleksij Rempel <kernel@pengutronix.de>
8  */
9 
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
13 
14 #include "adapter.h"
15 #include "jtag.h"
16 #include "minidriver.h"
17 #include "interface.h"
18 #include "interfaces.h"
19 #include <helper/bits.h>
20 #include <transport/transport.h>
21 
28 
33 };
34 
35 #define DEFAULT_CLOCK_SPEED_KHZ 100U
36 
40 static struct {
42  char *usb_location;
43  char *serial;
45  int speed_khz;
48  bool gpios_initialized; /* Initialization of GPIOs to their unset values performed at run time */
50 
51 static const struct gpio_map {
52  const char *name;
57  [ADAPTER_GPIO_IDX_TDO] = { "tdo", ADAPTER_GPIO_DIRECTION_INPUT, false, true, },
58  [ADAPTER_GPIO_IDX_TDI] = { "tdi", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, },
59  [ADAPTER_GPIO_IDX_TMS] = { "tms", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, },
60  [ADAPTER_GPIO_IDX_TCK] = { "tck", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, },
62  [ADAPTER_GPIO_IDX_SWDIO_DIR] = { "swdio_dir", ADAPTER_GPIO_DIRECTION_OUTPUT, true, false, },
63  [ADAPTER_GPIO_IDX_SWCLK] = { "swclk", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, },
64  [ADAPTER_GPIO_IDX_TRST] = { "trst", ADAPTER_GPIO_DIRECTION_OUTPUT, false, true, },
65  [ADAPTER_GPIO_IDX_SRST] = { "srst", ADAPTER_GPIO_DIRECTION_OUTPUT, false, true, },
66  [ADAPTER_GPIO_IDX_LED] = { "led", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, },
67 };
68 
69 static int adapter_config_khz(unsigned int khz);
70 
72 {
73  return adapter_config.adapter_initialized;
74 }
75 
76 /* For convenience of the bit-banging drivers keep the gpio_config drive
77  * settings for srst and trst in sync with values set by the "adapter
78  * reset_config" command.
79  */
81 {
83  if (cfg & RESET_SRST_PUSH_PULL)
85  else
87  if (cfg & RESET_TRST_OPEN_DRAIN)
89  else
91 }
92 
93 static void adapter_driver_gpios_init(void)
94 {
95  if (adapter_config.gpios_initialized)
96  return;
97 
98  for (int i = 0; i < ADAPTER_GPIO_IDX_NUM; ++i) {
99  /* Use ADAPTER_GPIO_NOT_SET as the sentinel 'unset' value. */
100  adapter_config.gpios[i].gpio_num = ADAPTER_GPIO_NOT_SET;
101  adapter_config.gpios[i].chip_num = ADAPTER_GPIO_NOT_SET;
103  adapter_config.gpios[i].init_state = ADAPTER_GPIO_INIT_STATE_INPUT;
104  }
105 
106  /* Drivers assume active low, and this is the normal behaviour for reset
107  * lines so should be the default. */
108  adapter_config.gpios[ADAPTER_GPIO_IDX_SRST].active_low = true;
109  adapter_config.gpios[ADAPTER_GPIO_IDX_TRST].active_low = true;
111 
112  /* JTAG GPIOs should be inactive except for tms */
114 
115  adapter_config.gpios_initialized = true;
116 }
117 
122 int adapter_init(struct command_context *cmd_ctx)
123 {
125  return ERROR_OK;
126 
127  if (!adapter_driver) {
128  /* nothing was previously specified by "adapter driver" command */
129  LOG_ERROR("Debug Adapter has to be specified, "
130  "see \"adapter driver\" command");
132  }
133 
135 
136  int retval;
137 
138  /* If the adapter supports configurable speed but the speed is not configured,
139  * provide a hint to the user. */
141  LOG_WARNING("An adapter speed is not selected in the init scripts."
142  " OpenOCD will try to run the adapter at very low speed (%d kHz).",
144  LOG_WARNING("To remove this warnings and achieve reasonable communication speed with the target,"
145  " set \"adapter speed\" or \"jtag_rclk\" in the init scripts.");
147  if (retval != ERROR_OK)
148  return ERROR_JTAG_INIT_FAILED;
149  }
150 
151  retval = adapter_driver->init();
152  if (retval != ERROR_OK)
153  return retval;
154  adapter_config.adapter_initialized = true;
155 
156  if (!adapter_driver->speed) {
157  LOG_INFO("Note: The adapter \"%s\" doesn't support configurable speed", adapter_driver->name);
158  return ERROR_OK;
159  }
160 
161  int requested_khz = adapter_get_speed_khz();
162  int actual_khz = requested_khz;
163  int speed_var = 0;
164  retval = adapter_get_speed(&speed_var);
165  if (retval != ERROR_OK)
166  return retval;
167  retval = adapter_driver->speed(speed_var);
168  if (retval != ERROR_OK)
169  return retval;
170  retval = adapter_get_speed_readable(&actual_khz);
171  if (retval != ERROR_OK)
172  LOG_INFO("adapter-specific clock speed value %d", speed_var);
173  else if (actual_khz) {
174  /* Adaptive clocking -- JTAG-specific */
175  if ((adapter_config.clock_mode == CLOCK_MODE_RCLK)
176  || ((adapter_config.clock_mode == CLOCK_MODE_KHZ) && !requested_khz)) {
177  LOG_INFO("RCLK (adaptive clock speed) not supported - fallback to %d kHz"
178  , actual_khz);
179  } else
180  LOG_INFO("clock speed %d kHz", actual_khz);
181  } else
182  LOG_INFO("RCLK (adaptive clock speed)");
183 
184  return ERROR_OK;
185 }
186 
187 int adapter_quit(void)
188 {
190  int result = adapter_driver->quit();
191  if (result != ERROR_OK)
192  LOG_ERROR("failed: %d", result);
193  }
194 
195  free(adapter_config.serial);
196  free(adapter_config.usb_location);
197 
198  struct jtag_tap *t = jtag_all_taps();
199  while (t) {
200  struct jtag_tap *n = t->next_tap;
201  jtag_tap_free(t);
202  t = n;
203  }
204 
205  return ERROR_OK;
206 }
207 
208 unsigned int adapter_get_speed_khz(void)
209 {
210  return adapter_config.speed_khz;
211 }
212 
213 static int adapter_khz_to_speed(unsigned int khz, int *speed)
214 {
215  LOG_DEBUG("convert khz to adapter specific speed value");
216  adapter_config.speed_khz = khz;
217  if (!is_adapter_initialized())
218  return ERROR_OK;
219  LOG_DEBUG("have adapter set up");
220  if (!adapter_driver->khz) {
221  LOG_ERROR("Translation from khz to adapter speed not implemented");
222  return ERROR_FAIL;
223  }
224  int speed_div1;
225  int retval = adapter_driver->khz(adapter_get_speed_khz(), &speed_div1);
226  if (retval != ERROR_OK)
227  return retval;
228  *speed = speed_div1;
229  return ERROR_OK;
230 }
231 
232 static int adapter_rclk_to_speed(unsigned int fallback_speed_khz, int *speed)
233 {
234  int retval = adapter_khz_to_speed(0, speed);
235  if ((retval != ERROR_OK) && fallback_speed_khz) {
236  LOG_DEBUG("trying fallback speed...");
237  retval = adapter_khz_to_speed(fallback_speed_khz, speed);
238  }
239  return retval;
240 }
241 
242 static int adapter_set_speed(int speed)
243 {
244  /* this command can be called during CONFIG,
245  * in which case adapter isn't initialized */
247 }
248 
250 static int adapter_config_khz(unsigned int khz)
251 {
252  LOG_DEBUG("handle adapter khz");
253  adapter_config.clock_mode = CLOCK_MODE_KHZ;
254  int speed = 0;
255  int retval = adapter_khz_to_speed(khz, &speed);
256  return (retval != ERROR_OK) ? retval : adapter_set_speed(speed);
257 }
258 
259 int adapter_config_rclk(unsigned int fallback_speed_khz)
260 {
261  LOG_DEBUG("handle adapter rclk");
262  adapter_config.clock_mode = CLOCK_MODE_RCLK;
263  adapter_config.rclk_fallback_speed_khz = fallback_speed_khz;
264  int speed = 0;
265  int retval = adapter_rclk_to_speed(fallback_speed_khz, &speed);
266  return (retval != ERROR_OK) ? retval : adapter_set_speed(speed);
267 }
268 
269 int adapter_get_speed(int *speed)
270 {
271  switch (adapter_config.clock_mode) {
272  case CLOCK_MODE_KHZ:
274  break;
275  case CLOCK_MODE_RCLK:
276  adapter_rclk_to_speed(adapter_config.rclk_fallback_speed_khz, speed);
277  break;
278  default:
279  LOG_ERROR("BUG: unknown adapter clock mode");
280  return ERROR_FAIL;
281  }
282  return ERROR_OK;
283 }
284 
286 {
287  int speed_var = 0;
288  int retval = adapter_get_speed(&speed_var);
289  if (retval != ERROR_OK)
290  return retval;
291  if (!is_adapter_initialized())
292  return ERROR_OK;
293  if (!adapter_driver->speed_div) {
294  LOG_ERROR("Translation from adapter speed to khz not implemented");
295  return ERROR_FAIL;
296  }
297  return adapter_driver->speed_div(speed_var, khz);
298 }
299 
301 {
302  return adapter_config.serial;
303 }
304 
305 /*
306  * 1 char: bus
307  * 2 * 7 chars: max 7 ports
308  * 1 char: test for overflow
309  * ------
310  * 16 chars
311  */
312 #define USB_MAX_LOCATION_LENGTH 16
313 
314 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
315 static void adapter_usb_set_location(const char *location)
316 {
318  LOG_WARNING("usb location string is too long!!");
319 
320  free(adapter_config.usb_location);
321 
322  adapter_config.usb_location = strndup(location, USB_MAX_LOCATION_LENGTH);
323 }
324 #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */
325 
326 const char *adapter_usb_get_location(void)
327 {
328  return adapter_config.usb_location;
329 }
330 
331 bool adapter_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, size_t path_len)
332 {
333  size_t path_step, string_length;
334  char *ptr, *loc;
335  bool equal = false;
336 
338  return equal;
339 
340  /* strtok need non const char */
342  string_length = strnlen(loc, USB_MAX_LOCATION_LENGTH);
343 
344  ptr = strtok(loc, "-");
345  if (!ptr) {
346  LOG_WARNING("no '-' in usb path\n");
347  goto done;
348  }
349 
350  string_length -= strnlen(ptr, string_length);
351  /* check bus mismatch */
352  if (atoi(ptr) != dev_bus)
353  goto done;
354 
355  path_step = 0;
356  while (path_step < path_len) {
357  ptr = strtok(NULL, ".");
358 
359  /* no more tokens in path */
360  if (!ptr)
361  break;
362 
363  /* path mismatch at some step */
364  if (path_step < path_len && atoi(ptr) != port_path[path_step])
365  break;
366 
367  path_step++;
368  string_length -= strnlen(ptr, string_length) + 1;
369  };
370 
371  /* walked the full path, all elements match */
372  if (path_step == path_len && !string_length)
373  equal = true;
374 
375 done:
376  free(loc);
377  return equal;
378 }
379 
380 COMMAND_HANDLER(handle_adapter_name)
381 {
382  /* return the name of the adapter driver */
383  /* TCL code might need to know the exact type... */
384  /* FUTURE: we allow this as a means to "set" the interface. */
385 
386  if (CMD_ARGC != 0)
388 
389  command_print(CMD, "%s", adapter_driver ? adapter_driver->name : "undefined");
390 
391  return ERROR_OK;
392 }
393 
394 COMMAND_HANDLER(dump_adapter_driver_list)
395 {
396  int max_len = 0;
397  for (unsigned int i = 0; adapter_drivers[i]; i++) {
398  int len = strlen(adapter_drivers[i]->name);
399  if (max_len < len)
400  max_len = len;
401  }
402 
403  for (unsigned int i = 0; adapter_drivers[i]; i++) {
404  const char *name = adapter_drivers[i]->name;
405  unsigned int transport_ids = adapter_drivers[i]->transport_ids;
406 
407  command_print_sameline(CMD, "%-*s {", max_len, name);
408  for (unsigned int j = BIT(0); j & TRANSPORT_VALID_MASK; j <<= 1)
409  if (j & transport_ids)
411  command_print(CMD, " }");
412  }
413 
414  return ERROR_OK;
415 }
416 
417 COMMAND_HANDLER(handle_adapter_list_command)
418 {
419  if (CMD_ARGC)
421 
422  return CALL_COMMAND_HANDLER(dump_adapter_driver_list);
423 }
424 
425 COMMAND_HANDLER(handle_adapter_driver_command)
426 {
427  int retval;
428 
429  /* check whether the adapter driver is already configured */
430  if (adapter_driver) {
431  LOG_WARNING("Adapter driver already configured, ignoring");
432  return ERROR_OK;
433  }
434 
435  /* adapter driver name is a mandatory argument */
436  if (CMD_ARGC != 1)
438 
439  for (unsigned int i = 0; adapter_drivers[i]; i++) {
440  if (strcmp(CMD_ARGV[0], adapter_drivers[i]->name) != 0)
441  continue;
442 
443  if (adapter_drivers[i]->commands) {
444  retval = register_commands(CMD_CTX, NULL, adapter_drivers[i]->commands);
445  if (retval != ERROR_OK)
446  return retval;
447  }
448 
450 
453  }
454 
455  /* no valid adapter driver was found (i.e. the configuration option,
456  * didn't match one of the compiled-in drivers
457  */
458  LOG_ERROR("The specified adapter driver was not found (%s)",
459  CMD_ARGV[0]);
460  command_print(CMD, "The following adapter drivers are available:");
461  CALL_COMMAND_HANDLER(dump_adapter_driver_list);
463 }
464 
465 COMMAND_HANDLER(handle_reset_config_command)
466 {
467  int new_cfg = 0;
468  int mask = 0;
469 
470  /* Original versions cared about the order of these tokens:
471  * reset_config signals [combination [trst_type [srst_type]]]
472  * They also clobbered the previous configuration even on error.
473  *
474  * Here we don't care about the order, and only change values
475  * which have been explicitly specified.
476  */
477  for (; CMD_ARGC; CMD_ARGC--, CMD_ARGV++) {
478  int tmp = 0;
479  int m;
480 
481  /* gating */
483  if (strcmp(*CMD_ARGV, "srst_gates_jtag") == 0)
484  /* default: don't use JTAG while SRST asserted */;
485  else if (strcmp(*CMD_ARGV, "srst_nogate") == 0)
486  tmp = RESET_SRST_NO_GATING;
487  else
488  m = 0;
489  if (mask & m) {
490  LOG_ERROR("extra reset_config %s spec (%s)",
491  "gating", *CMD_ARGV);
493  }
494  if (m)
495  goto next;
496 
497  /* signals */
499  if (strcmp(*CMD_ARGV, "none") == 0)
500  tmp = RESET_NONE;
501  else if (strcmp(*CMD_ARGV, "trst_only") == 0)
502  tmp = RESET_HAS_TRST;
503  else if (strcmp(*CMD_ARGV, "srst_only") == 0)
504  tmp = RESET_HAS_SRST;
505  else if (strcmp(*CMD_ARGV, "trst_and_srst") == 0)
507  else
508  m = 0;
509  if (mask & m) {
510  LOG_ERROR("extra reset_config %s spec (%s)",
511  "signal", *CMD_ARGV);
513  }
514  if (m)
515  goto next;
516 
517  /* combination (options for broken wiring) */
519  if (strcmp(*CMD_ARGV, "separate") == 0)
520  /* separate reset lines - default */;
521  else if (strcmp(*CMD_ARGV, "srst_pulls_trst") == 0)
522  tmp |= RESET_SRST_PULLS_TRST;
523  else if (strcmp(*CMD_ARGV, "trst_pulls_srst") == 0)
524  tmp |= RESET_TRST_PULLS_SRST;
525  else if (strcmp(*CMD_ARGV, "combined") == 0)
527  else
528  m = 0;
529  if (mask & m) {
530  LOG_ERROR("extra reset_config %s spec (%s)",
531  "combination", *CMD_ARGV);
533  }
534  if (m)
535  goto next;
536 
537  /* trst_type (NOP without HAS_TRST) */
539  if (strcmp(*CMD_ARGV, "trst_open_drain") == 0)
540  tmp |= RESET_TRST_OPEN_DRAIN;
541  else if (strcmp(*CMD_ARGV, "trst_push_pull") == 0)
542  /* push/pull from adapter - default */;
543  else
544  m = 0;
545  if (mask & m) {
546  LOG_ERROR("extra reset_config %s spec (%s)",
547  "trst_type", *CMD_ARGV);
549  }
550  if (m)
551  goto next;
552 
553  /* srst_type (NOP without HAS_SRST) */
555  if (strcmp(*CMD_ARGV, "srst_push_pull") == 0)
556  tmp |= RESET_SRST_PUSH_PULL;
557  else if (strcmp(*CMD_ARGV, "srst_open_drain") == 0)
558  /* open drain from adapter - default */;
559  else
560  m = 0;
561  if (mask & m) {
562  LOG_ERROR("extra reset_config %s spec (%s)",
563  "srst_type", *CMD_ARGV);
565  }
566  if (m)
567  goto next;
568 
569  /* connect_type - only valid when srst_nogate */
571  if (strcmp(*CMD_ARGV, "connect_assert_srst") == 0)
572  tmp |= RESET_CNCT_UNDER_SRST;
573  else if (strcmp(*CMD_ARGV, "connect_deassert_srst") == 0)
574  /* connect normally - default */;
575  else
576  m = 0;
577  if (mask & m) {
578  LOG_ERROR("extra reset_config %s spec (%s)",
579  "connect_type", *CMD_ARGV);
581  }
582  if (m)
583  goto next;
584 
585  /* caller provided nonsense; fail */
586  LOG_ERROR("unknown reset_config flag (%s)", *CMD_ARGV);
588 
589 next:
590  /* Remember the bits which were specified (mask)
591  * and their new values (new_cfg).
592  */
593  mask |= m;
594  new_cfg |= tmp;
595  }
596 
597  /* clear previous values of those bits, save new values */
598  if (mask) {
599  int old_cfg = jtag_get_reset_config();
600 
601  old_cfg &= ~mask;
602  new_cfg |= old_cfg;
603  jtag_set_reset_config(new_cfg);
605 
606  } else
607  new_cfg = jtag_get_reset_config();
608 
609  /*
610  * Display the (now-)current reset mode
611  */
612  char *modes[6];
613 
614  /* minimal JTAG has neither SRST nor TRST (so that's the default) */
615  switch (new_cfg & (RESET_HAS_TRST | RESET_HAS_SRST)) {
616  case RESET_HAS_SRST:
617  modes[0] = "srst_only";
618  break;
619  case RESET_HAS_TRST:
620  modes[0] = "trst_only";
621  break;
622  case RESET_TRST_AND_SRST:
623  modes[0] = "trst_and_srst";
624  break;
625  default:
626  modes[0] = "none";
627  break;
628  }
629 
630  /* normally SRST and TRST are decoupled; but bugs happen ... */
631  switch (new_cfg & (RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST)) {
633  modes[1] = "srst_pulls_trst";
634  break;
636  modes[1] = "trst_pulls_srst";
637  break;
639  modes[1] = "combined";
640  break;
641  default:
642  modes[1] = "separate";
643  break;
644  }
645 
646  /* TRST-less connectors include Altera, Xilinx, and minimal JTAG */
647  if (new_cfg & RESET_HAS_TRST) {
648  if (new_cfg & RESET_TRST_OPEN_DRAIN)
649  modes[3] = " trst_open_drain";
650  else
651  modes[3] = " trst_push_pull";
652  } else
653  modes[3] = "";
654 
655  /* SRST-less connectors include TI-14, Xilinx, and minimal JTAG */
656  if (new_cfg & RESET_HAS_SRST) {
657  if (new_cfg & RESET_SRST_NO_GATING)
658  modes[2] = " srst_nogate";
659  else
660  modes[2] = " srst_gates_jtag";
661 
662  if (new_cfg & RESET_SRST_PUSH_PULL)
663  modes[4] = " srst_push_pull";
664  else
665  modes[4] = " srst_open_drain";
666 
667  if (new_cfg & RESET_CNCT_UNDER_SRST)
668  modes[5] = " connect_assert_srst";
669  else
670  modes[5] = " connect_deassert_srst";
671  } else {
672  modes[2] = "";
673  modes[4] = "";
674  modes[5] = "";
675  }
676 
677  command_print(CMD, "%s %s%s%s%s%s",
678  modes[0], modes[1],
679  modes[2], modes[3], modes[4], modes[5]);
680 
681  return ERROR_OK;
682 }
683 
684 COMMAND_HANDLER(handle_adapter_srst_delay_command)
685 {
686  if (CMD_ARGC > 1)
688  if (CMD_ARGC == 1) {
689  unsigned int delay;
690  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], delay);
691 
692  jtag_set_nsrst_delay(delay);
693  }
694  command_print(CMD, "adapter srst delay: %u", jtag_get_nsrst_delay());
695  return ERROR_OK;
696 }
697 
698 COMMAND_HANDLER(handle_adapter_srst_pulse_width_command)
699 {
700  if (CMD_ARGC > 1)
702  if (CMD_ARGC == 1) {
703  unsigned int width;
705 
707  }
708  command_print(CMD, "adapter srst pulse_width: %u", jtag_get_nsrst_assert_width());
709  return ERROR_OK;
710 }
711 
712 COMMAND_HANDLER(handle_adapter_speed_command)
713 {
714  if (CMD_ARGC > 1)
716 
717  int retval = ERROR_OK;
718  if (CMD_ARGC == 1) {
719  unsigned int khz = 0;
720  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], khz);
721 
722  retval = adapter_config_khz(khz);
723  if (retval != ERROR_OK)
724  return retval;
725  }
726 
727  int cur_speed = adapter_get_speed_khz();
728  retval = adapter_get_speed_readable(&cur_speed);
729  if (retval != ERROR_OK)
730  return retval;
731 
732  if (cur_speed)
733  command_print(CMD, "adapter speed: %d kHz", cur_speed);
734  else
735  command_print(CMD, "adapter speed: RCLK - adaptive");
736 
737  return retval;
738 }
739 
740 COMMAND_HANDLER(handle_adapter_serial_command)
741 {
742  if (CMD_ARGC != 1)
744 
745  free(adapter_config.serial);
746  adapter_config.serial = strdup(CMD_ARGV[0]);
747  return ERROR_OK;
748 }
749 
750 COMMAND_HANDLER(handle_adapter_reset_de_assert)
751 {
752  enum values {
753  VALUE_UNDEFINED = -1,
754  VALUE_DEASSERT = 0,
755  VALUE_ASSERT = 1,
756  };
757  enum values value;
758  enum values srst = VALUE_UNDEFINED;
759  enum values trst = VALUE_UNDEFINED;
761  char *signal;
762 
763  if (CMD_ARGC == 0) {
764  if (transport_is_jtag()) {
766  signal = jtag_get_trst() ? "asserted" : "deasserted";
767  else
768  signal = "not present";
769  command_print(CMD, "trst %s", signal);
770  }
771 
773  signal = jtag_get_srst() ? "asserted" : "deasserted";
774  else
775  signal = "not present";
776  command_print(CMD, "srst %s", signal);
777 
778  return ERROR_OK;
779  }
780 
781  if (CMD_ARGC != 1 && CMD_ARGC != 3)
783 
784  value = (strcmp(CMD_NAME, "assert") == 0) ? VALUE_ASSERT : VALUE_DEASSERT;
785  if (strcmp(CMD_ARGV[0], "srst") == 0)
786  srst = value;
787  else if (strcmp(CMD_ARGV[0], "trst") == 0)
788  trst = value;
789  else
791 
792  if (CMD_ARGC == 3) {
793  if (strcmp(CMD_ARGV[1], "assert") == 0)
794  value = VALUE_ASSERT;
795  else if (strcmp(CMD_ARGV[1], "deassert") == 0)
796  value = VALUE_DEASSERT;
797  else
799 
800  if (strcmp(CMD_ARGV[2], "srst") == 0 && srst == VALUE_UNDEFINED)
801  srst = value;
802  else if (strcmp(CMD_ARGV[2], "trst") == 0 && trst == VALUE_UNDEFINED)
803  trst = value;
804  else
806  }
807 
808  if (trst == VALUE_UNDEFINED) {
809  if (transport_is_jtag())
810  trst = jtag_get_trst() ? VALUE_ASSERT : VALUE_DEASSERT;
811  else
812  trst = VALUE_DEASSERT; /* unused, safe value */
813  }
814 
815  if (srst == VALUE_UNDEFINED) {
817  srst = jtag_get_srst() ? VALUE_ASSERT : VALUE_DEASSERT;
818  else
819  srst = VALUE_DEASSERT; /* unused, safe value */
820  }
821 
822  if (trst == VALUE_ASSERT && !transport_is_jtag()) {
823  LOG_ERROR("transport has no trst signal");
824  return ERROR_FAIL;
825  }
826 
827  if (srst == VALUE_ASSERT && !(jtag_reset_config & RESET_HAS_SRST)) {
828  LOG_ERROR("adapter has no srst signal");
829  return ERROR_FAIL;
830  }
831 
832  return adapter_resets((trst == VALUE_DEASSERT) ? TRST_DEASSERT : TRST_ASSERT,
833  (srst == VALUE_DEASSERT) ? SRST_DEASSERT : SRST_ASSERT);
834 }
835 
836 static int get_gpio_index(const char *signal_name)
837 {
838  for (int i = 0; i < ADAPTER_GPIO_IDX_NUM; ++i) {
839  if (strcmp(gpio_map[i].name, signal_name) == 0)
840  return i;
841  }
842  return -1;
843 }
844 
845 static COMMAND_HELPER(helper_adapter_gpio_print_config, enum adapter_gpio_config_index gpio_idx)
846 {
847  struct adapter_gpio_config *gpio_config = &adapter_config.gpios[gpio_idx];
848  const char *active_state = gpio_config->active_low ? "low" : "high";
849  const char *dir = "";
850  const char *drive = "";
851  const char *pull = "";
852  const char *init_state = "";
853 
854  if (gpio_config->gpio_num == ADAPTER_GPIO_NOT_SET) {
855  command_print(CMD, "adapter gpio %s: not configured", gpio_map[gpio_idx].name);
856  return ERROR_OK;
857  }
858 
859  switch (gpio_map[gpio_idx].direction) {
861  dir = "input";
862  break;
864  dir = "output";
865  break;
867  dir = "bidirectional";
868  break;
869  }
870 
871  if (gpio_map[gpio_idx].permit_drive_option) {
872  switch (gpio_config->drive) {
874  drive = ", push-pull";
875  break;
877  drive = ", open-drain";
878  break;
880  drive = ", open-source";
881  break;
882  }
883  }
884 
885  switch (gpio_config->pull) {
887  pull = ", pull-none";
888  break;
890  pull = ", pull-up";
891  break;
893  pull = ", pull-down";
894  break;
895  }
896 
897  if (gpio_map[gpio_idx].permit_init_state_option) {
898  switch (gpio_config->init_state) {
900  init_state = ", init-state inactive";
901  break;
903  init_state = ", init-state active";
904  break;
906  init_state = ", init-state input";
907  break;
908  }
909  }
910 
911  command_print(CMD, "adapter gpio %s (%s): num %u, chip %d, active-%s%s%s%s",
912  gpio_map[gpio_idx].name, dir, gpio_config->gpio_num, (int)gpio_config->chip_num, active_state,
913  drive, pull, init_state);
914 
915  return ERROR_OK;
916 }
917 
918 COMMAND_HANDLER(helper_adapter_gpio_print_all_configs)
919 {
920  for (int i = 0; i < ADAPTER_GPIO_IDX_NUM; ++i)
921  CALL_COMMAND_HANDLER(helper_adapter_gpio_print_config, i);
922  return ERROR_OK;
923 }
924 
925 COMMAND_HANDLER(adapter_gpio_config_handler)
926 {
927  unsigned int i = 1;
928  struct adapter_gpio_config *gpio_config;
929 
931 
932  if (CMD_ARGC == 0) {
933  CALL_COMMAND_HANDLER(helper_adapter_gpio_print_all_configs);
934  return ERROR_OK;
935  }
936 
937  int gpio_idx = get_gpio_index(CMD_ARGV[0]);
938  if (gpio_idx == -1) {
939  LOG_ERROR("adapter has no gpio named %s", CMD_ARGV[0]);
941  }
942 
943  if (CMD_ARGC == 1) {
944  CALL_COMMAND_HANDLER(helper_adapter_gpio_print_config, gpio_idx);
945  return ERROR_OK;
946  }
947 
948  gpio_config = &adapter_config.gpios[gpio_idx];
949  while (i < CMD_ARGC) {
950  LOG_DEBUG("Processing %s", CMD_ARGV[i]);
951 
952  if (isdigit(*CMD_ARGV[i])) {
953  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[i], gpio_config->gpio_num);
954  ++i;
955  continue;
956  }
957 
958  if (strcmp(CMD_ARGV[i], "-chip") == 0) {
959  if (CMD_ARGC - i < 2) {
960  LOG_ERROR("-chip option requires a parameter");
961  return ERROR_FAIL;
962  }
963  LOG_DEBUG("-chip arg is %s", CMD_ARGV[i + 1]);
964  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[i + 1], gpio_config->chip_num);
965  i += 2;
966  continue;
967  }
968 
969  if (strcmp(CMD_ARGV[i], "-active-high") == 0) {
970  ++i;
971  gpio_config->active_low = false;
972  continue;
973  }
974  if (strcmp(CMD_ARGV[i], "-active-low") == 0) {
975  ++i;
976  gpio_config->active_low = true;
977  continue;
978  }
979 
980  if (gpio_map[gpio_idx].permit_drive_option) {
981  if (strcmp(CMD_ARGV[i], "-push-pull") == 0) {
982  ++i;
984  continue;
985  }
986  if (strcmp(CMD_ARGV[i], "-open-drain") == 0) {
987  ++i;
989  continue;
990  }
991  if (strcmp(CMD_ARGV[i], "-open-source") == 0) {
992  ++i;
994  continue;
995  }
996  }
997 
998  if (strcmp(CMD_ARGV[i], "-pull-none") == 0) {
999  ++i;
1000  gpio_config->pull = ADAPTER_GPIO_PULL_NONE;
1001  continue;
1002  }
1003  if (strcmp(CMD_ARGV[i], "-pull-up") == 0) {
1004  ++i;
1005  gpio_config->pull = ADAPTER_GPIO_PULL_UP;
1006  continue;
1007  }
1008  if (strcmp(CMD_ARGV[i], "-pull-down") == 0) {
1009  ++i;
1010  gpio_config->pull = ADAPTER_GPIO_PULL_DOWN;
1011  continue;
1012  }
1013 
1014  if (gpio_map[gpio_idx].permit_init_state_option) {
1015  if (strcmp(CMD_ARGV[i], "-init-inactive") == 0) {
1016  ++i;
1018  continue;
1019  }
1020  if (strcmp(CMD_ARGV[i], "-init-active") == 0) {
1021  ++i;
1023  continue;
1024  }
1025 
1027  strcmp(CMD_ARGV[i], "-init-input") == 0) {
1028  ++i;
1030  continue;
1031  }
1032  }
1033 
1034  LOG_ERROR("illegal option for adapter %s %s: %s",
1035  CMD_NAME, gpio_map[gpio_idx].name, CMD_ARGV[i]);
1037  }
1038 
1039  /* Force swdio_dir init state to be compatible with swdio init state */
1040  if (gpio_idx == ADAPTER_GPIO_IDX_SWDIO)
1041  adapter_config.gpios[ADAPTER_GPIO_IDX_SWDIO_DIR].init_state =
1042  (gpio_config->init_state == ADAPTER_GPIO_INIT_STATE_INPUT) ?
1045 
1046  return ERROR_OK;
1047 }
1048 
1049 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
1050 COMMAND_HANDLER(handle_usb_location_command)
1051 {
1052  if (CMD_ARGC == 1)
1053  adapter_usb_set_location(CMD_ARGV[0]);
1054 
1055  command_print(CMD, "adapter usb location: %s", adapter_usb_get_location());
1056 
1057  return ERROR_OK;
1058 }
1059 #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */
1060 
1061 static const struct command_registration adapter_usb_command_handlers[] = {
1062 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
1063  {
1064  .name = "location",
1065  .handler = &handle_usb_location_command,
1066  .mode = COMMAND_CONFIG,
1067  .help = "display or set the USB bus location of the USB device",
1068  .usage = "[<bus>-port[.port]...]",
1069  },
1070 #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */
1072 };
1073 
1074 static const struct command_registration adapter_srst_command_handlers[] = {
1075  {
1076  .name = "delay",
1077  .handler = handle_adapter_srst_delay_command,
1078  .mode = COMMAND_ANY,
1079  .help = "delay after deasserting SRST in ms",
1080  .usage = "[milliseconds]",
1081  },
1082  {
1083  .name = "pulse_width",
1084  .handler = handle_adapter_srst_pulse_width_command,
1085  .mode = COMMAND_ANY,
1086  .help = "SRST assertion pulse width in ms",
1087  .usage = "[milliseconds]",
1088  },
1090 };
1091 
1092 static const struct command_registration adapter_command_handlers[] = {
1093  {
1094  .name = "driver",
1095  .handler = handle_adapter_driver_command,
1096  .mode = COMMAND_CONFIG,
1097  .help = "Select a debug adapter driver",
1098  .usage = "driver_name",
1099  },
1100  {
1101  .name = "speed",
1102  .handler = handle_adapter_speed_command,
1103  .mode = COMMAND_ANY,
1104  .help = "With an argument, change to the specified maximum "
1105  "jtag speed. For JTAG, 0 KHz signifies adaptive "
1106  "clocking. "
1107  "With or without argument, display current setting.",
1108  .usage = "[khz]",
1109  },
1110  {
1111  .name = "serial",
1112  .handler = handle_adapter_serial_command,
1113  .mode = COMMAND_CONFIG,
1114  .help = "Set the serial number of the adapter",
1115  .usage = "serial_string",
1116  },
1117  {
1118  .name = "list",
1119  .handler = handle_adapter_list_command,
1120  .mode = COMMAND_ANY,
1121  .help = "List all built-in debug adapter drivers",
1122  .usage = "",
1123  },
1124  {
1125  .name = "name",
1126  .mode = COMMAND_ANY,
1127  .handler = handle_adapter_name,
1128  .help = "Returns the name of the currently "
1129  "selected adapter (driver)",
1130  .usage = "",
1131  },
1132  {
1133  .name = "srst",
1134  .mode = COMMAND_ANY,
1135  .help = "srst adapter command group",
1136  .usage = "",
1138  },
1139  {
1140  .name = "usb",
1141  .mode = COMMAND_ANY,
1142  .help = "usb adapter command group",
1143  .usage = "",
1145  },
1146  {
1147  .name = "assert",
1148  .handler = handle_adapter_reset_de_assert,
1149  .mode = COMMAND_EXEC,
1150  .help = "Controls SRST and TRST lines.",
1151  .usage = "|deassert [srst|trst [assert|deassert srst|trst]]",
1152  },
1153  {
1154  .name = "deassert",
1155  .handler = handle_adapter_reset_de_assert,
1156  .mode = COMMAND_EXEC,
1157  .help = "Controls SRST and TRST lines.",
1158  .usage = "|assert [srst|trst [deassert|assert srst|trst]]",
1159  },
1160  {
1161  .name = "gpio",
1162  .handler = adapter_gpio_config_handler,
1163  .mode = COMMAND_CONFIG,
1164  .help = "gpio adapter command group",
1165  .usage = "[ tdo|tdi|tms|tck|trst|swdio|swdio_dir|swclk|srst|led"
1166  "[gpio_number] "
1167  "[-chip chip_number] "
1168  "[-active-high|-active-low] "
1169  "[-push-pull|-open-drain|-open-source] "
1170  "[-pull-none|-pull-up|-pull-down]"
1171  "[-init-inactive|-init-active|-init-input] ]",
1172  },
1174 };
1175 
1176 static const struct command_registration interface_command_handlers[] = {
1177  {
1178  .name = "adapter",
1179  .mode = COMMAND_ANY,
1180  .help = "adapter command group",
1181  .usage = "",
1182  .chain = adapter_command_handlers,
1183  },
1184  {
1185  .name = "reset_config",
1186  .handler = handle_reset_config_command,
1187  .mode = COMMAND_ANY,
1188  .help = "configure adapter reset behavior",
1189  .usage = "[none|trst_only|srst_only|trst_and_srst] "
1190  "[srst_pulls_trst|trst_pulls_srst|combined|separate] "
1191  "[srst_gates_jtag|srst_nogate] "
1192  "[trst_push_pull|trst_open_drain] "
1193  "[srst_push_pull|srst_open_drain] "
1194  "[connect_deassert_srst|connect_assert_srst]",
1195  },
1197 };
1198 
1206 {
1208 }
1209 
1211 {
1212  return gpio_map[idx].name;
1213 }
1214 
1215 /* Allow drivers access to the GPIO configuration */
1217 {
1218  return adapter_config.gpios;
1219 }
static const struct command_registration adapter_srst_command_handlers[]
Definition: adapter.c:1074
static int adapter_rclk_to_speed(unsigned int fallback_speed_khz, int *speed)
Definition: adapter.c:232
int adapter_config_rclk(unsigned int fallback_speed_khz)
Attempt to enable RTCK/RCLK.
Definition: adapter.c:259
const char * adapter_get_required_serial(void)
Retrieves the serial number set with command 'adapter serial'.
Definition: adapter.c:300
bool adapter_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, size_t path_len)
Definition: adapter.c:331
const struct adapter_gpio_config * adapter_gpio_get_config(void)
Retrieves gpio configuration set with command "adapter gpio <signal_name>".
Definition: adapter.c:1216
static void sync_adapter_reset_with_gpios(void)
Definition: adapter.c:80
static struct @16 adapter_config
Adapter configuration.
static int get_gpio_index(const char *signal_name)
Definition: adapter.c:836
enum adapter_clk_mode clock_mode
Definition: adapter.c:44
COMMAND_HANDLER(handle_adapter_name)
Definition: adapter.c:380
int rclk_fallback_speed_khz
Definition: adapter.c:46
static int adapter_set_speed(int speed)
Definition: adapter.c:242
int adapter_get_speed(int *speed)
Definition: adapter.c:269
bool is_adapter_initialized(void)
Definition: adapter.c:71
int adapter_quit(void)
Shutdown the debug adapter upon program exit.
Definition: adapter.c:187
unsigned int adapter_get_speed_khz(void)
Retrieves the clock speed of the adapter in kHz.
Definition: adapter.c:208
bool gpios_initialized
Definition: adapter.c:48
bool adapter_initialized
Definition: adapter.c:41
static int adapter_khz_to_speed(unsigned int khz, int *speed)
Definition: adapter.c:213
int speed_khz
Definition: adapter.c:45
adapter_clk_mode
Definition: adapter.c:29
@ CLOCK_MODE_KHZ
Definition: adapter.c:31
@ CLOCK_MODE_RCLK
Definition: adapter.c:32
@ CLOCK_MODE_UNSELECTED
Definition: adapter.c:30
int adapter_get_speed_readable(int *khz)
Given a speed setting, use the interface speed_div callback to adjust the setting.
Definition: adapter.c:285
static const struct command_registration adapter_usb_command_handlers[]
Definition: adapter.c:1061
#define DEFAULT_CLOCK_SPEED_KHZ
Definition: adapter.c:35
struct adapter_gpio_config gpios[ADAPTER_GPIO_IDX_NUM]
Definition: adapter.c:47
char * usb_location
Definition: adapter.c:42
const char * adapter_usb_get_location(void)
Definition: adapter.c:326
int adapter_register_commands(struct command_context *ctx)
Register the commands which deal with arbitrary debug adapter drivers.
Definition: adapter.c:1205
int adapter_init(struct command_context *cmd_ctx)
Do low-level setup like initializing registers, output signals, and clocking.
Definition: adapter.c:122
static const struct command_registration adapter_command_handlers[]
Definition: adapter.c:1092
char * serial
Definition: adapter.c:43
static int adapter_config_khz(unsigned int khz)
Attempt to configure the adapter for the specified kHz.
Definition: adapter.c:250
struct adapter_driver * adapter_driver
Definition: adapter.c:27
#define USB_MAX_LOCATION_LENGTH
Definition: adapter.c:312
static void adapter_driver_gpios_init(void)
Definition: adapter.c:93
static const struct command_registration interface_command_handlers[]
Definition: adapter.c:1176
static COMMAND_HELPER(helper_adapter_gpio_print_config, enum adapter_gpio_config_index gpio_idx)
Definition: adapter.c:845
const char * adapter_gpio_get_name(enum adapter_gpio_config_index idx)
Retrieves gpio name.
Definition: adapter.c:1210
@ ADAPTER_GPIO_INIT_STATE_ACTIVE
Definition: adapter.h:32
@ ADAPTER_GPIO_INIT_STATE_INPUT
Definition: adapter.h:33
@ ADAPTER_GPIO_INIT_STATE_INACTIVE
Definition: adapter.h:31
adapter_gpio_config_index
Adapter GPIO.
Definition: adapter.h:44
@ ADAPTER_GPIO_IDX_LED
Definition: adapter.h:54
@ ADAPTER_GPIO_IDX_NUM
Definition: adapter.h:55
@ ADAPTER_GPIO_IDX_SWCLK
Definition: adapter.h:52
@ ADAPTER_GPIO_IDX_SWDIO_DIR
Definition: adapter.h:51
@ ADAPTER_GPIO_IDX_SRST
Definition: adapter.h:53
@ ADAPTER_GPIO_IDX_TRST
Definition: adapter.h:49
@ ADAPTER_GPIO_IDX_TDI
Definition: adapter.h:46
@ ADAPTER_GPIO_IDX_TMS
Definition: adapter.h:47
@ ADAPTER_GPIO_IDX_TCK
Definition: adapter.h:48
@ ADAPTER_GPIO_IDX_TDO
Definition: adapter.h:45
@ ADAPTER_GPIO_IDX_SWDIO
Definition: adapter.h:50
adapter_gpio_direction
Supported GPIO directions.
Definition: adapter.h:23
@ ADAPTER_GPIO_DIRECTION_OUTPUT
Definition: adapter.h:25
@ ADAPTER_GPIO_DIRECTION_INPUT
Definition: adapter.h:24
@ ADAPTER_GPIO_DIRECTION_BIDIRECTIONAL
Definition: adapter.h:26
@ ADAPTER_GPIO_PULL_UP
Definition: adapter.h:39
@ ADAPTER_GPIO_PULL_DOWN
Definition: adapter.h:40
@ ADAPTER_GPIO_PULL_NONE
Definition: adapter.h:38
@ ADAPTER_GPIO_DRIVE_MODE_OPEN_SOURCE
Definition: adapter.h:19
@ ADAPTER_GPIO_DRIVE_MODE_OPEN_DRAIN
Definition: adapter.h:18
@ ADAPTER_GPIO_DRIVE_MODE_PUSH_PULL
Definition: adapter.h:17
#define ADAPTER_GPIO_NOT_SET
Definition: adapter.h:122
const char * name
Definition: armv4_5.c:76
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
Definition: command.c:353
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:376
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:141
#define CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
Definition: command.h:118
#define CMD_NAME
Use this macro to access the name of the command being handled, rather than accessing the variable di...
Definition: command.h:166
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:156
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:402
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:151
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
Definition: command.h:442
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
Definition: command.h:146
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
static int register_commands(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds)
Register one or more commands in the specified context, as children of parent (or top-level commends,...
Definition: command.h:274
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
unsigned short width
Definition: embeddedice.c:47
int mask
Definition: esirisc.c:1740
static uint16_t direction
Definition: ftdi.c:120
struct adapter_driver * adapter_drivers[]
The list of built-in JTAG interfaces, containing entries for those drivers that were enabled by the c...
Definition: interfaces.c:38
Exports the list of JTAG interface drivers, along with routines for loading and unloading them dynami...
int adapter_resets(int trst, int srst)
Definition: jtag/core.c:1845
int jtag_get_trst(void)
Definition: jtag/core.c:1756
bool transport_is_jtag(void)
Returns true if the current debug session is using JTAG as its transport.
Definition: jtag/core.c:1840
unsigned int jtag_get_nsrst_delay(void)
Definition: jtag/core.c:1769
struct jtag_tap * jtag_all_taps(void)
Definition: jtag/core.c:190
unsigned int jtag_get_nsrst_assert_width(void)
Definition: jtag/core.c:1786
void jtag_set_nsrst_assert_width(unsigned int delay)
Definition: jtag/core.c:1782
static enum reset_types jtag_reset_config
Definition: jtag/core.c:89
int jtag_get_srst(void)
Definition: jtag/core.c:1760
void jtag_tap_free(struct jtag_tap *tap)
Definition: jtag/core.c:1494
void jtag_set_nsrst_delay(unsigned int delay)
Definition: jtag/core.c:1765
void jtag_set_reset_config(enum reset_types type)
Definition: jtag/core.c:1751
enum reset_types jtag_get_reset_config(void)
Definition: jtag/core.c:1747
The JTAG interface can be implemented with a software or hardware fifo.
#define ERROR_JTAG_INIT_FAILED
Definition: jtag.h:552
#define TRST_DEASSERT
Definition: jtag.h:64
#define ERROR_JTAG_INVALID_INTERFACE
Definition: jtag.h:553
#define TRST_ASSERT
Definition: jtag.h:65
reset_types
Definition: jtag.h:215
@ RESET_NONE
Definition: jtag.h:216
@ RESET_SRST_NO_GATING
Definition: jtag.h:224
@ RESET_HAS_SRST
Definition: jtag.h:218
@ RESET_HAS_TRST
Definition: jtag.h:217
@ RESET_TRST_PULLS_SRST
Definition: jtag.h:221
@ RESET_CNCT_UNDER_SRST
Definition: jtag.h:225
@ RESET_SRST_PULLS_TRST
Definition: jtag.h:220
@ RESET_TRST_OPEN_DRAIN
Definition: jtag.h:222
@ RESET_TRST_AND_SRST
Definition: jtag.h:219
@ RESET_SRST_PUSH_PULL
Definition: jtag.h:223
#define SRST_ASSERT
Definition: jtag.h:63
#define SRST_DEASSERT
Defines arguments for reset functions.
Definition: jtag.h:62
#define LOG_WARNING(expr ...)
Definition: log.h:130
#define ERROR_FAIL
Definition: log.h:174
#define LOG_ERROR(expr ...)
Definition: log.h:133
#define LOG_INFO(expr ...)
Definition: log.h:127
#define LOG_DEBUG(expr ...)
Definition: log.h:110
#define ERROR_OK
Definition: log.h:168
char * strndup(const char *s, size_t n)
Definition: replacements.c:115
size_t strnlen(const char *s, size_t maxlen)
Definition: replacements.c:107
#define BIT(nr)
Definition: stm32l4x.h:18
Represents a driver for a debugging interface.
Definition: interface.h:208
int(* speed)(int speed)
Set the interface speed.
Definition: interface.h:271
unsigned int transport_preferred_id
ID of transport that gets auto-selected when not specified by the user.
Definition: interface.h:221
int(* khz)(int khz, int *jtag_speed)
Returns JTAG maximum speed for KHz.
Definition: interface.h:283
int(* speed_div)(int speed, int *khz)
Calculate the clock frequency (in KHz) for the given speed.
Definition: interface.h:292
unsigned int transport_ids
Bitmask of transport IDs supported in C code.
Definition: interface.h:215
int(* init)(void)
Interface driver must initialize any resources and connect to a JTAG device.
Definition: interface.h:240
const char *const name
The name of the interface driver.
Definition: interface.h:210
int(* quit)(void)
Interface driver must tear down all resources and disconnect from the JTAG device.
Definition: interface.h:248
Configuration options for a single GPIO.
Definition: adapter.h:59
unsigned int gpio_num
Definition: adapter.h:60
unsigned int chip_num
Definition: adapter.h:61
enum adapter_gpio_pull pull
Definition: adapter.h:65
enum adapter_gpio_init_state init_state
Definition: adapter.h:63
enum adapter_gpio_drive_mode drive
Definition: adapter.h:62
const char * name
Definition: command.h:235
const char * name
Definition: adapter.c:52
enum adapter_gpio_direction direction
Definition: adapter.c:53
bool permit_init_state_option
Definition: adapter.c:55
bool permit_drive_option
Definition: adapter.c:54
Definition: jtag.h:101
struct jtag_tap * next_tap
Definition: jtag.h:141
Definition: ftdi.c:95
int allow_transports(struct command_context *ctx, unsigned int transport_ids, unsigned int transport_preferred_id)
Called by debug adapter drivers, or affiliated Tcl config scripts, to declare the set of transports s...
Definition: transport.c:149
const char * transport_name(unsigned int id)
Definition: transport.c:86
#define TRANSPORT_VALID_MASK
Definition: transport.h:28
#define NULL
Definition: usb.h:16