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