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(dump_adapter_driver_list)
396 {
397  for (unsigned int i = 0; adapter_drivers[i]; i++) {
398  const char *name = adapter_drivers[i]->name;
399  command_print(CMD, "%u: %s", i + 1, name);
400  }
401 
402  return ERROR_OK;
403 }
404 
405 COMMAND_HANDLER(handle_adapter_list_command)
406 {
407  if (CMD_ARGC)
409 
410  return CALL_COMMAND_HANDLER(dump_adapter_driver_list);
411 }
412 
413 COMMAND_HANDLER(handle_adapter_driver_command)
414 {
415  int retval;
416 
417  /* check whether the interface is already configured */
418  if (adapter_driver) {
419  LOG_WARNING("Interface already configured, ignoring");
420  return ERROR_OK;
421  }
422 
423  /* interface name is a mandatory argument */
424  if (CMD_ARGC != 1 || CMD_ARGV[0][0] == '\0')
426 
427  for (unsigned int i = 0; adapter_drivers[i]; i++) {
428  if (strcmp(CMD_ARGV[0], adapter_drivers[i]->name) != 0)
429  continue;
430 
431  if (adapter_drivers[i]->commands) {
432  retval = register_commands(CMD_CTX, NULL, adapter_drivers[i]->commands);
433  if (retval != ERROR_OK)
434  return retval;
435  }
436 
438 
440  }
441 
442  /* no valid interface was found (i.e. the configuration option,
443  * didn't match one of the compiled-in interfaces
444  */
445  LOG_ERROR("The specified debug interface was not found (%s)",
446  CMD_ARGV[0]);
447  command_print(CMD, "The following adapter drivers are available:");
448  CALL_COMMAND_HANDLER(dump_adapter_driver_list);
450 }
451 
452 COMMAND_HANDLER(handle_reset_config_command)
453 {
454  int new_cfg = 0;
455  int mask = 0;
456 
457  /* Original versions cared about the order of these tokens:
458  * reset_config signals [combination [trst_type [srst_type]]]
459  * They also clobbered the previous configuration even on error.
460  *
461  * Here we don't care about the order, and only change values
462  * which have been explicitly specified.
463  */
464  for (; CMD_ARGC; CMD_ARGC--, CMD_ARGV++) {
465  int tmp = 0;
466  int m;
467 
468  /* gating */
470  if (strcmp(*CMD_ARGV, "srst_gates_jtag") == 0)
471  /* default: don't use JTAG while SRST asserted */;
472  else if (strcmp(*CMD_ARGV, "srst_nogate") == 0)
473  tmp = RESET_SRST_NO_GATING;
474  else
475  m = 0;
476  if (mask & m) {
477  LOG_ERROR("extra reset_config %s spec (%s)",
478  "gating", *CMD_ARGV);
480  }
481  if (m)
482  goto next;
483 
484  /* signals */
486  if (strcmp(*CMD_ARGV, "none") == 0)
487  tmp = RESET_NONE;
488  else if (strcmp(*CMD_ARGV, "trst_only") == 0)
489  tmp = RESET_HAS_TRST;
490  else if (strcmp(*CMD_ARGV, "srst_only") == 0)
491  tmp = RESET_HAS_SRST;
492  else if (strcmp(*CMD_ARGV, "trst_and_srst") == 0)
494  else
495  m = 0;
496  if (mask & m) {
497  LOG_ERROR("extra reset_config %s spec (%s)",
498  "signal", *CMD_ARGV);
500  }
501  if (m)
502  goto next;
503 
504  /* combination (options for broken wiring) */
506  if (strcmp(*CMD_ARGV, "separate") == 0)
507  /* separate reset lines - default */;
508  else if (strcmp(*CMD_ARGV, "srst_pulls_trst") == 0)
509  tmp |= RESET_SRST_PULLS_TRST;
510  else if (strcmp(*CMD_ARGV, "trst_pulls_srst") == 0)
511  tmp |= RESET_TRST_PULLS_SRST;
512  else if (strcmp(*CMD_ARGV, "combined") == 0)
514  else
515  m = 0;
516  if (mask & m) {
517  LOG_ERROR("extra reset_config %s spec (%s)",
518  "combination", *CMD_ARGV);
520  }
521  if (m)
522  goto next;
523 
524  /* trst_type (NOP without HAS_TRST) */
526  if (strcmp(*CMD_ARGV, "trst_open_drain") == 0)
527  tmp |= RESET_TRST_OPEN_DRAIN;
528  else if (strcmp(*CMD_ARGV, "trst_push_pull") == 0)
529  /* push/pull from adapter - default */;
530  else
531  m = 0;
532  if (mask & m) {
533  LOG_ERROR("extra reset_config %s spec (%s)",
534  "trst_type", *CMD_ARGV);
536  }
537  if (m)
538  goto next;
539 
540  /* srst_type (NOP without HAS_SRST) */
542  if (strcmp(*CMD_ARGV, "srst_push_pull") == 0)
543  tmp |= RESET_SRST_PUSH_PULL;
544  else if (strcmp(*CMD_ARGV, "srst_open_drain") == 0)
545  /* open drain from adapter - default */;
546  else
547  m = 0;
548  if (mask & m) {
549  LOG_ERROR("extra reset_config %s spec (%s)",
550  "srst_type", *CMD_ARGV);
552  }
553  if (m)
554  goto next;
555 
556  /* connect_type - only valid when srst_nogate */
558  if (strcmp(*CMD_ARGV, "connect_assert_srst") == 0)
559  tmp |= RESET_CNCT_UNDER_SRST;
560  else if (strcmp(*CMD_ARGV, "connect_deassert_srst") == 0)
561  /* connect normally - default */;
562  else
563  m = 0;
564  if (mask & m) {
565  LOG_ERROR("extra reset_config %s spec (%s)",
566  "connect_type", *CMD_ARGV);
568  }
569  if (m)
570  goto next;
571 
572  /* caller provided nonsense; fail */
573  LOG_ERROR("unknown reset_config flag (%s)", *CMD_ARGV);
575 
576 next:
577  /* Remember the bits which were specified (mask)
578  * and their new values (new_cfg).
579  */
580  mask |= m;
581  new_cfg |= tmp;
582  }
583 
584  /* clear previous values of those bits, save new values */
585  if (mask) {
586  int old_cfg = jtag_get_reset_config();
587 
588  old_cfg &= ~mask;
589  new_cfg |= old_cfg;
590  jtag_set_reset_config(new_cfg);
592 
593  } else
594  new_cfg = jtag_get_reset_config();
595 
596  /*
597  * Display the (now-)current reset mode
598  */
599  char *modes[6];
600 
601  /* minimal JTAG has neither SRST nor TRST (so that's the default) */
602  switch (new_cfg & (RESET_HAS_TRST | RESET_HAS_SRST)) {
603  case RESET_HAS_SRST:
604  modes[0] = "srst_only";
605  break;
606  case RESET_HAS_TRST:
607  modes[0] = "trst_only";
608  break;
609  case RESET_TRST_AND_SRST:
610  modes[0] = "trst_and_srst";
611  break;
612  default:
613  modes[0] = "none";
614  break;
615  }
616 
617  /* normally SRST and TRST are decoupled; but bugs happen ... */
618  switch (new_cfg & (RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST)) {
620  modes[1] = "srst_pulls_trst";
621  break;
623  modes[1] = "trst_pulls_srst";
624  break;
626  modes[1] = "combined";
627  break;
628  default:
629  modes[1] = "separate";
630  break;
631  }
632 
633  /* TRST-less connectors include Altera, Xilinx, and minimal JTAG */
634  if (new_cfg & RESET_HAS_TRST) {
635  if (new_cfg & RESET_TRST_OPEN_DRAIN)
636  modes[3] = " trst_open_drain";
637  else
638  modes[3] = " trst_push_pull";
639  } else
640  modes[3] = "";
641 
642  /* SRST-less connectors include TI-14, Xilinx, and minimal JTAG */
643  if (new_cfg & RESET_HAS_SRST) {
644  if (new_cfg & RESET_SRST_NO_GATING)
645  modes[2] = " srst_nogate";
646  else
647  modes[2] = " srst_gates_jtag";
648 
649  if (new_cfg & RESET_SRST_PUSH_PULL)
650  modes[4] = " srst_push_pull";
651  else
652  modes[4] = " srst_open_drain";
653 
654  if (new_cfg & RESET_CNCT_UNDER_SRST)
655  modes[5] = " connect_assert_srst";
656  else
657  modes[5] = " connect_deassert_srst";
658  } else {
659  modes[2] = "";
660  modes[4] = "";
661  modes[5] = "";
662  }
663 
664  command_print(CMD, "%s %s%s%s%s%s",
665  modes[0], modes[1],
666  modes[2], modes[3], modes[4], modes[5]);
667 
668  return ERROR_OK;
669 }
670 
671 COMMAND_HANDLER(handle_adapter_srst_delay_command)
672 {
673  if (CMD_ARGC > 1)
675  if (CMD_ARGC == 1) {
676  unsigned int delay;
677  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], delay);
678 
679  jtag_set_nsrst_delay(delay);
680  }
681  command_print(CMD, "adapter srst delay: %u", jtag_get_nsrst_delay());
682  return ERROR_OK;
683 }
684 
685 COMMAND_HANDLER(handle_adapter_srst_pulse_width_command)
686 {
687  if (CMD_ARGC > 1)
689  if (CMD_ARGC == 1) {
690  unsigned int width;
692 
694  }
695  command_print(CMD, "adapter srst pulse_width: %u", jtag_get_nsrst_assert_width());
696  return ERROR_OK;
697 }
698 
699 COMMAND_HANDLER(handle_adapter_speed_command)
700 {
701  if (CMD_ARGC > 1)
703 
704  int retval = ERROR_OK;
705  if (CMD_ARGC == 1) {
706  unsigned int khz = 0;
707  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], khz);
708 
709  retval = adapter_config_khz(khz);
710  if (retval != ERROR_OK)
711  return retval;
712  }
713 
714  int cur_speed = adapter_get_speed_khz();
715  retval = adapter_get_speed_readable(&cur_speed);
716  if (retval != ERROR_OK)
717  return retval;
718 
719  if (cur_speed)
720  command_print(CMD, "adapter speed: %d kHz", cur_speed);
721  else
722  command_print(CMD, "adapter speed: RCLK - adaptive");
723 
724  return retval;
725 }
726 
727 COMMAND_HANDLER(handle_adapter_serial_command)
728 {
729  if (CMD_ARGC != 1)
731 
732  free(adapter_config.serial);
733  adapter_config.serial = strdup(CMD_ARGV[0]);
734  return ERROR_OK;
735 }
736 
737 COMMAND_HANDLER(handle_adapter_reset_de_assert)
738 {
739  enum values {
740  VALUE_UNDEFINED = -1,
741  VALUE_DEASSERT = 0,
742  VALUE_ASSERT = 1,
743  };
744  enum values value;
745  enum values srst = VALUE_UNDEFINED;
746  enum values trst = VALUE_UNDEFINED;
748  char *signal;
749 
750  if (CMD_ARGC == 0) {
751  if (transport_is_jtag()) {
753  signal = jtag_get_trst() ? "asserted" : "deasserted";
754  else
755  signal = "not present";
756  command_print(CMD, "trst %s", signal);
757  }
758 
760  signal = jtag_get_srst() ? "asserted" : "deasserted";
761  else
762  signal = "not present";
763  command_print(CMD, "srst %s", signal);
764 
765  return ERROR_OK;
766  }
767 
768  if (CMD_ARGC != 1 && CMD_ARGC != 3)
770 
771  value = (strcmp(CMD_NAME, "assert") == 0) ? VALUE_ASSERT : VALUE_DEASSERT;
772  if (strcmp(CMD_ARGV[0], "srst") == 0)
773  srst = value;
774  else if (strcmp(CMD_ARGV[0], "trst") == 0)
775  trst = value;
776  else
778 
779  if (CMD_ARGC == 3) {
780  if (strcmp(CMD_ARGV[1], "assert") == 0)
781  value = VALUE_ASSERT;
782  else if (strcmp(CMD_ARGV[1], "deassert") == 0)
783  value = VALUE_DEASSERT;
784  else
786 
787  if (strcmp(CMD_ARGV[2], "srst") == 0 && srst == VALUE_UNDEFINED)
788  srst = value;
789  else if (strcmp(CMD_ARGV[2], "trst") == 0 && trst == VALUE_UNDEFINED)
790  trst = value;
791  else
793  }
794 
795  if (trst == VALUE_UNDEFINED) {
796  if (transport_is_jtag())
797  trst = jtag_get_trst() ? VALUE_ASSERT : VALUE_DEASSERT;
798  else
799  trst = VALUE_DEASSERT; /* unused, safe value */
800  }
801 
802  if (srst == VALUE_UNDEFINED) {
804  srst = jtag_get_srst() ? VALUE_ASSERT : VALUE_DEASSERT;
805  else
806  srst = VALUE_DEASSERT; /* unused, safe value */
807  }
808 
809  if (trst == VALUE_ASSERT && !transport_is_jtag()) {
810  LOG_ERROR("transport has no trst signal");
811  return ERROR_FAIL;
812  }
813 
814  if (srst == VALUE_ASSERT && !(jtag_reset_config & RESET_HAS_SRST)) {
815  LOG_ERROR("adapter has no srst signal");
816  return ERROR_FAIL;
817  }
818 
819  return adapter_resets((trst == VALUE_DEASSERT) ? TRST_DEASSERT : TRST_ASSERT,
820  (srst == VALUE_DEASSERT) ? SRST_DEASSERT : SRST_ASSERT);
821 }
822 
823 static int get_gpio_index(const char *signal_name)
824 {
825  for (int i = 0; i < ADAPTER_GPIO_IDX_NUM; ++i) {
826  if (strcmp(gpio_map[i].name, signal_name) == 0)
827  return i;
828  }
829  return -1;
830 }
831 
832 static COMMAND_HELPER(helper_adapter_gpio_print_config, enum adapter_gpio_config_index gpio_idx)
833 {
834  struct adapter_gpio_config *gpio_config = &adapter_config.gpios[gpio_idx];
835  const char *active_state = gpio_config->active_low ? "low" : "high";
836  const char *dir = "";
837  const char *drive = "";
838  const char *pull = "";
839  const char *init_state = "";
840 
841  if (gpio_config->gpio_num == ADAPTER_GPIO_NOT_SET) {
842  command_print(CMD, "adapter gpio %s: not configured", gpio_map[gpio_idx].name);
843  return ERROR_OK;
844  }
845 
846  switch (gpio_map[gpio_idx].direction) {
848  dir = "input";
849  break;
851  dir = "output";
852  break;
854  dir = "bidirectional";
855  break;
856  }
857 
858  if (gpio_map[gpio_idx].permit_drive_option) {
859  switch (gpio_config->drive) {
861  drive = ", push-pull";
862  break;
864  drive = ", open-drain";
865  break;
867  drive = ", open-source";
868  break;
869  }
870  }
871 
872  switch (gpio_config->pull) {
874  pull = ", pull-none";
875  break;
877  pull = ", pull-up";
878  break;
880  pull = ", pull-down";
881  break;
882  }
883 
884  if (gpio_map[gpio_idx].permit_init_state_option) {
885  switch (gpio_config->init_state) {
887  init_state = ", init-state inactive";
888  break;
890  init_state = ", init-state active";
891  break;
893  init_state = ", init-state input";
894  break;
895  }
896  }
897 
898  command_print(CMD, "adapter gpio %s (%s): num %u, chip %d, active-%s%s%s%s",
899  gpio_map[gpio_idx].name, dir, gpio_config->gpio_num, (int)gpio_config->chip_num, active_state,
900  drive, pull, init_state);
901 
902  return ERROR_OK;
903 }
904 
905 COMMAND_HANDLER(helper_adapter_gpio_print_all_configs)
906 {
907  for (int i = 0; i < ADAPTER_GPIO_IDX_NUM; ++i)
908  CALL_COMMAND_HANDLER(helper_adapter_gpio_print_config, i);
909  return ERROR_OK;
910 }
911 
912 COMMAND_HANDLER(adapter_gpio_config_handler)
913 {
914  unsigned int i = 1;
915  struct adapter_gpio_config *gpio_config;
916 
918 
919  if (CMD_ARGC == 0) {
920  CALL_COMMAND_HANDLER(helper_adapter_gpio_print_all_configs);
921  return ERROR_OK;
922  }
923 
924  int gpio_idx = get_gpio_index(CMD_ARGV[0]);
925  if (gpio_idx == -1) {
926  LOG_ERROR("adapter has no gpio named %s", CMD_ARGV[0]);
928  }
929 
930  if (CMD_ARGC == 1) {
931  CALL_COMMAND_HANDLER(helper_adapter_gpio_print_config, gpio_idx);
932  return ERROR_OK;
933  }
934 
935  gpio_config = &adapter_config.gpios[gpio_idx];
936  while (i < CMD_ARGC) {
937  LOG_DEBUG("Processing %s", CMD_ARGV[i]);
938 
939  if (isdigit(*CMD_ARGV[i])) {
940  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[i], gpio_config->gpio_num);
941  ++i;
942  continue;
943  }
944 
945  if (strcmp(CMD_ARGV[i], "-chip") == 0) {
946  if (CMD_ARGC - i < 2) {
947  LOG_ERROR("-chip option requires a parameter");
948  return ERROR_FAIL;
949  }
950  LOG_DEBUG("-chip arg is %s", CMD_ARGV[i + 1]);
951  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[i + 1], gpio_config->chip_num);
952  i += 2;
953  continue;
954  }
955 
956  if (strcmp(CMD_ARGV[i], "-active-high") == 0) {
957  ++i;
958  gpio_config->active_low = false;
959  continue;
960  }
961  if (strcmp(CMD_ARGV[i], "-active-low") == 0) {
962  ++i;
963  gpio_config->active_low = true;
964  continue;
965  }
966 
967  if (gpio_map[gpio_idx].permit_drive_option) {
968  if (strcmp(CMD_ARGV[i], "-push-pull") == 0) {
969  ++i;
971  continue;
972  }
973  if (strcmp(CMD_ARGV[i], "-open-drain") == 0) {
974  ++i;
976  continue;
977  }
978  if (strcmp(CMD_ARGV[i], "-open-source") == 0) {
979  ++i;
981  continue;
982  }
983  }
984 
985  if (strcmp(CMD_ARGV[i], "-pull-none") == 0) {
986  ++i;
987  gpio_config->pull = ADAPTER_GPIO_PULL_NONE;
988  continue;
989  }
990  if (strcmp(CMD_ARGV[i], "-pull-up") == 0) {
991  ++i;
992  gpio_config->pull = ADAPTER_GPIO_PULL_UP;
993  continue;
994  }
995  if (strcmp(CMD_ARGV[i], "-pull-down") == 0) {
996  ++i;
997  gpio_config->pull = ADAPTER_GPIO_PULL_DOWN;
998  continue;
999  }
1000 
1001  if (gpio_map[gpio_idx].permit_init_state_option) {
1002  if (strcmp(CMD_ARGV[i], "-init-inactive") == 0) {
1003  ++i;
1005  continue;
1006  }
1007  if (strcmp(CMD_ARGV[i], "-init-active") == 0) {
1008  ++i;
1010  continue;
1011  }
1012 
1014  strcmp(CMD_ARGV[i], "-init-input") == 0) {
1015  ++i;
1017  continue;
1018  }
1019  }
1020 
1021  LOG_ERROR("illegal option for adapter %s %s: %s",
1022  CMD_NAME, gpio_map[gpio_idx].name, CMD_ARGV[i]);
1024  }
1025 
1026  /* Force swdio_dir init state to be compatible with swdio init state */
1027  if (gpio_idx == ADAPTER_GPIO_IDX_SWDIO)
1028  adapter_config.gpios[ADAPTER_GPIO_IDX_SWDIO_DIR].init_state =
1029  (gpio_config->init_state == ADAPTER_GPIO_INIT_STATE_INPUT) ?
1032 
1033  return ERROR_OK;
1034 }
1035 
1036 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
1037 COMMAND_HANDLER(handle_usb_location_command)
1038 {
1039  if (CMD_ARGC == 1)
1040  adapter_usb_set_location(CMD_ARGV[0]);
1041 
1042  command_print(CMD, "adapter usb location: %s", adapter_usb_get_location());
1043 
1044  return ERROR_OK;
1045 }
1046 #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */
1047 
1048 static const struct command_registration adapter_usb_command_handlers[] = {
1049 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
1050  {
1051  .name = "location",
1052  .handler = &handle_usb_location_command,
1053  .mode = COMMAND_CONFIG,
1054  .help = "display or set the USB bus location of the USB device",
1055  .usage = "[<bus>-port[.port]...]",
1056  },
1057 #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */
1059 };
1060 
1061 static const struct command_registration adapter_srst_command_handlers[] = {
1062  {
1063  .name = "delay",
1064  .handler = handle_adapter_srst_delay_command,
1065  .mode = COMMAND_ANY,
1066  .help = "delay after deasserting SRST in ms",
1067  .usage = "[milliseconds]",
1068  },
1069  {
1070  .name = "pulse_width",
1071  .handler = handle_adapter_srst_pulse_width_command,
1072  .mode = COMMAND_ANY,
1073  .help = "SRST assertion pulse width in ms",
1074  .usage = "[milliseconds]",
1075  },
1077 };
1078 
1079 static const struct command_registration adapter_command_handlers[] = {
1080  {
1081  .name = "driver",
1082  .handler = handle_adapter_driver_command,
1083  .mode = COMMAND_CONFIG,
1084  .help = "Select a debug adapter driver",
1085  .usage = "driver_name",
1086  },
1087  {
1088  .name = "speed",
1089  .handler = handle_adapter_speed_command,
1090  .mode = COMMAND_ANY,
1091  .help = "With an argument, change to the specified maximum "
1092  "jtag speed. For JTAG, 0 KHz signifies adaptive "
1093  "clocking. "
1094  "With or without argument, display current setting.",
1095  .usage = "[khz]",
1096  },
1097  {
1098  .name = "serial",
1099  .handler = handle_adapter_serial_command,
1100  .mode = COMMAND_CONFIG,
1101  .help = "Set the serial number of the adapter",
1102  .usage = "serial_string",
1103  },
1104  {
1105  .name = "list",
1106  .handler = handle_adapter_list_command,
1107  .mode = COMMAND_ANY,
1108  .help = "List all built-in debug adapter drivers",
1109  .usage = "",
1110  },
1111  {
1112  .name = "name",
1113  .mode = COMMAND_ANY,
1114  .handler = handle_adapter_name,
1115  .help = "Returns the name of the currently "
1116  "selected adapter (driver)",
1117  .usage = "",
1118  },
1119  {
1120  .name = "srst",
1121  .mode = COMMAND_ANY,
1122  .help = "srst adapter command group",
1123  .usage = "",
1125  },
1126  {
1127  .name = "usb",
1128  .mode = COMMAND_ANY,
1129  .help = "usb adapter command group",
1130  .usage = "",
1132  },
1133  {
1134  .name = "assert",
1135  .handler = handle_adapter_reset_de_assert,
1136  .mode = COMMAND_EXEC,
1137  .help = "Controls SRST and TRST lines.",
1138  .usage = "|deassert [srst|trst [assert|deassert srst|trst]]",
1139  },
1140  {
1141  .name = "deassert",
1142  .handler = handle_adapter_reset_de_assert,
1143  .mode = COMMAND_EXEC,
1144  .help = "Controls SRST and TRST lines.",
1145  .usage = "|assert [srst|trst [deassert|assert srst|trst]]",
1146  },
1147  {
1148  .name = "gpio",
1149  .handler = adapter_gpio_config_handler,
1150  .mode = COMMAND_CONFIG,
1151  .help = "gpio adapter command group",
1152  .usage = "[ tdo|tdi|tms|tck|trst|swdio|swdio_dir|swclk|srst|led"
1153  "[gpio_number] "
1154  "[-chip chip_number] "
1155  "[-active-high|-active-low] "
1156  "[-push-pull|-open-drain|-open-source] "
1157  "[-pull-none|-pull-up|-pull-down]"
1158  "[-init-inactive|-init-active|-init-input] ]",
1159  },
1161 };
1162 
1163 static const struct command_registration interface_command_handlers[] = {
1164  {
1165  .name = "adapter",
1166  .mode = COMMAND_ANY,
1167  .help = "adapter command group",
1168  .usage = "",
1169  .chain = adapter_command_handlers,
1170  },
1171  {
1172  .name = "reset_config",
1173  .handler = handle_reset_config_command,
1174  .mode = COMMAND_ANY,
1175  .help = "configure adapter reset behavior",
1176  .usage = "[none|trst_only|srst_only|trst_and_srst] "
1177  "[srst_pulls_trst|trst_pulls_srst|combined|separate] "
1178  "[srst_gates_jtag|srst_nogate] "
1179  "[trst_push_pull|trst_open_drain] "
1180  "[srst_push_pull|srst_open_drain] "
1181  "[connect_deassert_srst|connect_assert_srst]",
1182  },
1184 };
1185 
1193 {
1195 }
1196 
1198 {
1199  return gpio_map[idx].name;
1200 }
1201 
1202 /* Allow drivers access to the GPIO configuration */
1204 {
1205  return adapter_config.gpios;
1206 }
static const struct command_registration adapter_srst_command_handlers[]
Definition: adapter.c:1061
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:1203
static void sync_adapter_reset_with_gpios(void)
Definition: adapter.c:80
static struct @16 adapter_config
Adapter configuration.
const char *const jtag_only[]
Definition: adapter.c:27
static int get_gpio_index(const char *signal_name)
Definition: adapter.c:823
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:1048
#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:327
int adapter_register_commands(struct command_context *ctx)
Register the commands which deal with arbitrary debug adapter drivers.
Definition: adapter.c:1192
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:1079
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:1163
static COMMAND_HELPER(helper_adapter_gpio_print_config, enum adapter_gpio_config_index gpio_idx)
Definition: adapter.c:832
const char * adapter_gpio_get_name(enum adapter_gpio_config_index idx)
Retrieves gpio name.
Definition: adapter.c:1197
@ 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: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
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