OpenOCD
vsllink.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2009-2010 by Simon Qian <SimonQian@SimonQian.com> *
5  ***************************************************************************/
6 
7 /* Versaloon is a programming tool for multiple MCUs.
8  * It's distributed under GPLv3.
9  * You can find it at http://www.Versaloon.com/.
10  */
11 
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15 
16 #include <jtag/adapter.h>
17 #include <jtag/interface.h>
18 #include <jtag/commands.h>
19 #include <jtag/swd.h>
20 #include <libusb.h>
21 
23 #include "versaloon/versaloon.h"
24 
25 static int vsllink_tms_offset;
26 
27 struct pending_scan_result {
30  int length; /* Number of bits to read */
31  struct scan_command *command; /* Corresponding scan command */
32  uint8_t *ack;
33  uint8_t *buffer;
34  bool last; /* indicate the last scan pending */
35 };
36 
37 #define MAX_PENDING_SCAN_RESULTS 256
38 
40 static struct pending_scan_result
42 
43 /* Queue command functions */
45 static void vsllink_state_move(void);
46 static void vsllink_path_move(int num_states, tap_state_t *path);
47 static void vsllink_tms(int num_bits, const uint8_t *bits);
48 static void vsllink_runtest(int num_cycles);
49 static void vsllink_stableclocks(int num_cycles, int tms);
50 static void vsllink_scan(bool ir_scan, enum scan_type type,
51  uint8_t *buffer, int scan_size, struct scan_command *command);
52 static int vsllink_reset(int trst, int srst);
53 
54 /* VSLLink tap buffer functions */
55 static void vsllink_tap_append_step(int tms, int tdi);
56 static void vsllink_tap_init(void);
57 static int vsllink_tap_execute(void);
58 static void vsllink_tap_ensure_pending(int scans);
59 static void vsllink_tap_append_scan(int length, uint8_t *buffer,
60  struct scan_command *command);
61 
62 /* VSLLink SWD functions */
63 static int_least32_t vsllink_swd_frequency(int_least32_t hz);
64 static int vsllink_swd_switch_seq(enum swd_special_seq seq);
65 
66 /* VSLLink lowlevel functions */
67 struct vsllink {
68  struct libusb_context *libusb_ctx;
69  struct libusb_device_handle *usb_device_handle;
70 };
71 
72 static int vsllink_usb_open(struct vsllink *vsllink);
73 static void vsllink_usb_close(struct vsllink *vsllink);
74 
75 static void vsllink_debug_buffer(uint8_t *buffer, int length);
76 
77 static int tap_length;
78 static int tap_buffer_size;
79 static uint8_t *tms_buffer;
80 static uint8_t *tdi_buffer;
81 static uint8_t *tdo_buffer;
82 
83 static bool swd_mode;
84 
85 static struct vsllink *vsllink_handle;
86 
87 static int vsllink_execute_queue(struct jtag_command *cmd_queue)
88 {
89  struct jtag_command *cmd = cmd_queue;
90  int scan_size;
91  enum scan_type type;
92  uint8_t *buffer;
93 
94  LOG_DEBUG_IO("-------------------------------------"
95  " vsllink "
96  "-------------------------------------");
97 
98  while (cmd) {
99  switch (cmd->type) {
100  case JTAG_RUNTEST:
101  LOG_DEBUG_IO("runtest %i cycles, end in %s",
102  cmd->cmd.runtest->num_cycles,
103  tap_state_name(cmd->cmd.runtest->end_state));
104 
105  vsllink_end_state(cmd->cmd.runtest->end_state);
106  vsllink_runtest(cmd->cmd.runtest->num_cycles);
107  break;
108 
109  case JTAG_TLR_RESET:
110  LOG_DEBUG_IO("statemove end in %s",
111  tap_state_name(cmd->cmd.statemove->end_state));
112 
113  vsllink_end_state(cmd->cmd.statemove->end_state);
115  break;
116 
117  case JTAG_PATHMOVE:
118  LOG_DEBUG_IO("pathmove: %i states, end in %s",
119  cmd->cmd.pathmove->num_states,
120  tap_state_name(cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]));
121 
122  vsllink_path_move(cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path);
123  break;
124 
125  case JTAG_SCAN:
126  LOG_DEBUG_IO("JTAG Scan...");
127 
128  vsllink_end_state(cmd->cmd.scan->end_state);
129 
130  scan_size = jtag_build_buffer(
131  cmd->cmd.scan, &buffer);
132 
133  if (cmd->cmd.scan->ir_scan)
134  LOG_DEBUG_IO(
135  "JTAG Scan write IR(%d bits), "
136  "end in %s:",
137  scan_size,
138  tap_state_name(cmd->cmd.scan->end_state));
139 
140  else
141  LOG_DEBUG_IO(
142  "JTAG Scan write DR(%d bits), "
143  "end in %s:",
144  scan_size,
145  tap_state_name(cmd->cmd.scan->end_state));
146 
148  vsllink_debug_buffer(buffer, DIV_ROUND_UP(scan_size, 8));
149 
150  type = jtag_scan_type(cmd->cmd.scan);
151 
152  vsllink_scan(cmd->cmd.scan->ir_scan,
153  type, buffer, scan_size,
154  cmd->cmd.scan);
155  break;
156 
157  case JTAG_SLEEP:
158  LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
160  jtag_sleep(cmd->cmd.sleep->us);
161  break;
162 
163  case JTAG_STABLECLOCKS:
164  LOG_DEBUG_IO("add %d clocks",
165  cmd->cmd.stableclocks->num_cycles);
166 
167  switch (tap_get_state()) {
168  case TAP_RESET:
169  /* tms must be '1' to stay
170  * n TAP_RESET mode
171  */
172  scan_size = 1;
173  break;
174  case TAP_DRSHIFT:
175  case TAP_IDLE:
176  case TAP_DRPAUSE:
177  case TAP_IRSHIFT:
178  case TAP_IRPAUSE:
179  /* else, tms should be '0' */
180  scan_size = 0;
181  break;
182  /* above stable states are OK */
183  default:
184  LOG_ERROR("jtag_add_clocks() "
185  "in non-stable state \"%s\"",
187  );
188  exit(-1);
189  }
190  vsllink_stableclocks(cmd->cmd.stableclocks->num_cycles, scan_size);
191  break;
192 
193  case JTAG_TMS:
194  LOG_DEBUG_IO("add %d jtag tms",
195  cmd->cmd.tms->num_bits);
196 
197  vsllink_tms(cmd->cmd.tms->num_bits, cmd->cmd.tms->bits);
198  break;
199 
200  default:
201  LOG_ERROR("BUG: unknown JTAG command type "
202  "encountered: %d", cmd->type);
203  exit(-1);
204  }
205  cmd = cmd->next;
206  }
207 
208  return vsllink_tap_execute();
209 }
210 
211 static int vsllink_speed(int speed)
212 {
213  if (swd_mode) {
214  vsllink_swd_frequency(speed * 1000);
215  return ERROR_OK;
216  }
217 
218  versaloon_interface.adaptors.jtag_raw.config(0, (uint16_t)speed);
220 }
221 
222 static int vsllink_khz(int khz, int *jtag_speed)
223 {
224  *jtag_speed = khz;
225 
226  return ERROR_OK;
227 }
228 
229 static int vsllink_speed_div(int jtag_speed, int *khz)
230 {
231  *khz = jtag_speed;
232 
233  return ERROR_OK;
234 }
235 
236 static void vsllink_free_buffer(void)
237 {
238  free(tdi_buffer);
239  tdi_buffer = NULL;
240 
241  free(tdo_buffer);
242  tdo_buffer = NULL;
243 
244  free(tms_buffer);
245  tms_buffer = NULL;
246 }
247 
248 static int vsllink_quit(void)
249 {
251  0, 0, GPIO_SRST | GPIO_TRST);
253 
254  if (swd_mode)
256  else
258 
261 
264 
265  libusb_exit(vsllink_handle->libusb_ctx);
266  free(vsllink_handle);
267 
268  return ERROR_OK;
269 }
270 
271 static int vsllink_interface_init(void)
272 {
273  vsllink_handle = malloc(sizeof(struct vsllink));
274  if (!vsllink_handle) {
275  LOG_ERROR("unable to allocate memory");
276  return ERROR_FAIL;
277  }
278 
279  libusb_init(&vsllink_handle->libusb_ctx);
280 
282  LOG_ERROR("Can't find USB JTAG Interface!"
283  "Please check connection and permissions.");
284  return ERROR_JTAG_INIT_FAILED;
285  }
286  LOG_DEBUG("vsllink found on %04X:%04X",
290 
292  return ERROR_FAIL;
295  return ERROR_FAIL;
296  }
297 
298  return ERROR_OK;
299 }
300 
301 static int vsllink_init(void)
302 {
303  int retval = vsllink_interface_init();
304  if (retval != ERROR_OK)
305  return retval;
306 
309  GPIO_SRST);
312 
313  if (swd_mode) {
319 
320  } else {
321  /* malloc buffer size for tap */
324  tdi_buffer = malloc(tap_buffer_size);
325  tdo_buffer = malloc(tap_buffer_size);
326  tms_buffer = malloc(tap_buffer_size);
327  if ((!tdi_buffer) || (!tdo_buffer) || (!tms_buffer)) {
328  vsllink_quit();
329  return ERROR_FAIL;
330  }
331 
336  }
337 
339  return ERROR_FAIL;
340 
341  vsllink_reset(0, 0);
343  return ERROR_OK;
344 }
345 
346 /**************************************************************************
347  * Queue command implementations */
348 
350 {
353  else {
354  LOG_ERROR("BUG: %i is not a valid end state", state);
355  exit(-1);
356  }
357 }
358 
359 /* Goes to the end state. */
360 static void vsllink_state_move(void)
361 {
362  int i;
363  uint8_t tms_scan = tap_get_tms_path(tap_get_state(),
365  uint8_t tms_scan_bits = tap_get_tms_path_len(tap_get_state(),
367 
368  for (i = 0; i < tms_scan_bits; i++)
369  vsllink_tap_append_step((tms_scan >> i) & 1, 0);
370 
372 }
373 
374 static void vsllink_path_move(int num_states, tap_state_t *path)
375 {
376  for (int i = 0; i < num_states; i++) {
377  if (path[i] == tap_state_transition(tap_get_state(), false))
379  else if (path[i] == tap_state_transition(tap_get_state(), true))
381  else {
382  LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
384  tap_state_name(path[i]));
385  exit(-1);
386  }
387 
388  tap_set_state(path[i]);
389  }
390 
392 }
393 
394 static void vsllink_tms(int num_bits, const uint8_t *bits)
395 {
396  for (int i = 0; i < num_bits; i++)
397  vsllink_tap_append_step((bits[i / 8] >> (i % 8)) & 1, 0);
398 }
399 
400 static void vsllink_stableclocks(int num_cycles, int tms)
401 {
402  while (num_cycles > 0) {
403  vsllink_tap_append_step(tms, 0);
404  num_cycles--;
405  }
406 }
407 
408 static void vsllink_runtest(int num_cycles)
409 {
410  tap_state_t saved_end_state = tap_get_end_state();
411 
412  if (tap_get_state() != TAP_IDLE) {
413  /* enter IDLE state */
416  }
417 
418  vsllink_stableclocks(num_cycles, 0);
419 
420  /* post-process */
421  /* set end_state */
422  vsllink_end_state(saved_end_state);
425 }
426 
427 static void vsllink_scan(bool ir_scan, enum scan_type type, uint8_t *buffer,
428  int scan_size, struct scan_command *command)
429 {
430  tap_state_t saved_end_state;
431 
432  saved_end_state = tap_get_end_state();
433 
434  /* Move to appropriate scan state */
436 
437  if (tap_get_state() != tap_get_end_state())
439  vsllink_end_state(saved_end_state);
440 
441  /* Scan */
443 
444  /* Goto Pause and record position to insert tms:0 */
447 
449 
450  if (tap_get_state() != tap_get_end_state())
452 }
453 
454 static int vsllink_reset(int trst, int srst)
455 {
456  LOG_DEBUG("trst: %i, srst: %i", trst, srst);
457 
458  if (!srst)
460  else
462 
463  if (!swd_mode) {
464  if (!trst)
466  else
468  }
469 
471 }
472 
473 COMMAND_HANDLER(vsllink_handle_usb_vid_command)
474 {
475  if (CMD_ARGC != 1)
477 
480  return ERROR_OK;
481 }
482 
483 COMMAND_HANDLER(vsllink_handle_usb_pid_command)
484 {
485  if (CMD_ARGC != 1)
489  return ERROR_OK;
490 }
491 
492 COMMAND_HANDLER(vsllink_handle_usb_bulkin_command)
493 {
494  if (CMD_ARGC != 1)
496 
499 
501 
502  return ERROR_OK;
503 }
504 
505 COMMAND_HANDLER(vsllink_handle_usb_bulkout_command)
506 {
507  if (CMD_ARGC != 1)
509 
512 
514 
515  return ERROR_OK;
516 }
517 
518 COMMAND_HANDLER(vsllink_handle_usb_interface_command)
519 {
520  if (CMD_ARGC != 1)
522 
525  return ERROR_OK;
526 }
527 
528 /**************************************************************************
529  * VSLLink tap functions */
530 
531 static void vsllink_tap_init(void)
532 {
533  tap_length = 0;
535  vsllink_tms_offset = 0;
536 }
537 
538 static void vsllink_tap_ensure_pending(int scans)
539 {
540  int available_scans =
542 
543  if (scans > available_scans)
545 }
546 
547 static void vsllink_tap_append_step(int tms, int tdi)
548 {
549  int index_var = tap_length / 8;
550 
551  int bit_index = tap_length % 8;
552  uint8_t bit = 1 << bit_index;
553 
554  if (tms)
555  tms_buffer[index_var] |= bit;
556  else
557  tms_buffer[index_var] &= ~bit;
558 
559  if (tdi)
560  tdi_buffer[index_var] |= bit;
561  else
562  tdi_buffer[index_var] &= ~bit;
563 
564  tap_length++;
565 
566  if (tap_buffer_size * 8 <= tap_length)
568 }
569 
570 static void vsllink_tap_append_scan(int length, uint8_t *buffer,
571  struct scan_command *command)
572 {
574  int len_tmp, len_all, i;
575 
576  len_all = 0;
577  while (len_all < length) {
582 
583  if ((length - len_all) > (tap_buffer_size * 8 - tap_length)) {
584  /* Use all memory available
585  vsllink_tap_append_step will commit automatically */
586  len_tmp = tap_buffer_size * 8 - tap_length;
587  pending_scan_result->last = false;
588  } else {
589  len_tmp = length - len_all;
590  pending_scan_result->last = true;
591  }
593  pending_scan_result->dest_offset = len_all;
594  pending_scan_result->length = len_tmp;
598 
599  for (i = 0; i < len_tmp; i++) {
600  vsllink_tap_append_step(((len_all + i) < length-1
601  ? 0 : 1),
602  (buffer[(len_all + i)/8]
603  >> ((len_all + i)%8)) & 1);
604  }
605 
606  len_all += len_tmp;
607  }
608 }
609 
610 static int vsllink_jtag_execute(void)
611 {
612  int i;
613  int result;
614 
615  if (tap_length <= 0)
616  return ERROR_OK;
617 
620 
622 
623  if (result == ERROR_OK) {
624  for (i = 0; i < pending_scan_results_length; i++) {
627  uint8_t *buffer = pending_scan_result->buffer;
629  int src_first = pending_scan_result->src_offset;
630  int dest_first = pending_scan_result->dest_offset;
631  bool last = pending_scan_result->last;
632 
633  struct scan_command *command;
634 
636  buf_set_buf(tdo_buffer, src_first, buffer, dest_first, length);
637 
638  LOG_DEBUG_IO(
639  "JTAG scan read(%d bits, from src %d bits to dest %d bits):",
640  length, src_first, dest_first);
642  vsllink_debug_buffer(buffer + dest_first / 8, DIV_ROUND_UP(length, 7));
643 
644  if (last) {
646  != ERROR_OK) {
649  }
650 
652  }
653  }
654  } else {
655  LOG_ERROR("vsllink_jtag_execute failure");
657  }
658 
660 
661  return ERROR_OK;
662 }
663 
664 static int vsllink_tap_execute(void)
665 {
666  if (swd_mode)
667  return ERROR_OK;
668 
669  return vsllink_jtag_execute();
670 }
671 
672 static int vsllink_swd_init(void)
673 {
674  LOG_INFO("VSLLink SWD mode enabled");
675  swd_mode = true;
676 
677  return ERROR_OK;
678 }
679 
680 static int_least32_t vsllink_swd_frequency(int_least32_t hz)
681 {
682  const int_least32_t delay2hz[] = {
683  1850000, 235000, 130000, 102000, 85000, 72000
684  };
685 
686  if (hz > 0) {
687  uint16_t delay = UINT16_MAX;
688 
689  for (uint16_t i = 0; i < ARRAY_SIZE(delay2hz); i++) {
690  if (hz >= delay2hz[i]) {
691  hz = delay2hz[i];
692  delay = i;
693  break;
694  }
695  }
696 
697  if (delay == UINT16_MAX)
698  delay = (500000 / hz) - 1;
699 
700  /* Calculate retry count after a WAIT response. This will give
701  * a retry timeout at about ~250 ms. 54 is the number of bits
702  * found in a transaction. */
703  uint16_t retry_count = 250 * hz / 1000 / 54;
704 
705  LOG_DEBUG("SWD delay: %d, retry count: %d", delay, retry_count);
706 
707  versaloon_interface.adaptors.swd.config(0, 2, retry_count, delay);
708  }
709 
710  return hz;
711 }
712 
714 {
715  switch (seq) {
716  case LINE_RESET:
717  LOG_DEBUG("SWD line reset");
720  break;
721  case JTAG_TO_SWD:
722  LOG_DEBUG("JTAG-to-SWD");
725  break;
726  case SWD_TO_JTAG:
727  LOG_DEBUG("SWD-to-JTAG");
730  break;
731  default:
732  LOG_ERROR("Sequence %d not supported", seq);
733  return ERROR_FAIL;
734  }
735 
736  return ERROR_OK;
737 }
738 
739 static void vsllink_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
740 {
742 }
743 
744 static void vsllink_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
745 {
747 }
748 
749 static int vsllink_swd_run_queue(void)
750 {
752 }
753 
754 /****************************************************************************
755  * VSLLink USB low-level functions */
756 
758  struct libusb_device_handle *usb_device_handle,
759  struct libusb_device_descriptor *usb_desc)
760 {
761  char desc_string[256];
762  int retval;
763 
765  retval = libusb_get_string_descriptor_ascii(usb_device_handle,
766  usb_desc->iSerialNumber, (unsigned char *)desc_string,
767  sizeof(desc_string));
768  if (retval < 0)
769  return ERROR_FAIL;
770 
771  if (strncmp(desc_string, adapter_get_required_serial(),
772  sizeof(desc_string)))
773  return ERROR_FAIL;
774  }
775 
776  retval = libusb_get_string_descriptor_ascii(usb_device_handle,
777  usb_desc->iProduct, (unsigned char *)desc_string,
778  sizeof(desc_string));
779  if (retval < 0)
780  return ERROR_FAIL;
781 
782  if (!strstr(desc_string, "Versaloon"))
783  return ERROR_FAIL;
784 
785  return ERROR_OK;
786 }
787 
788 static int vsllink_usb_open(struct vsllink *vsllink)
789 {
790  ssize_t num_devices, i;
791  struct libusb_device **usb_devices;
792  struct libusb_device_descriptor usb_desc;
793  struct libusb_device_handle *usb_device_handle;
794  int retval;
795 
796  num_devices = libusb_get_device_list(vsllink->libusb_ctx, &usb_devices);
797 
798  if (num_devices <= 0)
799  return ERROR_FAIL;
800 
801  for (i = 0; i < num_devices; i++) {
802  struct libusb_device *device = usb_devices[i];
803 
804  retval = libusb_get_device_descriptor(device, &usb_desc);
805  if (retval != 0)
806  continue;
807 
808  if (usb_desc.idVendor != versaloon_interface.usb_setting.vid ||
809  usb_desc.idProduct != versaloon_interface.usb_setting.pid)
810  continue;
811 
812  retval = libusb_open(device, &usb_device_handle);
813  if (retval != 0)
814  continue;
815 
816  retval = vsllink_check_usb_strings(usb_device_handle, &usb_desc);
817  if (retval == ERROR_OK)
818  break;
819 
820  libusb_close(usb_device_handle);
821  }
822 
823  libusb_free_device_list(usb_devices, 1);
824 
825  if (i == num_devices)
826  return ERROR_FAIL;
827 
828  retval = libusb_claim_interface(usb_device_handle,
830  if (retval != 0) {
831  LOG_ERROR("unable to claim interface");
832  libusb_close(usb_device_handle);
833  return ERROR_FAIL;
834  }
835 
836  vsllink->usb_device_handle = usb_device_handle;
837  return ERROR_OK;
838 }
839 
840 static void vsllink_usb_close(struct vsllink *vsllink)
841 {
842  libusb_release_interface(vsllink->usb_device_handle,
844  libusb_close(vsllink->usb_device_handle);
845 }
846 
847 #define BYTES_PER_LINE 16
848 
849 static void vsllink_debug_buffer(uint8_t *buffer, int length)
850 {
851  char line[81];
852  char s[4];
853  int i;
854  int j;
855 
856  for (i = 0; i < length; i += BYTES_PER_LINE) {
857  snprintf(line, 5, "%04x", i & 0xffff);
858  for (j = i; j < i + BYTES_PER_LINE && j < length; j++) {
859  snprintf(s, 4, " %02x", buffer[j]);
860  strcat(line, s);
861  }
862  LOG_DEBUG_IO("%s", line);
863  }
864 }
865 
866 static const struct command_registration vsllink_subcommand_handlers[] = {
867  {
868  .name = "usb_vid",
869  .handler = &vsllink_handle_usb_vid_command,
870  .mode = COMMAND_CONFIG,
871  .help = "Set USB VID",
872  .usage = "<vid>",
873  },
874  {
875  .name = "usb_pid",
876  .handler = &vsllink_handle_usb_pid_command,
877  .mode = COMMAND_CONFIG,
878  .help = "Set USB PID",
879  .usage = "<pid>",
880  },
881  {
882  .name = "usb_bulkin",
883  .handler = &vsllink_handle_usb_bulkin_command,
884  .mode = COMMAND_CONFIG,
885  .help = "Set USB input endpoint",
886  .usage = "<ep_in>",
887  },
888  {
889  .name = "usb_bulkout",
890  .handler = &vsllink_handle_usb_bulkout_command,
891  .mode = COMMAND_CONFIG,
892  .help = "Set USB output endpoint",
893  .usage = "<ep_out>",
894  },
895  {
896  .name = "usb_interface",
897  .handler = &vsllink_handle_usb_interface_command,
898  .mode = COMMAND_CONFIG,
899  .help = "Set USB output interface",
900  .usage = "<interface>",
901  },
903 };
904 
905 static const struct command_registration vsllink_command_handlers[] = {
906  {
907  .name = "vsllink",
908  .mode = COMMAND_ANY,
909  .help = "perform vsllink management",
911  .usage = "",
912  },
914 };
915 
916 static const char * const vsllink_transports[] = {"jtag", "swd", NULL};
917 
918 static const struct swd_driver vsllink_swd_driver = {
920  .switch_seq = vsllink_swd_switch_seq,
921  .read_reg = vsllink_swd_read_reg,
922  .write_reg = vsllink_swd_write_reg,
923  .run = vsllink_swd_run_queue,
924 };
925 
926 static struct jtag_interface vsllink_interface = {
928  .execute_queue = vsllink_execute_queue,
929 };
930 
932  .name = "vsllink",
933  .transports = vsllink_transports,
934  .commands = vsllink_command_handlers,
935 
936  .init = vsllink_init,
937  .quit = vsllink_quit,
938  .reset = vsllink_reset,
939  .speed = vsllink_speed,
940  .khz = vsllink_khz,
941  .speed_div = vsllink_speed_div,
942 
943  .jtag_ops = &vsllink_interface,
944  .swd_ops = &vsllink_swd_driver,
945 };
const char * adapter_get_required_serial(void)
Retrieves the serial number set with command 'adapter serial'.
Definition: adapter.c:298
unsigned int adapter_get_speed_khz(void)
Retrieves the clock speed of the adapter in kHz.
Definition: adapter.c:207
swd_special_seq
Definition: arm_adi_v5.h:236
@ JTAG_TO_SWD
Definition: arm_adi_v5.h:238
@ LINE_RESET
Definition: arm_adi_v5.h:237
@ SWD_TO_JTAG
Definition: arm_adi_v5.h:240
static const struct device_t * device
Definition: at91rm9200.c:94
void * buf_set_buf(const void *_src, unsigned src_start, void *_dst, unsigned dst_start, unsigned len)
Definition: binarybuffer.c:121
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:156
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:402
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:151
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
Definition: command.h:442
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
Definition: commands.c:194
enum scan_type jtag_scan_type(const struct scan_command *cmd)
Definition: commands.c:167
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
Definition: commands.c:235
scan_type
The inferred type of a scan_command_s structure, indicating whether the command has the host scan in ...
Definition: commands.h:22
@ JTAG_TLR_RESET
Definition: commands.h:137
@ JTAG_SCAN
Definition: commands.h:129
@ JTAG_PATHMOVE
Definition: commands.h:140
@ JTAG_STABLECLOCKS
Definition: commands.h:142
@ JTAG_RUNTEST
Definition: commands.h:138
@ JTAG_SLEEP
Definition: commands.h:141
@ JTAG_TMS
Definition: commands.h:143
uint8_t type
Definition: esp_usb_jtag.c:0
uint8_t length
Definition: esp_usb_jtag.c:1
bool tap_is_state_stable(tap_state_t astate)
Function tap_is_state_stable returns true if the astate is stable.
Definition: interface.c:200
tap_state_t tap_state_transition(tap_state_t cur_state, bool tms)
Function tap_state_transition takes a current TAP state and returns the next state according to the t...
Definition: interface.c:223
const char * tap_state_name(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
Definition: interface.c:344
void tap_set_end_state(tap_state_t new_end_state)
This function sets the state of an "end state follower" which tracks the state that any cable driver ...
Definition: interface.c:48
tap_state_t tap_get_end_state(void)
For more information,.
Definition: interface.c:56
int tap_get_tms_path(tap_state_t from, tap_state_t to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
Definition: interface.c:190
int tap_get_tms_path_len(tap_state_t from, tap_state_t to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
Definition: interface.c:195
tap_state_t tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
Definition: interface.c:37
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:187
#define tap_set_state(new_state)
This function sets the state of a "state follower" which tracks the state of the TAPs connected to th...
Definition: interface.h:49
void jtag_sleep(uint32_t us)
Definition: jtag/core.c:1062
@ TAP_RESET
Definition: jtag.h:56
@ TAP_DRPAUSE
Definition: jtag.h:44
@ TAP_IRSHIFT
Definition: jtag.h:51
@ TAP_IDLE
Definition: jtag.h:53
@ TAP_DRSHIFT
Definition: jtag.h:43
@ TAP_IRPAUSE
Definition: jtag.h:52
#define ERROR_JTAG_QUEUE_FAILED
Definition: jtag.h:557
#define ERROR_JTAG_INIT_FAILED
Definition: jtag.h:553
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
#define LOG_DEBUG_IO(expr ...)
Definition: log.h:101
#define ERROR_FAIL
Definition: log.h:170
#define LOG_ERROR(expr ...)
Definition: log.h:132
#define LOG_LEVEL_IS(FOO)
Definition: log.h:99
#define LOG_INFO(expr ...)
Definition: log.h:126
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:164
@ LOG_LVL_DEBUG_IO
Definition: log.h:48
static uint32_t bit(uint32_t value, unsigned int b)
Definition: opcodes.h:15
uint8_t bits[QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
Definition: qn908x.c:0
Represents a driver for a debugging interface.
Definition: interface.h:207
const char *const name
The name of the interface driver.
Definition: interface.h:209
const char * name
Definition: command.h:235
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:241
RESULT(* delayms)(uint16_t ms)
Definition: versaloon.h:42
RESULT(* fini)(uint8_t interface_index)
Definition: versaloon.h:34
RESULT(* init)(uint8_t interface_index)
Definition: versaloon.h:33
RESULT(* out)(uint8_t interface_index, uint32_t pin_mask, uint32_t value)
Definition: versaloon.h:37
RESULT(* config)(uint8_t interface_index, uint32_t pin_mask, uint32_t io, uint32_t pull_en_mask, uint32_t input_pull_mask)
Definition: versaloon.h:35
RESULT(* init)(uint8_t interface_index)
Definition: versaloon.h:59
RESULT(* execute)(uint8_t interface_index, uint8_t *tdi, uint8_t *tms, uint8_t *tdo, uint32_t bitlen)
Definition: versaloon.h:62
RESULT(* config)(uint8_t interface_index, uint32_t khz)
Definition: versaloon.h:61
RESULT(* fini)(uint8_t interface_index)
Definition: versaloon.h:60
RESULT(* seqout)(uint8_t interface_index, const uint8_t *data, uint16_t bitlen)
Definition: versaloon.h:51
RESULT(* init)(uint8_t interface_index)
Definition: versaloon.h:47
RESULT(* transact)(uint8_t interface_index, uint8_t request, uint32_t *data, uint8_t *ack)
Definition: versaloon.h:54
RESULT(* config)(uint8_t interface_index, uint8_t trn, uint16_t retry, uint16_t dly)
Definition: versaloon.h:49
RESULT(* fini)(uint8_t interface_index)
Definition: versaloon.h:48
Represents a driver for a debugging interface.
Definition: interface.h:182
unsigned supported
Bit vector listing capabilities exposed by this driver.
Definition: interface.h:186
uint8_t * ack
Definition: vsllink.c:32
uint8_t * buffer
Location to store the result.
Definition: arm-jtag-ew.c:520
struct scan_command * command
Definition: arm-jtag-ew.c:519
The scan_command provide a means of encapsulating a set of scan_field_s structures that should be sca...
Definition: commands.h:35
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
Definition: swd.h:255
struct interface_swd_t swd
Definition: versaloon.h:75
struct interface_gpio_t gpio
Definition: versaloon.h:73
RESULT(* peripheral_commit)(void)
Definition: versaloon.h:77
struct interface_delay_t delay
Definition: versaloon.h:74
struct interface_jtag_raw_t jtag_raw
Definition: versaloon.h:76
RESULT(* fini)(void)
Definition: versaloon.h:91
struct versaloon_adaptors_t adaptors
Definition: versaloon.h:92
RESULT(* init)(void)
Definition: versaloon.h:90
struct versaloon_usb_setting_t usb_setting
Definition: versaloon.h:93
static const unsigned swd_seq_swd_to_jtag_len
Definition: swd.h:144
static const unsigned swd_seq_jtag_to_swd_len
Definition: swd.h:125
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
Definition: swd.h:98
static const unsigned swd_seq_line_reset_len
Definition: swd.h:104
static const uint8_t swd_seq_jtag_to_swd[]
JTAG-to-SWD sequence.
Definition: swd.h:115
static const uint8_t swd_seq_swd_to_jtag[]
SWD-to-JTAG sequence.
Definition: swd.h:136
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
Definition: types.h:79
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
uint8_t state[4]
Definition: vdebug.c:21
struct libusb_device_handle * versaloon_usb_device_handle
Definition: versaloon.c:28
struct versaloon_interface_t versaloon_interface
Definition: versaloon.c:38
#define GPIO_SRST
Definition: versaloon.h:22
#define GPIO_TRST
Definition: versaloon.h:23