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