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 <transport/transport.h>
20 
27 const char * const jtag_only[] = { "jtag", NULL };
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  /* close the JTAG interface */
191  int result = adapter_driver->quit();
192  if (result != ERROR_OK)
193  LOG_ERROR("failed: %d", result);
194  }
195 
196  free(adapter_config.serial);
197  free(adapter_config.usb_location);
198 
199  struct jtag_tap *t = jtag_all_taps();
200  while (t) {
201  struct jtag_tap *n = t->next_tap;
202  jtag_tap_free(t);
203  t = n;
204  }
205 
206  return ERROR_OK;
207 }
208 
209 unsigned int adapter_get_speed_khz(void)
210 {
211  return adapter_config.speed_khz;
212 }
213 
214 static int adapter_khz_to_speed(unsigned int khz, int *speed)
215 {
216  LOG_DEBUG("convert khz to adapter specific speed value");
217  adapter_config.speed_khz = khz;
218  if (!is_adapter_initialized())
219  return ERROR_OK;
220  LOG_DEBUG("have adapter set up");
221  if (!adapter_driver->khz) {
222  LOG_ERROR("Translation from khz to adapter speed not implemented");
223  return ERROR_FAIL;
224  }
225  int speed_div1;
226  int retval = adapter_driver->khz(adapter_get_speed_khz(), &speed_div1);
227  if (retval != ERROR_OK)
228  return retval;
229  *speed = speed_div1;
230  return ERROR_OK;
231 }
232 
233 static int adapter_rclk_to_speed(unsigned int fallback_speed_khz, int *speed)
234 {
235  int retval = adapter_khz_to_speed(0, speed);
236  if ((retval != ERROR_OK) && fallback_speed_khz) {
237  LOG_DEBUG("trying fallback speed...");
238  retval = adapter_khz_to_speed(fallback_speed_khz, speed);
239  }
240  return retval;
241 }
242 
243 static int adapter_set_speed(int speed)
244 {
245  /* this command can be called during CONFIG,
246  * in which case adapter isn't initialized */
248 }
249 
251 static int adapter_config_khz(unsigned int khz)
252 {
253  LOG_DEBUG("handle adapter khz");
254  adapter_config.clock_mode = CLOCK_MODE_KHZ;
255  int speed = 0;
256  int retval = adapter_khz_to_speed(khz, &speed);
257  return (retval != ERROR_OK) ? retval : adapter_set_speed(speed);
258 }
259 
260 int adapter_config_rclk(unsigned int fallback_speed_khz)
261 {
262  LOG_DEBUG("handle adapter rclk");
263  adapter_config.clock_mode = CLOCK_MODE_RCLK;
264  adapter_config.rclk_fallback_speed_khz = fallback_speed_khz;
265  int speed = 0;
266  int retval = adapter_rclk_to_speed(fallback_speed_khz, &speed);
267  return (retval != ERROR_OK) ? retval : adapter_set_speed(speed);
268 }
269 
270 int adapter_get_speed(int *speed)
271 {
272  switch (adapter_config.clock_mode) {
273  case CLOCK_MODE_KHZ:
275  break;
276  case CLOCK_MODE_RCLK:
277  adapter_rclk_to_speed(adapter_config.rclk_fallback_speed_khz, speed);
278  break;
279  default:
280  LOG_ERROR("BUG: unknown adapter clock mode");
281  return ERROR_FAIL;
282  }
283  return ERROR_OK;
284 }
285 
287 {
288  int speed_var = 0;
289  int retval = adapter_get_speed(&speed_var);
290  if (retval != ERROR_OK)
291  return retval;
292  if (!is_adapter_initialized())
293  return ERROR_OK;
294  if (!adapter_driver->speed_div) {
295  LOG_ERROR("Translation from adapter speed to khz not implemented");
296  return ERROR_FAIL;
297  }
298  return adapter_driver->speed_div(speed_var, khz);
299 }
300 
302 {
303  return adapter_config.serial;
304 }
305 
306 /*
307  * 1 char: bus
308  * 2 * 7 chars: max 7 ports
309  * 1 char: test for overflow
310  * ------
311  * 16 chars
312  */
313 #define USB_MAX_LOCATION_LENGTH 16
314 
315 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
316 static void adapter_usb_set_location(const char *location)
317 {
319  LOG_WARNING("usb location string is too long!!");
320 
321  free(adapter_config.usb_location);
322 
323  adapter_config.usb_location = strndup(location, USB_MAX_LOCATION_LENGTH);
324 }
325 #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */
326 
327 const char *adapter_usb_get_location(void)
328 {
329  return adapter_config.usb_location;
330 }
331 
332 bool adapter_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, size_t path_len)
333 {
334  size_t path_step, string_length;
335  char *ptr, *loc;
336  bool equal = false;
337 
339  return equal;
340 
341  /* strtok need non const char */
343  string_length = strnlen(loc, USB_MAX_LOCATION_LENGTH);
344 
345  ptr = strtok(loc, "-");
346  if (!ptr) {
347  LOG_WARNING("no '-' in usb path\n");
348  goto done;
349  }
350 
351  string_length -= strnlen(ptr, string_length);
352  /* check bus mismatch */
353  if (atoi(ptr) != dev_bus)
354  goto done;
355 
356  path_step = 0;
357  while (path_step < path_len) {
358  ptr = strtok(NULL, ".");
359 
360  /* no more tokens in path */
361  if (!ptr)
362  break;
363 
364  /* path mismatch at some step */
365  if (path_step < path_len && atoi(ptr) != port_path[path_step])
366  break;
367 
368  path_step++;
369  string_length -= strnlen(ptr, string_length) + 1;
370  };
371 
372  /* walked the full path, all elements match */
373  if (path_step == path_len && !string_length)
374  equal = true;
375 
376 done:
377  free(loc);
378  return equal;
379 }
380 
381 COMMAND_HANDLER(handle_adapter_name)
382 {
383  /* return the name of the interface */
384  /* TCL code might need to know the exact type... */
385  /* FUTURE: we allow this as a means to "set" the interface. */
386 
387  if (CMD_ARGC != 0)
389 
390  command_print(CMD, "%s", adapter_driver ? adapter_driver->name : "undefined");
391 
392  return ERROR_OK;
393 }
394 
395 COMMAND_HANDLER(adapter_transports_command)
396 {
397  char **transports;
398  int retval;
399 
400  retval = CALL_COMMAND_HANDLER(transport_list_parse, &transports);
401  if (retval != ERROR_OK)
402  return retval;
403 
404  retval = allow_transports(CMD_CTX, (const char **)transports);
405 
406  if (retval != ERROR_OK) {
407  for (unsigned int i = 0; transports[i]; i++)
408  free(transports[i]);
409  free(transports);
410  }
411  return retval;
412 }
413 
414 COMMAND_HANDLER(handle_adapter_list_command)
415 {
416  if (strcmp(CMD_NAME, "list") == 0 && CMD_ARGC > 0)
418 
419  command_print(CMD, "The following debug adapters are available:");
420  for (unsigned int i = 0; adapter_drivers[i]; i++) {
421  const char *name = adapter_drivers[i]->name;
422  command_print(CMD, "%u: %s", i + 1, name);
423  }
424 
425  return ERROR_OK;
426 }
427 
428 COMMAND_HANDLER(handle_adapter_driver_command)
429 {
430  int retval;
431 
432  /* check whether the interface is already configured */
433  if (adapter_driver) {
434  LOG_WARNING("Interface already configured, ignoring");
435  return ERROR_OK;
436  }
437 
438  /* interface name is a mandatory argument */
439  if (CMD_ARGC != 1 || CMD_ARGV[0][0] == '\0')
441 
442  for (unsigned int i = 0; adapter_drivers[i]; i++) {
443  if (strcmp(CMD_ARGV[0], adapter_drivers[i]->name) != 0)
444  continue;
445 
446  if (adapter_drivers[i]->commands) {
447  retval = register_commands(CMD_CTX, NULL, adapter_drivers[i]->commands);
448  if (retval != ERROR_OK)
449  return retval;
450  }
451 
453 
455  }
456 
457  /* no valid interface was found (i.e. the configuration option,
458  * didn't match one of the compiled-in interfaces
459  */
460  LOG_ERROR("The specified debug interface was not found (%s)",
461  CMD_ARGV[0]);
462  CALL_COMMAND_HANDLER(handle_adapter_list_command);
464 }
465 
466 COMMAND_HANDLER(handle_reset_config_command)
467 {
468  int new_cfg = 0;
469  int mask = 0;
470 
471  /* Original versions cared about the order of these tokens:
472  * reset_config signals [combination [trst_type [srst_type]]]
473  * They also clobbered the previous configuration even on error.
474  *
475  * Here we don't care about the order, and only change values
476  * which have been explicitly specified.
477  */
478  for (; CMD_ARGC; CMD_ARGC--, CMD_ARGV++) {
479  int tmp = 0;
480  int m;
481 
482  /* gating */
484  if (strcmp(*CMD_ARGV, "srst_gates_jtag") == 0)
485  /* default: don't use JTAG while SRST asserted */;
486  else if (strcmp(*CMD_ARGV, "srst_nogate") == 0)
487  tmp = RESET_SRST_NO_GATING;
488  else
489  m = 0;
490  if (mask & m) {
491  LOG_ERROR("extra reset_config %s spec (%s)",
492  "gating", *CMD_ARGV);
494  }
495  if (m)
496  goto next;
497 
498  /* signals */
500  if (strcmp(*CMD_ARGV, "none") == 0)
501  tmp = RESET_NONE;
502  else if (strcmp(*CMD_ARGV, "trst_only") == 0)
503  tmp = RESET_HAS_TRST;
504  else if (strcmp(*CMD_ARGV, "srst_only") == 0)
505  tmp = RESET_HAS_SRST;
506  else if (strcmp(*CMD_ARGV, "trst_and_srst") == 0)
508  else
509  m = 0;
510  if (mask & m) {
511  LOG_ERROR("extra reset_config %s spec (%s)",
512  "signal", *CMD_ARGV);
514  }
515  if (m)
516  goto next;
517 
518  /* combination (options for broken wiring) */
520  if (strcmp(*CMD_ARGV, "separate") == 0)
521  /* separate reset lines - default */;
522  else if (strcmp(*CMD_ARGV, "srst_pulls_trst") == 0)
523  tmp |= RESET_SRST_PULLS_TRST;
524  else if (strcmp(*CMD_ARGV, "trst_pulls_srst") == 0)
525  tmp |= RESET_TRST_PULLS_SRST;
526  else if (strcmp(*CMD_ARGV, "combined") == 0)
528  else
529  m = 0;
530  if (mask & m) {
531  LOG_ERROR("extra reset_config %s spec (%s)",
532  "combination", *CMD_ARGV);
534  }
535  if (m)
536  goto next;
537 
538  /* trst_type (NOP without HAS_TRST) */
540  if (strcmp(*CMD_ARGV, "trst_open_drain") == 0)
541  tmp |= RESET_TRST_OPEN_DRAIN;
542  else if (strcmp(*CMD_ARGV, "trst_push_pull") == 0)
543  /* push/pull from adapter - default */;
544  else
545  m = 0;
546  if (mask & m) {
547  LOG_ERROR("extra reset_config %s spec (%s)",
548  "trst_type", *CMD_ARGV);
550  }
551  if (m)
552  goto next;
553 
554  /* srst_type (NOP without HAS_SRST) */
556  if (strcmp(*CMD_ARGV, "srst_push_pull") == 0)
557  tmp |= RESET_SRST_PUSH_PULL;
558  else if (strcmp(*CMD_ARGV, "srst_open_drain") == 0)
559  /* open drain from adapter - default */;
560  else
561  m = 0;
562  if (mask & m) {
563  LOG_ERROR("extra reset_config %s spec (%s)",
564  "srst_type", *CMD_ARGV);
566  }
567  if (m)
568  goto next;
569 
570  /* connect_type - only valid when srst_nogate */
572  if (strcmp(*CMD_ARGV, "connect_assert_srst") == 0)
573  tmp |= RESET_CNCT_UNDER_SRST;
574  else if (strcmp(*CMD_ARGV, "connect_deassert_srst") == 0)
575  /* connect normally - default */;
576  else
577  m = 0;
578  if (mask & m) {
579  LOG_ERROR("extra reset_config %s spec (%s)",
580  "connect_type", *CMD_ARGV);
582  }
583  if (m)
584  goto next;
585 
586  /* caller provided nonsense; fail */
587  LOG_ERROR("unknown reset_config flag (%s)", *CMD_ARGV);
589 
590 next:
591  /* Remember the bits which were specified (mask)
592  * and their new values (new_cfg).
593  */
594  mask |= m;
595  new_cfg |= tmp;
596  }
597 
598  /* clear previous values of those bits, save new values */
599  if (mask) {
600  int old_cfg = jtag_get_reset_config();
601 
602  old_cfg &= ~mask;
603  new_cfg |= old_cfg;
604  jtag_set_reset_config(new_cfg);
606 
607  } else
608  new_cfg = jtag_get_reset_config();
609 
610  /*
611  * Display the (now-)current reset mode
612  */
613  char *modes[6];
614 
615  /* minimal JTAG has neither SRST nor TRST (so that's the default) */
616  switch (new_cfg & (RESET_HAS_TRST | RESET_HAS_SRST)) {
617  case RESET_HAS_SRST:
618  modes[0] = "srst_only";
619  break;
620  case RESET_HAS_TRST:
621  modes[0] = "trst_only";
622  break;
623  case RESET_TRST_AND_SRST:
624  modes[0] = "trst_and_srst";
625  break;
626  default:
627  modes[0] = "none";
628  break;
629  }
630 
631  /* normally SRST and TRST are decoupled; but bugs happen ... */
632  switch (new_cfg & (RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST)) {
634  modes[1] = "srst_pulls_trst";
635  break;
637  modes[1] = "trst_pulls_srst";
638  break;
640  modes[1] = "combined";
641  break;
642  default:
643  modes[1] = "separate";
644  break;
645  }
646 
647  /* TRST-less connectors include Altera, Xilinx, and minimal JTAG */
648  if (new_cfg & RESET_HAS_TRST) {
649  if (new_cfg & RESET_TRST_OPEN_DRAIN)
650  modes[3] = " trst_open_drain";
651  else
652  modes[3] = " trst_push_pull";
653  } else
654  modes[3] = "";
655 
656  /* SRST-less connectors include TI-14, Xilinx, and minimal JTAG */
657  if (new_cfg & RESET_HAS_SRST) {
658  if (new_cfg & RESET_SRST_NO_GATING)
659  modes[2] = " srst_nogate";
660  else
661  modes[2] = " srst_gates_jtag";
662 
663  if (new_cfg & RESET_SRST_PUSH_PULL)
664  modes[4] = " srst_push_pull";
665  else
666  modes[4] = " srst_open_drain";
667 
668  if (new_cfg & RESET_CNCT_UNDER_SRST)
669  modes[5] = " connect_assert_srst";
670  else
671  modes[5] = " connect_deassert_srst";
672  } else {
673  modes[2] = "";
674  modes[4] = "";
675  modes[5] = "";
676  }
677 
678  command_print(CMD, "%s %s%s%s%s%s",
679  modes[0], modes[1],
680  modes[2], modes[3], modes[4], modes[5]);
681 
682  return ERROR_OK;
683 }
684 
685 COMMAND_HANDLER(handle_adapter_srst_delay_command)
686 {
687  if (CMD_ARGC > 1)
689  if (CMD_ARGC == 1) {
690  unsigned int delay;
691  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], delay);
692 
693  jtag_set_nsrst_delay(delay);
694  }
695  command_print(CMD, "adapter srst delay: %u", jtag_get_nsrst_delay());
696  return ERROR_OK;
697 }
698 
699 COMMAND_HANDLER(handle_adapter_srst_pulse_width_command)
700 {
701  if (CMD_ARGC > 1)
703  if (CMD_ARGC == 1) {
704  unsigned int width;
706 
708  }
709  command_print(CMD, "adapter srst pulse_width: %u", jtag_get_nsrst_assert_width());
710  return ERROR_OK;
711 }
712 
713 COMMAND_HANDLER(handle_adapter_speed_command)
714 {
715  if (CMD_ARGC > 1)
717 
718  int retval = ERROR_OK;
719  if (CMD_ARGC == 1) {
720  unsigned int khz = 0;
721  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], khz);
722 
723  retval = adapter_config_khz(khz);
724  if (retval != ERROR_OK)
725  return retval;
726  }
727 
728  int cur_speed = adapter_get_speed_khz();
729  retval = adapter_get_speed_readable(&cur_speed);
730  if (retval != ERROR_OK)
731  return retval;
732 
733  if (cur_speed)
734  command_print(CMD, "adapter speed: %d kHz", cur_speed);
735  else
736  command_print(CMD, "adapter speed: RCLK - adaptive");
737 
738  return retval;
739 }
740 
741 COMMAND_HANDLER(handle_adapter_serial_command)
742 {
743  if (CMD_ARGC != 1)
745 
746  free(adapter_config.serial);
747  adapter_config.serial = strdup(CMD_ARGV[0]);
748  return ERROR_OK;
749 }
750 
751 COMMAND_HANDLER(handle_adapter_reset_de_assert)
752 {
753  enum values {
754  VALUE_UNDEFINED = -1,
755  VALUE_DEASSERT = 0,
756  VALUE_ASSERT = 1,
757  };
758  enum values value;
759  enum values srst = VALUE_UNDEFINED;
760  enum values trst = VALUE_UNDEFINED;
762  char *signal;
763 
764  if (CMD_ARGC == 0) {
765  if (transport_is_jtag()) {
767  signal = jtag_get_trst() ? "asserted" : "deasserted";
768  else
769  signal = "not present";
770  command_print(CMD, "trst %s", signal);
771  }
772 
774  signal = jtag_get_srst() ? "asserted" : "deasserted";
775  else
776  signal = "not present";
777  command_print(CMD, "srst %s", signal);
778 
779  return ERROR_OK;
780  }
781 
782  if (CMD_ARGC != 1 && CMD_ARGC != 3)
784 
785  value = (strcmp(CMD_NAME, "assert") == 0) ? VALUE_ASSERT : VALUE_DEASSERT;
786  if (strcmp(CMD_ARGV[0], "srst") == 0)
787  srst = value;
788  else if (strcmp(CMD_ARGV[0], "trst") == 0)
789  trst = value;
790  else
792 
793  if (CMD_ARGC == 3) {
794  if (strcmp(CMD_ARGV[1], "assert") == 0)
795  value = VALUE_ASSERT;
796  else if (strcmp(CMD_ARGV[1], "deassert") == 0)
797  value = VALUE_DEASSERT;
798  else
800 
801  if (strcmp(CMD_ARGV[2], "srst") == 0 && srst == VALUE_UNDEFINED)
802  srst = value;
803  else if (strcmp(CMD_ARGV[2], "trst") == 0 && trst == VALUE_UNDEFINED)
804  trst = value;
805  else
807  }
808 
809  if (trst == VALUE_UNDEFINED) {
810  if (transport_is_jtag())
811  trst = jtag_get_trst() ? VALUE_ASSERT : VALUE_DEASSERT;
812  else
813  trst = VALUE_DEASSERT; /* unused, safe value */
814  }
815 
816  if (srst == VALUE_UNDEFINED) {
818  srst = jtag_get_srst() ? VALUE_ASSERT : VALUE_DEASSERT;
819  else
820  srst = VALUE_DEASSERT; /* unused, safe value */
821  }
822 
823  if (trst == VALUE_ASSERT && !transport_is_jtag()) {
824  LOG_ERROR("transport has no trst signal");
825  return ERROR_FAIL;
826  }
827 
828  if (srst == VALUE_ASSERT && !(jtag_reset_config & RESET_HAS_SRST)) {
829  LOG_ERROR("adapter has no srst signal");
830  return ERROR_FAIL;
831  }
832 
833  return adapter_resets((trst == VALUE_DEASSERT) ? TRST_DEASSERT : TRST_ASSERT,
834  (srst == VALUE_DEASSERT) ? SRST_DEASSERT : SRST_ASSERT);
835 }
836 
837 static int get_gpio_index(const char *signal_name)
838 {
839  for (int i = 0; i < ADAPTER_GPIO_IDX_NUM; ++i) {
840  if (strcmp(gpio_map[i].name, signal_name) == 0)
841  return i;
842  }
843  return -1;
844 }
845 
846 static COMMAND_HELPER(helper_adapter_gpio_print_config, enum adapter_gpio_config_index gpio_idx)
847 {
848  struct adapter_gpio_config *gpio_config = &adapter_config.gpios[gpio_idx];
849  const char *active_state = gpio_config->active_low ? "low" : "high";
850  const char *dir = "";
851  const char *drive = "";
852  const char *pull = "";
853  const char *init_state = "";
854 
855  if (gpio_config->gpio_num == ADAPTER_GPIO_NOT_SET) {
856  command_print(CMD, "adapter gpio %s: not configured", gpio_map[gpio_idx].name);
857  return ERROR_OK;
858  }
859 
860  switch (gpio_map[gpio_idx].direction) {
862  dir = "input";
863  break;
865  dir = "output";
866  break;
868  dir = "bidirectional";
869  break;
870  }
871 
872  if (gpio_map[gpio_idx].permit_drive_option) {
873  switch (gpio_config->drive) {
875  drive = ", push-pull";
876  break;
878  drive = ", open-drain";
879  break;
881  drive = ", open-source";
882  break;
883  }
884  }
885 
886  switch (gpio_config->pull) {
888  pull = ", pull-none";
889  break;
891  pull = ", pull-up";
892  break;
894  pull = ", pull-down";
895  break;
896  }
897 
898  if (gpio_map[gpio_idx].permit_init_state_option) {
899  switch (gpio_config->init_state) {
901  init_state = ", init-state inactive";
902  break;
904  init_state = ", init-state active";
905  break;
907  init_state = ", init-state input";
908  break;
909  }
910  }
911 
912  command_print(CMD, "adapter gpio %s (%s): num %u, chip %d, active-%s%s%s%s",
913  gpio_map[gpio_idx].name, dir, gpio_config->gpio_num, (int)gpio_config->chip_num, active_state,
914  drive, pull, init_state);
915 
916  return ERROR_OK;
917 }
918 
919 COMMAND_HANDLER(helper_adapter_gpio_print_all_configs)
920 {
921  for (int i = 0; i < ADAPTER_GPIO_IDX_NUM; ++i)
922  CALL_COMMAND_HANDLER(helper_adapter_gpio_print_config, i);
923  return ERROR_OK;
924 }
925 
926 COMMAND_HANDLER(adapter_gpio_config_handler)
927 {
928  unsigned int i = 1;
929  struct adapter_gpio_config *gpio_config;
930 
932 
933  if (CMD_ARGC == 0) {
934  CALL_COMMAND_HANDLER(helper_adapter_gpio_print_all_configs);
935  return ERROR_OK;
936  }
937 
938  int gpio_idx = get_gpio_index(CMD_ARGV[0]);
939  if (gpio_idx == -1) {
940  LOG_ERROR("adapter has no gpio named %s", CMD_ARGV[0]);
942  }
943 
944  if (CMD_ARGC == 1) {
945  CALL_COMMAND_HANDLER(helper_adapter_gpio_print_config, gpio_idx);
946  return ERROR_OK;
947  }
948 
949  gpio_config = &adapter_config.gpios[gpio_idx];
950  while (i < CMD_ARGC) {
951  LOG_DEBUG("Processing %s", CMD_ARGV[i]);
952 
953  if (isdigit(*CMD_ARGV[i])) {
954  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[i], gpio_config->gpio_num);
955  ++i;
956  continue;
957  }
958 
959  if (strcmp(CMD_ARGV[i], "-chip") == 0) {
960  if (CMD_ARGC - i < 2) {
961  LOG_ERROR("-chip option requires a parameter");
962  return ERROR_FAIL;
963  }
964  LOG_DEBUG("-chip arg is %s", CMD_ARGV[i + 1]);
965  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[i + 1], gpio_config->chip_num);
966  i += 2;
967  continue;
968  }
969 
970  if (strcmp(CMD_ARGV[i], "-active-high") == 0) {
971  ++i;
972  gpio_config->active_low = false;
973  continue;
974  }
975  if (strcmp(CMD_ARGV[i], "-active-low") == 0) {
976  ++i;
977  gpio_config->active_low = true;
978  continue;
979  }
980 
981  if (gpio_map[gpio_idx].permit_drive_option) {
982  if (strcmp(CMD_ARGV[i], "-push-pull") == 0) {
983  ++i;
985  continue;
986  }
987  if (strcmp(CMD_ARGV[i], "-open-drain") == 0) {
988  ++i;
990  continue;
991  }
992  if (strcmp(CMD_ARGV[i], "-open-source") == 0) {
993  ++i;
995  continue;
996  }
997  }
998 
999  if (strcmp(CMD_ARGV[i], "-pull-none") == 0) {
1000  ++i;
1001  gpio_config->pull = ADAPTER_GPIO_PULL_NONE;
1002  continue;
1003  }
1004  if (strcmp(CMD_ARGV[i], "-pull-up") == 0) {
1005  ++i;
1006  gpio_config->pull = ADAPTER_GPIO_PULL_UP;
1007  continue;
1008  }
1009  if (strcmp(CMD_ARGV[i], "-pull-down") == 0) {
1010  ++i;
1011  gpio_config->pull = ADAPTER_GPIO_PULL_DOWN;
1012  continue;
1013  }
1014 
1015  if (gpio_map[gpio_idx].permit_init_state_option) {
1016  if (strcmp(CMD_ARGV[i], "-init-inactive") == 0) {
1017  ++i;
1019  continue;
1020  }
1021  if (strcmp(CMD_ARGV[i], "-init-active") == 0) {
1022  ++i;
1024  continue;
1025  }
1026 
1028  strcmp(CMD_ARGV[i], "-init-input") == 0) {
1029  ++i;
1031  continue;
1032  }
1033  }
1034 
1035  LOG_ERROR("illegal option for adapter %s %s: %s",
1036  CMD_NAME, gpio_map[gpio_idx].name, CMD_ARGV[i]);
1038  }
1039 
1040  /* Force swdio_dir init state to be compatible with swdio init state */
1041  if (gpio_idx == ADAPTER_GPIO_IDX_SWDIO)
1042  adapter_config.gpios[ADAPTER_GPIO_IDX_SWDIO_DIR].init_state =
1043  (gpio_config->init_state == ADAPTER_GPIO_INIT_STATE_INPUT) ?
1046 
1047  return ERROR_OK;
1048 }
1049 
1050 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
1051 COMMAND_HANDLER(handle_usb_location_command)
1052 {
1053  if (CMD_ARGC == 1)
1054  adapter_usb_set_location(CMD_ARGV[0]);
1055 
1056  command_print(CMD, "adapter usb location: %s", adapter_usb_get_location());
1057 
1058  return ERROR_OK;
1059 }
1060 #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */
1061 
1062 static const struct command_registration adapter_usb_command_handlers[] = {
1063 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
1064  {
1065  .name = "location",
1066  .handler = &handle_usb_location_command,
1067  .mode = COMMAND_CONFIG,
1068  .help = "display or set the USB bus location of the USB device",
1069  .usage = "[<bus>-port[.port]...]",
1070  },
1071 #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */
1073 };
1074 
1075 static const struct command_registration adapter_srst_command_handlers[] = {
1076  {
1077  .name = "delay",
1078  .handler = handle_adapter_srst_delay_command,
1079  .mode = COMMAND_ANY,
1080  .help = "delay after deasserting SRST in ms",
1081  .usage = "[milliseconds]",
1082  },
1083  {
1084  .name = "pulse_width",
1085  .handler = handle_adapter_srst_pulse_width_command,
1086  .mode = COMMAND_ANY,
1087  .help = "SRST assertion pulse width in ms",
1088  .usage = "[milliseconds]",
1089  },
1091 };
1092 
1093 static const struct command_registration adapter_command_handlers[] = {
1094  {
1095  .name = "driver",
1096  .handler = handle_adapter_driver_command,
1097  .mode = COMMAND_CONFIG,
1098  .help = "Select a debug adapter driver",
1099  .usage = "driver_name",
1100  },
1101  {
1102  .name = "speed",
1103  .handler = handle_adapter_speed_command,
1104  .mode = COMMAND_ANY,
1105  .help = "With an argument, change to the specified maximum "
1106  "jtag speed. For JTAG, 0 KHz signifies adaptive "
1107  "clocking. "
1108  "With or without argument, display current setting.",
1109  .usage = "[khz]",
1110  },
1111  {
1112  .name = "serial",
1113  .handler = handle_adapter_serial_command,
1114  .mode = COMMAND_CONFIG,
1115  .help = "Set the serial number of the adapter",
1116  .usage = "serial_string",
1117  },
1118  {
1119  .name = "list",
1120  .handler = handle_adapter_list_command,
1121  .mode = COMMAND_ANY,
1122  .help = "List all built-in debug adapter drivers",
1123  .usage = "",
1124  },
1125  {
1126  .name = "name",
1127  .mode = COMMAND_ANY,
1128  .handler = handle_adapter_name,
1129  .help = "Returns the name of the currently "
1130  "selected adapter (driver)",
1131  .usage = "",
1132  },
1133  {
1134  .name = "srst",
1135  .mode = COMMAND_ANY,
1136  .help = "srst adapter command group",
1137  .usage = "",
1139  },
1140  {
1141  .name = "transports",
1142  .handler = adapter_transports_command,
1143  .mode = COMMAND_CONFIG,
1144  .help = "Declare transports the adapter supports.",
1145  .usage = "transport ...",
1146  },
1147  {
1148  .name = "usb",
1149  .mode = COMMAND_ANY,
1150  .help = "usb adapter command group",
1151  .usage = "",
1153  },
1154  {
1155  .name = "assert",
1156  .handler = handle_adapter_reset_de_assert,
1157  .mode = COMMAND_EXEC,
1158  .help = "Controls SRST and TRST lines.",
1159  .usage = "|deassert [srst|trst [assert|deassert srst|trst]]",
1160  },
1161  {
1162  .name = "deassert",
1163  .handler = handle_adapter_reset_de_assert,
1164  .mode = COMMAND_EXEC,
1165  .help = "Controls SRST and TRST lines.",
1166  .usage = "|assert [srst|trst [deassert|assert srst|trst]]",
1167  },
1168  {
1169  .name = "gpio",
1170  .handler = adapter_gpio_config_handler,
1171  .mode = COMMAND_CONFIG,
1172  .help = "gpio adapter command group",
1173  .usage = "[ tdo|tdi|tms|tck|trst|swdio|swdio_dir|swclk|srst|led"
1174  "[gpio_number] "
1175  "[-chip chip_number] "
1176  "[-active-high|-active-low] "
1177  "[-push-pull|-open-drain|-open-source] "
1178  "[-pull-none|-pull-up|-pull-down]"
1179  "[-init-inactive|-init-active|-init-input] ]",
1180  },
1182 };
1183 
1184 static const struct command_registration interface_command_handlers[] = {
1185  {
1186  .name = "adapter",
1187  .mode = COMMAND_ANY,
1188  .help = "adapter command group",
1189  .usage = "",
1190  .chain = adapter_command_handlers,
1191  },
1192  {
1193  .name = "reset_config",
1194  .handler = handle_reset_config_command,
1195  .mode = COMMAND_ANY,
1196  .help = "configure adapter reset behavior",
1197  .usage = "[none|trst_only|srst_only|trst_and_srst] "
1198  "[srst_pulls_trst|trst_pulls_srst|combined|separate] "
1199  "[srst_gates_jtag|srst_nogate] "
1200  "[trst_push_pull|trst_open_drain] "
1201  "[srst_push_pull|srst_open_drain] "
1202  "[connect_deassert_srst|connect_assert_srst]",
1203  },
1205 };
1206 
1214 {
1216 }
1217 
1219 {
1220  return gpio_map[idx].name;
1221 }
1222 
1223 /* Allow drivers access to the GPIO configuration */
1225 {
1226  return adapter_config.gpios;
1227 }
static const struct command_registration adapter_srst_command_handlers[]
Definition: adapter.c:1075
static int adapter_rclk_to_speed(unsigned int fallback_speed_khz, int *speed)
Definition: adapter.c:233
int adapter_config_rclk(unsigned int fallback_speed_khz)
Attempt to enable RTCK/RCLK.
Definition: adapter.c:260
const char * adapter_get_required_serial(void)
Retrieves the serial number set with command 'adapter serial'.
Definition: adapter.c:301
bool adapter_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, size_t path_len)
Definition: adapter.c:332
const struct adapter_gpio_config * adapter_gpio_get_config(void)
Retrieves gpio configuration set with command "adapter gpio <signal_name>".
Definition: adapter.c:1224
static void sync_adapter_reset_with_gpios(void)
Definition: adapter.c:80
const char *const jtag_only[]
Definition: adapter.c:27
static int get_gpio_index(const char *signal_name)
Definition: adapter.c:837
enum adapter_clk_mode clock_mode
Definition: adapter.c:44
COMMAND_HANDLER(handle_adapter_name)
Definition: adapter.c:381
int rclk_fallback_speed_khz
Definition: adapter.c:46
static int adapter_set_speed(int speed)
Definition: adapter.c:243
int adapter_get_speed(int *speed)
Definition: adapter.c:270
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:209
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:214
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:286
static const struct command_registration adapter_usb_command_handlers[]
Definition: adapter.c:1062
#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
static struct @15 adapter_config
Adapter configuration.
const char * adapter_usb_get_location(void)
Definition: adapter.c:327
int adapter_register_commands(struct command_context *ctx)
Register the commands which deal with arbitrary debug adapter drivers.
Definition: adapter.c:1213
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:1093
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:251
struct adapter_driver * adapter_driver
Definition: adapter.c:26
#define USB_MAX_LOCATION_LENGTH
Definition: adapter.c:313
static void adapter_driver_gpios_init(void)
Definition: adapter.c:93
static const struct command_registration interface_command_handlers[]
Definition: adapter.c:1184
static COMMAND_HELPER(helper_adapter_gpio_print_config, enum adapter_gpio_config_index gpio_idx)
Definition: adapter.c:846
const char * adapter_gpio_get_name(enum adapter_gpio_config_index idx)
Retrieves gpio name.
Definition: adapter.c:1218
@ 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(struct command_invocation *cmd, const char *format,...)
Definition: command.c:443
#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:1739
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:1838
int jtag_get_trst(void)
Definition: jtag/core.c:1749
bool transport_is_jtag(void)
Returns true if the current debug session is using JTAG as its transport.
Definition: jtag/core.c:1833
unsigned int jtag_get_nsrst_delay(void)
Definition: jtag/core.c:1762
struct jtag_tap * jtag_all_taps(void)
Definition: jtag/core.c:190
unsigned int jtag_get_nsrst_assert_width(void)
Definition: jtag/core.c:1779
void jtag_set_nsrst_assert_width(unsigned int delay)
Definition: jtag/core.c:1775
static enum reset_types jtag_reset_config
Definition: jtag/core.c:89
int jtag_get_srst(void)
Definition: jtag/core.c:1753
void jtag_tap_free(struct jtag_tap *tap)
Definition: jtag/core.c:1487
void jtag_set_nsrst_delay(unsigned int delay)
Definition: jtag/core.c:1758
void jtag_set_reset_config(enum reset_types type)
Definition: jtag/core.c:1744
enum reset_types jtag_get_reset_config(void)
Definition: jtag/core.c:1740
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:129
#define ERROR_FAIL
Definition: log.h:173
#define LOG_ERROR(expr ...)
Definition: log.h:132
#define LOG_INFO(expr ...)
Definition: log.h:126
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:167
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
Represents a driver for a debugging interface.
Definition: interface.h:207
int(* speed)(int speed)
Set the interface speed.
Definition: interface.h:262
int(* khz)(int khz, int *jtag_speed)
Returns JTAG maximum speed for KHz.
Definition: interface.h:274
int(* speed_div)(int speed, int *khz)
Calculate the clock frequency (in KHz) for the given speed.
Definition: interface.h:283
int(* init)(void)
Interface driver must initialize any resources and connect to a JTAG device.
Definition: interface.h:231
const char *const * transports
transports supported in C code (NULL terminated vector)
Definition: interface.h:212
const char *const name
The name of the interface driver.
Definition: interface.h:209
int(* quit)(void)
Interface driver must tear down all resources and disconnect from the JTAG device.
Definition: interface.h:239
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, const char *const *vector)
Called by debug adapter drivers, or affiliated Tcl config scripts, to declare the set of transports s...
Definition: transport.c:86
#define NULL
Definition: usb.h:16