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