OpenOCD
arm-jtag-ew.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2009 by Dimitar Dimitrov <dinuxbg@gmail.com> *
5  * based on Dominic Rath's and Benedikt Sauter's usbprog.c *
6  ***************************************************************************/
7 
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11 
12 #include <jtag/interface.h>
13 #include <jtag/commands.h>
14 #include "helper/system.h"
15 #include "libusb_helper.h"
16 
17 #define USB_VID 0x15ba
18 #define USB_PID 0x001e
19 
20 #define ARMJTAGEW_EPT_BULK_OUT 0x01u
21 #define ARMJTAGEW_EPT_BULK_IN 0x82u
22 
23 #define ARMJTAGEW_USB_TIMEOUT 2000
24 
25 #define ARMJTAGEW_IN_BUFFER_SIZE (4*1024)
26 #define ARMJTAGEW_OUT_BUFFER_SIZE (4*1024)
27 
28 /* USB command request codes. */
29 #define CMD_GET_VERSION 0x00
30 #define CMD_SELECT_DPIMPL 0x10
31 #define CMD_SET_TCK_FREQUENCY 0x11
32 #define CMD_GET_TCK_FREQUENCY 0x12
33 #define CMD_MEASURE_MAX_TCK_FREQ 0x15
34 #define CMD_MEASURE_RTCK_RESPONSE 0x16
35 #define CMD_TAP_SHIFT 0x17
36 #define CMD_SET_TAPHW_STATE 0x20
37 #define CMD_GET_TAPHW_STATE 0x21
38 #define CMD_TGPWR_SETUP 0x22
39 
40 /* Global USB buffers */
43 
44 /* Queue command functions */
46 static void armjtagew_state_move(void);
47 static void armjtagew_path_move(int num_states, tap_state_t *path);
48 static void armjtagew_runtest(int num_cycles);
49 static void armjtagew_scan(bool ir_scan,
50  enum scan_type type,
51  uint8_t *buffer,
52  int scan_size,
53  struct scan_command *command);
54 static void armjtagew_reset(int trst, int srst);
55 /* static void armjtagew_simple_command(uint8_t command); */
56 static int armjtagew_get_status(void);
57 
58 /* tap buffer functions */
59 static void armjtagew_tap_init(void);
60 static int armjtagew_tap_execute(void);
61 static void armjtagew_tap_ensure_space(int scans, int bits);
62 static void armjtagew_tap_append_step(int tms, int tdi);
63 static void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command);
64 
65 /* ARM-JTAG-EW lowlevel functions */
66 struct armjtagew {
67  struct libusb_device_handle *usb_handle;
68 };
69 
70 static struct armjtagew *armjtagew_usb_open(void);
71 static void armjtagew_usb_close(struct armjtagew *armjtagew);
72 static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, int in_length);
73 static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length);
74 static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length);
75 
76 /* helper functions */
77 static int armjtagew_get_version_info(void);
78 
79 #ifdef _DEBUG_USB_COMMS_
80 static void armjtagew_debug_buffer(uint8_t *buffer, int length);
81 #endif
82 
83 static struct armjtagew *armjtagew_handle;
84 
85 /**************************************************************************
86  * External interface implementation */
87 
88 static int armjtagew_execute_queue(void)
89 {
91  int scan_size;
92  enum scan_type type;
93  uint8_t *buffer;
94 
95  while (cmd) {
96  switch (cmd->type) {
97  case JTAG_RUNTEST:
98  LOG_DEBUG_IO("runtest %i cycles, end in %i",
99  cmd->cmd.runtest->num_cycles,
100  cmd->cmd.runtest->end_state);
101 
102  armjtagew_end_state(cmd->cmd.runtest->end_state);
103  armjtagew_runtest(cmd->cmd.runtest->num_cycles);
104  break;
105 
106  case JTAG_TLR_RESET:
107  LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state);
108 
109  armjtagew_end_state(cmd->cmd.statemove->end_state);
111  break;
112 
113  case JTAG_PATHMOVE:
114  LOG_DEBUG_IO("pathmove: %i states, end in %i",
115  cmd->cmd.pathmove->num_states,
116  cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
117 
118  armjtagew_path_move(cmd->cmd.pathmove->num_states,
119  cmd->cmd.pathmove->path);
120  break;
121 
122  case JTAG_SCAN:
123  LOG_DEBUG_IO("scan end in %i", cmd->cmd.scan->end_state);
124 
125  armjtagew_end_state(cmd->cmd.scan->end_state);
126 
127  scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
128  LOG_DEBUG_IO("scan input, length = %d", scan_size);
129 
130 #ifdef _DEBUG_USB_COMMS_
131  armjtagew_debug_buffer(buffer, (scan_size + 7) / 8);
132 #endif
133  type = jtag_scan_type(cmd->cmd.scan);
134  armjtagew_scan(cmd->cmd.scan->ir_scan,
135  type, buffer,
136  scan_size, cmd->cmd.scan);
137  break;
138 
139  case JTAG_RESET:
140  LOG_DEBUG_IO("reset trst: %i srst %i",
141  cmd->cmd.reset->trst,
142  cmd->cmd.reset->srst);
143 
145 
146  if (cmd->cmd.reset->trst == 1)
148  armjtagew_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
149  break;
150 
151  case JTAG_SLEEP:
152  LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
154  jtag_sleep(cmd->cmd.sleep->us);
155  break;
156 
157  default:
158  LOG_ERROR("BUG: unknown JTAG command type encountered");
159  exit(-1);
160  }
161  cmd = cmd->next;
162  }
163 
164  return armjtagew_tap_execute();
165 }
166 
167 /* Sets speed in kHz. */
168 static int armjtagew_speed(int speed)
169 {
170  int result;
171  int speed_real;
172 
173 
175  buf_set_u32(usb_out_buffer + 1, 0, 32, speed*1000);
176 
177  result = armjtagew_usb_message(armjtagew_handle, 5, 4);
178 
179  if (result < 0) {
180  LOG_ERROR("ARM-JTAG-EW setting speed failed (%d)", result);
182  }
183 
185  result = armjtagew_usb_message(armjtagew_handle, 1, 4);
186  speed_real = (int)buf_get_u32(usb_in_buffer, 0, 32) / 1000;
187  if (result < 0) {
188  LOG_ERROR("ARM-JTAG-EW getting speed failed (%d)", result);
190  } else
191  LOG_INFO("Requested speed %dkHz, emulator reported %dkHz.", speed, speed_real);
192 
193  return ERROR_OK;
194 }
195 
196 static int armjtagew_khz(int khz, int *jtag_speed)
197 {
198  *jtag_speed = khz;
199 
200  return ERROR_OK;
201 }
202 
203 static int armjtagew_speed_div(int speed, int *khz)
204 {
205  *khz = speed;
206 
207  return ERROR_OK;
208 }
209 
210 static int armjtagew_init(void)
211 {
212  int check_cnt;
213 
215 
216  if (armjtagew_handle == 0) {
217  LOG_ERROR(
218  "Cannot find ARM-JTAG-EW Interface! Please check connection and permissions.");
219  return ERROR_JTAG_INIT_FAILED;
220  }
221 
222  check_cnt = 0;
223  while (check_cnt < 3) {
225  /* attempt to get status */
227  break;
228  }
229 
230  check_cnt++;
231  }
232 
233  if (check_cnt == 3)
234  LOG_INFO("ARM-JTAG-EW initial read failed, don't worry");
235 
236  /* Initial JTAG speed (for reset and initialization): 32 kHz */
237  armjtagew_speed(32);
238 
239  LOG_INFO("ARM-JTAG-EW JTAG Interface ready");
240 
241  armjtagew_reset(0, 0);
243 
244  return ERROR_OK;
245 }
246 
247 static int armjtagew_quit(void)
248 {
250  return ERROR_OK;
251 }
252 
253 /**************************************************************************
254  * Queue command implementations */
255 
257 {
260  else {
261  LOG_ERROR("BUG: %i is not a valid end state", state);
262  exit(-1);
263  }
264 }
265 
266 /* Goes to the end state. */
267 static void armjtagew_state_move(void)
268 {
269  int i;
270  int tms = 0;
271  uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
273 
274  for (i = 0; i < tms_count; i++) {
275  tms = (tms_scan >> i) & 1;
277  }
278 
280 }
281 
282 static void armjtagew_path_move(int num_states, tap_state_t *path)
283 {
284  int i;
285 
286  for (i = 0; i < num_states; i++) {
287  /*
288  * TODO: The ARM-JTAG-EW hardware delays TDI with 3 TCK cycles when in RTCK mode.
289  * Either handle that here, or update the documentation with examples
290  * how to fix that in the configuration files.
291  */
292  if (path[i] == tap_state_transition(tap_get_state(), false))
294  else if (path[i] == tap_state_transition(tap_get_state(), true))
296  else {
297  LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
299  exit(-1);
300  }
301 
302  tap_set_state(path[i]);
303  }
304 
306 }
307 
308 static void armjtagew_runtest(int num_cycles)
309 {
310  int i;
311 
312  tap_state_t saved_end_state = tap_get_end_state();
313 
314  /* only do a state_move when we're not already in IDLE */
315  if (tap_get_state() != TAP_IDLE) {
318  }
319 
320  /* execute num_cycles */
321  for (i = 0; i < num_cycles; i++)
323 
324  /* finish in end_state */
325  armjtagew_end_state(saved_end_state);
326  if (tap_get_state() != tap_get_end_state())
328 }
329 
330 static void armjtagew_scan(bool ir_scan,
331  enum scan_type type,
332  uint8_t *buffer,
333  int scan_size,
334  struct scan_command *command)
335 {
336  tap_state_t saved_end_state;
337 
338  armjtagew_tap_ensure_space(1, scan_size + 8);
339 
340  saved_end_state = tap_get_end_state();
341 
342  /* Move to appropriate scan state */
344 
345  /* Only move if we're not already there */
346  if (tap_get_state() != tap_get_end_state())
348 
349  armjtagew_end_state(saved_end_state);
350 
351  /* Scan */
353 
354  /* We are in Exit1, go to Pause */
356 
358 
359  if (tap_get_state() != tap_get_end_state())
361 }
362 
363 static void armjtagew_reset(int trst, int srst)
364 {
365  const uint8_t trst_mask = (1u << 5);
366  const uint8_t srst_mask = (1u << 6);
367  uint8_t val = 0;
368  uint8_t outp_en = 0;
369  uint8_t change_mask = 0;
370  int result;
371 
372  LOG_DEBUG("trst: %i, srst: %i", trst, srst);
373 
374  if (srst == 0) {
375  val |= srst_mask;
376  outp_en &= ~srst_mask; /* tristate */
377  change_mask |= srst_mask;
378  } else if (srst == 1) {
379  val &= ~srst_mask;
380  outp_en |= srst_mask;
381  change_mask |= srst_mask;
382  }
383 
384  if (trst == 0) {
385  val |= trst_mask;
386  outp_en &= ~trst_mask; /* tristate */
387  change_mask |= trst_mask;
388  } else if (trst == 1) {
389  val &= ~trst_mask;
390  outp_en |= trst_mask;
391  change_mask |= trst_mask;
392  }
393 
395  usb_out_buffer[1] = val;
396  usb_out_buffer[2] = outp_en;
397  usb_out_buffer[3] = change_mask;
399  if (result != 4)
400  LOG_ERROR("ARM-JTAG-EW TRST/SRST pin set failed failed (%d)", result);
401 }
402 
403 static int armjtagew_get_status(void)
404 {
405  int result;
406 
408  result = armjtagew_usb_message(armjtagew_handle, 1, 12);
409 
410  if (result == 0) {
411  unsigned int u_tg = buf_get_u32(usb_in_buffer, 0, 16);
412  LOG_INFO(
413  "U_tg = %d mV, U_aux = %d mV, U_tgpwr = %d mV, I_tgpwr = %d mA, D1 = %d, Target power %s %s",
414  (int)(buf_get_u32(usb_in_buffer + 0, 0, 16)),
415  (int)(buf_get_u32(usb_in_buffer + 2, 0, 16)),
416  (int)(buf_get_u32(usb_in_buffer + 4, 0, 16)),
417  (int)(buf_get_u32(usb_in_buffer + 6, 0, 16)),
418  usb_in_buffer[9],
419  usb_in_buffer[11] ? "OVERCURRENT" : "OK",
420  usb_in_buffer[10] ? "enabled" : "disabled");
421 
422  if (u_tg < 1500)
423  LOG_ERROR("Vref too low. Check Target Power");
424  } else
425  LOG_ERROR("ARM-JTAG-EW command CMD_GET_TAPHW_STATE failed (%d)", result);
426 
427  return ERROR_OK;
428 }
429 
431 {
432  int result;
433  char sn[16];
434  char auxinfo[257];
435 
436  /* query hardware version */
438  result = armjtagew_usb_message(armjtagew_handle, 1, 4 + 15 + 256);
439 
440  if (result != 0) {
441  LOG_ERROR("ARM-JTAG-EW command CMD_GET_VERSION failed (%d)", result);
443  }
444 
445  memcpy(sn, usb_in_buffer + 4, 15);
446  sn[15] = '\0';
447  memcpy(auxinfo, usb_in_buffer + 4+15, 256);
448  auxinfo[256] = '\0';
449 
450  LOG_INFO(
451  "ARM-JTAG-EW firmware version %d.%d, hardware revision %c, SN=%s, Additional info: %s",
452  usb_in_buffer[1],
453  usb_in_buffer[0],
454  isgraph(usb_in_buffer[2]) ? usb_in_buffer[2] : 'X',
455  sn,
456  auxinfo);
457 
458  if (1 != usb_in_buffer[1] || 6 != usb_in_buffer[0])
459  LOG_WARNING(
460  "ARM-JTAG-EW firmware version %d.%d is untested with this version of OpenOCD. You might experience unexpected behavior.",
461  usb_in_buffer[1],
462  usb_in_buffer[0]);
463  return ERROR_OK;
464 }
465 
466 COMMAND_HANDLER(armjtagew_handle_armjtagew_info_command)
467 {
469  /* attempt to get status */
471  }
472 
473  return ERROR_OK;
474 }
475 
476 static const struct command_registration armjtagew_command_handlers[] = {
477  {
478  .name = "armjtagew_info",
479  .handler = &armjtagew_handle_armjtagew_info_command,
480  .mode = COMMAND_EXEC,
481  .help = "query armjtagew info",
482  .usage = "",
483  },
485 };
486 
487 static struct jtag_interface armjtagew_interface = {
489 };
490 
492  .name = "arm-jtag-ew",
493  .transports = jtag_only,
494  .commands = armjtagew_command_handlers,
495 
496  .init = armjtagew_init,
497  .quit = armjtagew_quit,
498  .speed = armjtagew_speed,
499  .khz = armjtagew_khz,
500  .speed_div = armjtagew_speed_div,
501 
502  .jtag_ops = &armjtagew_interface,
503 };
504 
505 /**************************************************************************
506  * ARM-JTAG-EW tap functions */
507 
508 /* 2048 is the max value we can use here */
509 #define ARMJTAGEW_TAP_BUFFER_SIZE 2048
510 
511 static int tap_length;
515 
517  int first; /* First bit position in tdo_buffer to read */
518  int length; /* Number of bits to read */
519  struct scan_command *command; /* Corresponding scan command */
520  uint8_t *buffer;
521 };
522 
523 #define MAX_PENDING_SCAN_RESULTS 256
524 
527 
528 static int last_tms;
529 
530 static void armjtagew_tap_init(void)
531 {
532  tap_length = 0;
534 }
535 
536 static void armjtagew_tap_ensure_space(int scans, int bits)
537 {
539  int available_bits = ARMJTAGEW_TAP_BUFFER_SIZE * 8 - tap_length;
540 
541  if (scans > available_scans || bits > available_bits)
543 }
544 
545 static void armjtagew_tap_append_step(int tms, int tdi)
546 {
547  last_tms = tms;
548  int index_local = tap_length / 8;
549 
550  if (index_local < ARMJTAGEW_TAP_BUFFER_SIZE) {
551  int bit_index = tap_length % 8;
552  uint8_t bit = 1 << bit_index;
553 
554  if (tms)
555  tms_buffer[index_local] |= bit;
556  else
557  tms_buffer[index_local] &= ~bit;
558 
559  if (tdi)
560  tdi_buffer[index_local] |= bit;
561  else
562  tdi_buffer[index_local] &= ~bit;
563 
564  tap_length++;
565  } else
566  LOG_ERROR("armjtagew_tap_append_step, overflow");
567 }
568 
570 {
573  int i;
574 
579 
580  for (i = 0; i < length; i++)
581  armjtagew_tap_append_step((i < length-1 ? 0 : 1), (buffer[i/8] >> (i%8)) & 1);
583 }
584 
585 /* Pad and send a tap sequence to the device, and receive the answer.
586  * For the purpose of padding we assume that we are in idle or pause state. */
587 static int armjtagew_tap_execute(void)
588 {
589  int byte_length;
590  int tms_offset;
591  int tdi_offset;
592  int i;
593  int result;
594 
595  if (tap_length > 0) {
596  /* Pad last byte so that tap_length is divisible by 8 */
597  while (tap_length % 8 != 0) {
598  /* More of the last TMS value keeps us in the same state,
599  * analogous to free-running JTAG interfaces. */
601  }
602 
603  byte_length = tap_length / 8;
604 
606  buf_set_u32(usb_out_buffer + 1, 0, 16, byte_length);
607 
608  tms_offset = 3;
609  for (i = 0; i < byte_length; i++)
610  usb_out_buffer[tms_offset + i] = flip_u32(tms_buffer[i], 8);
611 
612  tdi_offset = tms_offset + byte_length;
613  for (i = 0; i < byte_length; i++)
614  usb_out_buffer[tdi_offset + i] = flip_u32(tdi_buffer[i], 8);
615 
617  3 + 2 * byte_length,
618  byte_length + 4);
619 
620  if (result == 0) {
621  int stat_local;
622 
623  stat_local = (int)buf_get_u32(usb_in_buffer + byte_length, 0, 32);
624  if (stat_local) {
625  LOG_ERROR(
626  "armjtagew_tap_execute, emulator returned error code %d for a CMD_TAP_SHIFT command",
627  stat_local);
629  }
630 
631  for (i = 0; i < byte_length; i++)
632  tdo_buffer[i] = flip_u32(usb_in_buffer[i], 8);
633 
634  for (i = 0; i < pending_scan_results_length; i++) {
637  uint8_t *buffer = pending_scan_result->buffer;
641 
642  /* Copy to buffer */
643  buf_set_buf(tdo_buffer, first, buffer, 0, length);
644 
645  LOG_DEBUG_IO("pending scan result, length = %d", length);
646 
647 #ifdef _DEBUG_USB_COMMS_
648  armjtagew_debug_buffer(buffer, byte_length);
649 #endif
650 
654  }
655 
657  }
658  } else {
659  LOG_ERROR("armjtagew_tap_execute, wrong result %d, expected %d",
660  result,
661  byte_length);
663  }
664 
666  }
667 
668  return ERROR_OK;
669 }
670 
671 /****************************************************************************
672  * JLink USB low-level functions */
673 
674 static struct armjtagew *armjtagew_usb_open(void)
675 {
676  const uint16_t vids[] = { USB_VID, 0 };
677  const uint16_t pids[] = { USB_PID, 0 };
678  struct libusb_device_handle *dev;
679 
680  if (jtag_libusb_open(vids, pids, &dev, NULL) != ERROR_OK)
681  return NULL;
682 
683  struct armjtagew *result = malloc(sizeof(struct armjtagew));
684  result->usb_handle = dev;
685 
686 #if 0
687  /* libusb_set_configuration required under win32 */
688  struct libusb_config_descriptor *config;
689  struct libusb_device *usb_dev = libusb_get_device(dev);
690  libusb_get_config_descriptor(usb_dev, 0, &config);
691  libusb_set_configuration(dev, config->bConfigurationValue);
692 #endif
693  libusb_claim_interface(dev, 0);
694 #if 0
695  /*
696  * This makes problems under Mac OS X. And is not needed
697  * under Windows. Hopefully this will not break a linux build
698  */
699  libusb_set_interface_alt_setting(dev, 0, 0);
700 #endif
701  return result;
702 }
703 
705 {
706  libusb_close(armjtagew->usb_handle);
707  free(armjtagew);
708 }
709 
710 /* Send a message and receive the reply. */
711 static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, int in_length)
712 {
713  int result;
714 
715  result = armjtagew_usb_write(armjtagew, out_length);
716  if (result == out_length) {
717  result = armjtagew_usb_read(armjtagew, in_length);
718  if (result != in_length) {
719  LOG_ERROR("jtag_libusb_bulk_read failed (requested=%d, result=%d)",
720  in_length,
721  result);
722  return -1;
723  }
724  } else {
725  LOG_ERROR("jtag_libusb_bulk_write failed (requested=%d, result=%d)", out_length, result);
726  return -1;
727  }
728  return 0;
729 }
730 
731 /* Write data from out_buffer to USB. */
732 static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
733 {
734  int result;
735  int transferred;
736 
737  if (out_length > ARMJTAGEW_OUT_BUFFER_SIZE) {
738  LOG_ERROR("armjtagew_write illegal out_length=%d (max=%d)",
739  out_length,
741  return -1;
742  }
743 
745  (char *)usb_out_buffer, out_length, ARMJTAGEW_USB_TIMEOUT, &transferred);
746 
747  LOG_DEBUG_IO("armjtagew_usb_write, out_length = %d, result = %d", out_length, result);
748 
749 #ifdef _DEBUG_USB_COMMS_
750  armjtagew_debug_buffer(usb_out_buffer, out_length);
751 #endif
752  if (result != ERROR_OK)
753  return -1;
754  return transferred;
755 }
756 
757 /* Read data from USB into in_buffer. */
758 static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length)
759 {
760  int transferred;
762  (char *)usb_in_buffer, exp_in_length, ARMJTAGEW_USB_TIMEOUT, &transferred);
763 
764  LOG_DEBUG_IO("armjtagew_usb_read, result = %d", result);
765 
766 #ifdef _DEBUG_USB_COMMS_
767  armjtagew_debug_buffer(usb_in_buffer, result);
768 #endif
769  if (result != ERROR_OK)
770  return -1;
771  return transferred;
772 }
773 
774 #ifdef _DEBUG_USB_COMMS_
775 #define BYTES_PER_LINE 16
776 
777 static void armjtagew_debug_buffer(uint8_t *buffer, int length)
778 {
779  char line[8 + 3 * BYTES_PER_LINE + 1];
780 
781  for (int i = 0; i < length; i += BYTES_PER_LINE) {
782  int n = snprintf(line, 9, "%04x", i);
783  for (int j = i; j < i + BYTES_PER_LINE && j < length; j++)
784  n += snprintf(line + n, 4, " %02x", buffer[j]);
785  LOG_DEBUG("%s", line);
786 
787  /* Prevent GDB timeout (writing to log might take some time) */
788  keep_alive();
789  }
790 }
791 #endif
const char *const jtag_only[]
Definition: adapter.c:31
static uint8_t tms_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]
Definition: arm-jtag-ew.c:512
static void armjtagew_end_state(tap_state_t state)
Definition: arm-jtag-ew.c:256
#define MAX_PENDING_SCAN_RESULTS
Definition: arm-jtag-ew.c:523
static int armjtagew_init(void)
Definition: arm-jtag-ew.c:210
static uint8_t usb_in_buffer[ARMJTAGEW_IN_BUFFER_SIZE]
Definition: arm-jtag-ew.c:41
static void armjtagew_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command)
Definition: arm-jtag-ew.c:330
static void armjtagew_tap_ensure_space(int scans, int bits)
Definition: arm-jtag-ew.c:536
#define CMD_GET_TAPHW_STATE
Definition: arm-jtag-ew.c:37
static int armjtagew_tap_execute(void)
Definition: arm-jtag-ew.c:587
static int last_tms
Definition: arm-jtag-ew.c:528
#define USB_VID
Definition: arm-jtag-ew.c:17
static struct armjtagew * armjtagew_usb_open(void)
Definition: arm-jtag-ew.c:674
static uint8_t tdi_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]
Definition: arm-jtag-ew.c:513
#define CMD_SET_TCK_FREQUENCY
Definition: arm-jtag-ew.c:31
static uint8_t tdo_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]
Definition: arm-jtag-ew.c:514
static int tap_length
Definition: arm-jtag-ew.c:511
#define ARMJTAGEW_USB_TIMEOUT
Definition: arm-jtag-ew.c:23
static void armjtagew_reset(int trst, int srst)
Definition: arm-jtag-ew.c:363
#define ARMJTAGEW_OUT_BUFFER_SIZE
Definition: arm-jtag-ew.c:26
static uint8_t usb_out_buffer[ARMJTAGEW_OUT_BUFFER_SIZE]
Definition: arm-jtag-ew.c:42
static struct pending_scan_result pending_scan_results_buffer[MAX_PENDING_SCAN_RESULTS]
Definition: arm-jtag-ew.c:526
static void armjtagew_tap_append_step(int tms, int tdi)
Definition: arm-jtag-ew.c:545
static void armjtagew_state_move(void)
Definition: arm-jtag-ew.c:267
static int armjtagew_khz(int khz, int *jtag_speed)
Definition: arm-jtag-ew.c:196
#define CMD_SET_TAPHW_STATE
Definition: arm-jtag-ew.c:36
#define ARMJTAGEW_EPT_BULK_OUT
Definition: arm-jtag-ew.c:20
static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, int in_length)
Definition: arm-jtag-ew.c:711
#define CMD_TAP_SHIFT
Definition: arm-jtag-ew.c:35
static void armjtagew_runtest(int num_cycles)
Definition: arm-jtag-ew.c:308
static struct armjtagew * armjtagew_handle
Definition: arm-jtag-ew.c:83
static void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command)
Definition: arm-jtag-ew.c:569
struct adapter_driver armjtagew_adapter_driver
Definition: arm-jtag-ew.c:491
#define CMD_GET_TCK_FREQUENCY
Definition: arm-jtag-ew.c:32
static int armjtagew_speed_div(int speed, int *khz)
Definition: arm-jtag-ew.c:203
#define USB_PID
Definition: arm-jtag-ew.c:18
#define ARMJTAGEW_EPT_BULK_IN
Definition: arm-jtag-ew.c:21
static void armjtagew_tap_init(void)
Definition: arm-jtag-ew.c:530
static const struct command_registration armjtagew_command_handlers[]
Definition: arm-jtag-ew.c:476
static struct jtag_interface armjtagew_interface
Definition: arm-jtag-ew.c:487
static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
Definition: arm-jtag-ew.c:732
static int armjtagew_execute_queue(void)
Definition: arm-jtag-ew.c:88
static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length)
Definition: arm-jtag-ew.c:758
static int armjtagew_get_version_info(void)
Definition: arm-jtag-ew.c:430
static int armjtagew_quit(void)
Definition: arm-jtag-ew.c:247
static int armjtagew_speed(int speed)
Definition: arm-jtag-ew.c:168
#define CMD_GET_VERSION
Definition: arm-jtag-ew.c:29
static int pending_scan_results_length
Definition: arm-jtag-ew.c:525
#define ARMJTAGEW_TAP_BUFFER_SIZE
Definition: arm-jtag-ew.c:509
#define ARMJTAGEW_IN_BUFFER_SIZE
Definition: arm-jtag-ew.c:25
static int armjtagew_get_status(void)
Definition: arm-jtag-ew.c:403
static void armjtagew_path_move(int num_states, tap_state_t *path)
Definition: arm-jtag-ew.c:282
COMMAND_HANDLER(armjtagew_handle_armjtagew_info_command)
Definition: arm-jtag-ew.c:466
static void armjtagew_usb_close(struct armjtagew *armjtagew)
Definition: arm-jtag-ew.c:704
uint32_t bits
Definition: armv4_5.c:359
uint32_t flip_u32(uint32_t value, unsigned int num)
Definition: binarybuffer.c:166
void * buf_set_buf(const void *_src, unsigned src_start, void *_dst, unsigned dst_start, unsigned len)
Definition: binarybuffer.c:121
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
Definition: binarybuffer.h:98
static void buf_set_u32(uint8_t *_buffer, unsigned first, unsigned num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:30
#define BYTES_PER_LINE
Definition: buspirate.c:1272
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
@ COMMAND_EXEC
Definition: command.h:40
struct jtag_command * jtag_command_queue
The current queue of jtag_command_s structures.
Definition: commands.c:36
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
Definition: commands.c:189
enum scan_type jtag_scan_type(const struct scan_command *cmd)
Definition: commands.c:162
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
Definition: commands.c:230
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_RUNTEST
Definition: commands.h:138
@ JTAG_SLEEP
Definition: commands.h:141
@ JTAG_RESET
Definition: commands.h:139
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 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
#define ERROR_JTAG_DEVICE_ERROR
Definition: jtag.h:555
@ TAP_RESET
Definition: jtag.h:55
@ TAP_DRPAUSE
Definition: jtag.h:43
@ TAP_IRSHIFT
Definition: jtag.h:50
@ TAP_IDLE
Definition: jtag.h:52
@ TAP_DRSHIFT
Definition: jtag.h:42
@ TAP_IRPAUSE
Definition: jtag.h:51
#define ERROR_JTAG_QUEUE_FAILED
Definition: jtag.h:553
#define ERROR_JTAG_INIT_FAILED
Definition: jtag.h:549
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
int jtag_libusb_bulk_write(struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout, int *transferred)
int jtag_libusb_bulk_read(struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout, int *transferred)
int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[], struct libusb_device_handle **out, adapter_get_alternate_serial_fn adapter_get_alternate_serial)
void keep_alive(void)
Definition: log.c:419
#define LOG_DEBUG_IO(expr ...)
Definition: log.h:101
#define LOG_WARNING(expr ...)
Definition: log.h:120
#define LOG_ERROR(expr ...)
Definition: log.h:123
#define LOG_INFO(expr ...)
Definition: log.h:117
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:155
static uint32_t bit(uint32_t value, unsigned int b)
Definition: opcodes.h:15
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
struct libusb_device_handle * usb_handle
Definition: arm-jtag-ew.c:67
const char * name
Definition: command.h:229
Represents a driver for a debugging interface.
Definition: interface.h:184
int(* execute_queue)(void)
Execute queued commands.
Definition: interface.h:195
int first
First bit position in tdo_buffer to read.
Definition: arm-jtag-ew.c:517
int length
Number of bits to read.
Definition: arm-jtag-ew.c:518
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
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
uint8_t state[4]
Definition: vdebug.c:21