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