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