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(unsigned int num_states, tap_state_t *path);
48 static void armjtagew_runtest(unsigned 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(struct jtag_command *cmd_queue)
89 {
90  struct jtag_command *cmd = cmd_queue;
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 %u 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: %u 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) {
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(unsigned int num_states, tap_state_t *path)
283 {
284  for (unsigned int i = 0; i < num_states; i++) {
285  /*
286  * TODO: The ARM-JTAG-EW hardware delays TDI with 3 TCK cycles when in RTCK mode.
287  * Either handle that here, or update the documentation with examples
288  * how to fix that in the configuration files.
289  */
290  if (path[i] == tap_state_transition(tap_get_state(), false))
292  else if (path[i] == tap_state_transition(tap_get_state(), true))
294  else {
295  LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
297  exit(-1);
298  }
299 
300  tap_set_state(path[i]);
301  }
302 
304 }
305 
306 static void armjtagew_runtest(unsigned int num_cycles)
307 {
308  tap_state_t saved_end_state = tap_get_end_state();
309 
310  /* only do a state_move when we're not already in IDLE */
311  if (tap_get_state() != TAP_IDLE) {
314  }
315 
316  /* execute num_cycles */
317  for (unsigned int i = 0; i < num_cycles; i++)
319 
320  /* finish in end_state */
321  armjtagew_end_state(saved_end_state);
322  if (tap_get_state() != tap_get_end_state())
324 }
325 
326 static void armjtagew_scan(bool ir_scan,
327  enum scan_type type,
328  uint8_t *buffer,
329  int scan_size,
330  struct scan_command *command)
331 {
332  tap_state_t saved_end_state;
333 
334  armjtagew_tap_ensure_space(1, scan_size + 8);
335 
336  saved_end_state = tap_get_end_state();
337 
338  /* Move to appropriate scan state */
340 
341  /* Only move if we're not already there */
342  if (tap_get_state() != tap_get_end_state())
344 
345  armjtagew_end_state(saved_end_state);
346 
347  /* Scan */
349 
350  /* We are in Exit1, go to Pause */
352 
354 
355  if (tap_get_state() != tap_get_end_state())
357 }
358 
359 static void armjtagew_reset(int trst, int srst)
360 {
361  const uint8_t trst_mask = (1u << 5);
362  const uint8_t srst_mask = (1u << 6);
363  uint8_t val = 0;
364  uint8_t outp_en = 0;
365  uint8_t change_mask = 0;
366  int result;
367 
368  LOG_DEBUG("trst: %i, srst: %i", trst, srst);
369 
370  if (srst == 0) {
371  val |= srst_mask;
372  outp_en &= ~srst_mask; /* tristate */
373  change_mask |= srst_mask;
374  } else if (srst == 1) {
375  val &= ~srst_mask;
376  outp_en |= srst_mask;
377  change_mask |= srst_mask;
378  }
379 
380  if (trst == 0) {
381  val |= trst_mask;
382  outp_en &= ~trst_mask; /* tristate */
383  change_mask |= trst_mask;
384  } else if (trst == 1) {
385  val &= ~trst_mask;
386  outp_en |= trst_mask;
387  change_mask |= trst_mask;
388  }
389 
391  usb_out_buffer[1] = val;
392  usb_out_buffer[2] = outp_en;
393  usb_out_buffer[3] = change_mask;
395  if (result != 4)
396  LOG_ERROR("ARM-JTAG-EW TRST/SRST pin set failed failed (%d)", result);
397 }
398 
399 static int armjtagew_get_status(void)
400 {
401  int result;
402 
404  result = armjtagew_usb_message(armjtagew_handle, 1, 12);
405 
406  if (result == 0) {
407  unsigned int u_tg = buf_get_u32(usb_in_buffer, 0, 16);
408  LOG_INFO(
409  "U_tg = %d mV, U_aux = %d mV, U_tgpwr = %d mV, I_tgpwr = %d mA, D1 = %d, Target power %s %s",
410  (int)(buf_get_u32(usb_in_buffer + 0, 0, 16)),
411  (int)(buf_get_u32(usb_in_buffer + 2, 0, 16)),
412  (int)(buf_get_u32(usb_in_buffer + 4, 0, 16)),
413  (int)(buf_get_u32(usb_in_buffer + 6, 0, 16)),
414  usb_in_buffer[9],
415  usb_in_buffer[11] ? "OVERCURRENT" : "OK",
416  usb_in_buffer[10] ? "enabled" : "disabled");
417 
418  if (u_tg < 1500)
419  LOG_ERROR("Vref too low. Check Target Power");
420  } else
421  LOG_ERROR("ARM-JTAG-EW command CMD_GET_TAPHW_STATE failed (%d)", result);
422 
423  return ERROR_OK;
424 }
425 
427 {
428  int result;
429  char sn[16];
430  char auxinfo[257];
431 
432  /* query hardware version */
434  result = armjtagew_usb_message(armjtagew_handle, 1, 4 + 15 + 256);
435 
436  if (result != 0) {
437  LOG_ERROR("ARM-JTAG-EW command CMD_GET_VERSION failed (%d)", result);
439  }
440 
441  memcpy(sn, usb_in_buffer + 4, 15);
442  sn[15] = '\0';
443  memcpy(auxinfo, usb_in_buffer + 4+15, 256);
444  auxinfo[256] = '\0';
445 
446  LOG_INFO(
447  "ARM-JTAG-EW firmware version %d.%d, hardware revision %c, SN=%s, Additional info: %s",
448  usb_in_buffer[1],
449  usb_in_buffer[0],
450  isgraph(usb_in_buffer[2]) ? usb_in_buffer[2] : 'X',
451  sn,
452  auxinfo);
453 
454  if (1 != usb_in_buffer[1] || 6 != usb_in_buffer[0])
455  LOG_WARNING(
456  "ARM-JTAG-EW firmware version %d.%d is untested with this version of OpenOCD. You might experience unexpected behavior.",
457  usb_in_buffer[1],
458  usb_in_buffer[0]);
459  return ERROR_OK;
460 }
461 
462 COMMAND_HANDLER(armjtagew_handle_armjtagew_info_command)
463 {
465  /* attempt to get status */
467  }
468 
469  return ERROR_OK;
470 }
471 
472 static const struct command_registration armjtagew_command_handlers[] = {
473  {
474  .name = "armjtagew_info",
475  .handler = &armjtagew_handle_armjtagew_info_command,
476  .mode = COMMAND_EXEC,
477  .help = "query armjtagew info",
478  .usage = "",
479  },
481 };
482 
483 static struct jtag_interface armjtagew_interface = {
485 };
486 
488  .name = "arm-jtag-ew",
489  .transports = jtag_only,
490  .commands = armjtagew_command_handlers,
491 
492  .init = armjtagew_init,
493  .quit = armjtagew_quit,
494  .speed = armjtagew_speed,
495  .khz = armjtagew_khz,
496  .speed_div = armjtagew_speed_div,
497 
498  .jtag_ops = &armjtagew_interface,
499 };
500 
501 /**************************************************************************
502  * ARM-JTAG-EW tap functions */
503 
504 /* 2048 is the max value we can use here */
505 #define ARMJTAGEW_TAP_BUFFER_SIZE 2048
506 
507 static int tap_length;
511 
513  int first; /* First bit position in tdo_buffer to read */
514  int length; /* Number of bits to read */
515  struct scan_command *command; /* Corresponding scan command */
516  uint8_t *buffer;
517 };
518 
519 #define MAX_PENDING_SCAN_RESULTS 256
520 
523 
524 static int last_tms;
525 
526 static void armjtagew_tap_init(void)
527 {
528  tap_length = 0;
530 }
531 
532 static void armjtagew_tap_ensure_space(int scans, int bits)
533 {
535  int available_bits = ARMJTAGEW_TAP_BUFFER_SIZE * 8 - tap_length;
536 
537  if (scans > available_scans || bits > available_bits)
539 }
540 
541 static void armjtagew_tap_append_step(int tms, int tdi)
542 {
543  last_tms = tms;
544  int index_local = tap_length / 8;
545 
546  if (index_local < ARMJTAGEW_TAP_BUFFER_SIZE) {
547  int bit_index = tap_length % 8;
548  uint8_t bit = 1 << bit_index;
549 
550  if (tms)
551  tms_buffer[index_local] |= bit;
552  else
553  tms_buffer[index_local] &= ~bit;
554 
555  if (tdi)
556  tdi_buffer[index_local] |= bit;
557  else
558  tdi_buffer[index_local] &= ~bit;
559 
560  tap_length++;
561  } else
562  LOG_ERROR("armjtagew_tap_append_step, overflow");
563 }
564 
566 {
569  int i;
570 
575 
576  for (i = 0; i < length; i++)
577  armjtagew_tap_append_step((i < length-1 ? 0 : 1), (buffer[i/8] >> (i%8)) & 1);
579 }
580 
581 /* Pad and send a tap sequence to the device, and receive the answer.
582  * For the purpose of padding we assume that we are in idle or pause state. */
583 static int armjtagew_tap_execute(void)
584 {
585  int byte_length;
586  int tms_offset;
587  int tdi_offset;
588  int i;
589  int result;
590 
591  if (tap_length > 0) {
592  /* Pad last byte so that tap_length is divisible by 8 */
593  while (tap_length % 8 != 0) {
594  /* More of the last TMS value keeps us in the same state,
595  * analogous to free-running JTAG interfaces. */
597  }
598 
599  byte_length = tap_length / 8;
600 
602  buf_set_u32(usb_out_buffer + 1, 0, 16, byte_length);
603 
604  tms_offset = 3;
605  for (i = 0; i < byte_length; i++)
606  usb_out_buffer[tms_offset + i] = flip_u32(tms_buffer[i], 8);
607 
608  tdi_offset = tms_offset + byte_length;
609  for (i = 0; i < byte_length; i++)
610  usb_out_buffer[tdi_offset + i] = flip_u32(tdi_buffer[i], 8);
611 
613  3 + 2 * byte_length,
614  byte_length + 4);
615 
616  if (result == 0) {
617  int stat_local;
618 
619  stat_local = (int)buf_get_u32(usb_in_buffer + byte_length, 0, 32);
620  if (stat_local) {
621  LOG_ERROR(
622  "armjtagew_tap_execute, emulator returned error code %d for a CMD_TAP_SHIFT command",
623  stat_local);
625  }
626 
627  for (i = 0; i < byte_length; i++)
628  tdo_buffer[i] = flip_u32(usb_in_buffer[i], 8);
629 
630  for (i = 0; i < pending_scan_results_length; i++) {
633  uint8_t *buffer = pending_scan_result->buffer;
637 
638  /* Copy to buffer */
639  buf_set_buf(tdo_buffer, first, buffer, 0, length);
640 
641  LOG_DEBUG_IO("pending scan result, length = %d", length);
642 
643 #ifdef _DEBUG_USB_COMMS_
644  armjtagew_debug_buffer(buffer, byte_length);
645 #endif
646 
650  }
651 
653  }
654  } else {
655  LOG_ERROR("armjtagew_tap_execute, wrong result %d, expected %d",
656  result,
657  byte_length);
659  }
660 
662  }
663 
664  return ERROR_OK;
665 }
666 
667 /****************************************************************************
668  * JLink USB low-level functions */
669 
670 static struct armjtagew *armjtagew_usb_open(void)
671 {
672  const uint16_t vids[] = { USB_VID, 0 };
673  const uint16_t pids[] = { USB_PID, 0 };
674  struct libusb_device_handle *dev;
675 
676  if (jtag_libusb_open(vids, pids, NULL, &dev, NULL) != ERROR_OK)
677  return NULL;
678 
679  struct armjtagew *result = malloc(sizeof(struct armjtagew));
680  result->usb_handle = dev;
681 
682 #if 0
683  /* libusb_set_configuration required under win32 */
684  struct libusb_config_descriptor *config;
685  struct libusb_device *usb_dev = libusb_get_device(dev);
686  libusb_get_config_descriptor(usb_dev, 0, &config);
687  libusb_set_configuration(dev, config->bConfigurationValue);
688 #endif
689  libusb_claim_interface(dev, 0);
690 #if 0
691  /*
692  * This makes problems under Mac OS X. And is not needed
693  * under Windows. Hopefully this will not break a linux build
694  */
695  libusb_set_interface_alt_setting(dev, 0, 0);
696 #endif
697  return result;
698 }
699 
701 {
702  libusb_close(armjtagew->usb_handle);
703  free(armjtagew);
704 }
705 
706 /* Send a message and receive the reply. */
707 static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, int in_length)
708 {
709  int result;
710 
711  result = armjtagew_usb_write(armjtagew, out_length);
712  if (result == out_length) {
713  result = armjtagew_usb_read(armjtagew, in_length);
714  if (result != in_length) {
715  LOG_ERROR("jtag_libusb_bulk_read failed (requested=%d, result=%d)",
716  in_length,
717  result);
718  return -1;
719  }
720  } else {
721  LOG_ERROR("jtag_libusb_bulk_write failed (requested=%d, result=%d)", out_length, result);
722  return -1;
723  }
724  return 0;
725 }
726 
727 /* Write data from out_buffer to USB. */
728 static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
729 {
730  int result;
731  int transferred;
732 
733  if (out_length > ARMJTAGEW_OUT_BUFFER_SIZE) {
734  LOG_ERROR("armjtagew_write illegal out_length=%d (max=%d)",
735  out_length,
737  return -1;
738  }
739 
741  (char *)usb_out_buffer, out_length, ARMJTAGEW_USB_TIMEOUT, &transferred);
742 
743  LOG_DEBUG_IO("armjtagew_usb_write, out_length = %d, result = %d", out_length, result);
744 
745 #ifdef _DEBUG_USB_COMMS_
746  armjtagew_debug_buffer(usb_out_buffer, out_length);
747 #endif
748  if (result != ERROR_OK)
749  return -1;
750  return transferred;
751 }
752 
753 /* Read data from USB into in_buffer. */
754 static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length)
755 {
756  int transferred;
758  (char *)usb_in_buffer, exp_in_length, ARMJTAGEW_USB_TIMEOUT, &transferred);
759 
760  LOG_DEBUG_IO("armjtagew_usb_read, result = %d", result);
761 
762 #ifdef _DEBUG_USB_COMMS_
763  armjtagew_debug_buffer(usb_in_buffer, result);
764 #endif
765  if (result != ERROR_OK)
766  return -1;
767  return transferred;
768 }
769 
770 #ifdef _DEBUG_USB_COMMS_
771 #define BYTES_PER_LINE 16
772 
773 static void armjtagew_debug_buffer(uint8_t *buffer, int length)
774 {
775  char line[8 + 3 * BYTES_PER_LINE + 1];
776 
777  for (int i = 0; i < length; i += BYTES_PER_LINE) {
778  int n = snprintf(line, 9, "%04x", i);
779  for (int j = i; j < i + BYTES_PER_LINE && j < length; j++)
780  n += snprintf(line + n, 4, " %02x", buffer[j]);
781  LOG_DEBUG("%s", line);
782 
783  /* Prevent GDB timeout (writing to log might take some time) */
784  keep_alive();
785  }
786 }
787 #endif
const char *const jtag_only[]
Definition: adapter.c:27
static uint8_t tms_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]
Definition: arm-jtag-ew.c:508
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:519
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:326
static void armjtagew_tap_ensure_space(int scans, int bits)
Definition: arm-jtag-ew.c:532
#define CMD_GET_TAPHW_STATE
Definition: arm-jtag-ew.c:37
static int armjtagew_tap_execute(void)
Definition: arm-jtag-ew.c:583
static int armjtagew_execute_queue(struct jtag_command *cmd_queue)
Definition: arm-jtag-ew.c:88
static int last_tms
Definition: arm-jtag-ew.c:524
#define USB_VID
Definition: arm-jtag-ew.c:17
static struct armjtagew * armjtagew_usb_open(void)
Definition: arm-jtag-ew.c:670
static uint8_t tdi_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]
Definition: arm-jtag-ew.c:509
#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:510
static int tap_length
Definition: arm-jtag-ew.c:507
#define ARMJTAGEW_USB_TIMEOUT
Definition: arm-jtag-ew.c:23
static void armjtagew_reset(int trst, int srst)
Definition: arm-jtag-ew.c:359
#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:522
static void armjtagew_tap_append_step(int tms, int tdi)
Definition: arm-jtag-ew.c:541
static void armjtagew_runtest(unsigned int num_cycles)
Definition: arm-jtag-ew.c:306
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:707
#define CMD_TAP_SHIFT
Definition: arm-jtag-ew.c:35
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:565
struct adapter_driver armjtagew_adapter_driver
Definition: arm-jtag-ew.c:487
#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:526
static const struct command_registration armjtagew_command_handlers[]
Definition: arm-jtag-ew.c:472
static struct jtag_interface armjtagew_interface
Definition: arm-jtag-ew.c:483
static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
Definition: arm-jtag-ew.c:728
static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length)
Definition: arm-jtag-ew.c:754
static void armjtagew_path_move(unsigned int num_states, tap_state_t *path)
Definition: arm-jtag-ew.c:282
static int armjtagew_get_version_info(void)
Definition: arm-jtag-ew.c:426
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:521
#define ARMJTAGEW_TAP_BUFFER_SIZE
Definition: arm-jtag-ew.c:505
#define ARMJTAGEW_IN_BUFFER_SIZE
Definition: arm-jtag-ew.c:25
static int armjtagew_get_status(void)
Definition: arm-jtag-ew.c:399
COMMAND_HANDLER(armjtagew_handle_armjtagew_info_command)
Definition: arm-jtag-ew.c:462
static void armjtagew_usb_close(struct armjtagew *armjtagew)
Definition: arm-jtag-ew.c:700
void * buf_set_buf(const void *_src, unsigned int src_start, void *_dst, unsigned int dst_start, unsigned int len)
Definition: binarybuffer.c:120
uint32_t flip_u32(uint32_t value, unsigned int num)
Inverts the ordering of bits inside a 32-bit word (e.g.
Definition: binarybuffer.c:165
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
Definition: binarybuffer.h:104
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:34
#define BYTES_PER_LINE
Definition: buspirate.c:1267
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_EXEC
Definition: command.h:40
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
Definition: commands.c:192
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:230
scan_type
The inferred type of a scan_command structure, indicating whether the command has the host scan in fr...
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:559
@ 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.
int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[], const char *product, struct libusb_device_handle **out, adapter_get_alternate_serial_fn adapter_get_alternate_serial)
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)
void keep_alive(void)
Definition: log.c:415
#define LOG_DEBUG_IO(expr ...)
Definition: log.h:101
#define LOG_WARNING(expr ...)
Definition: log.h:129
#define LOG_ERROR(expr ...)
Definition: log.h:132
#define LOG_INFO(expr ...)
Definition: log.h:126
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:164
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
struct libusb_device_handle * usb_handle
Definition: arm-jtag-ew.c:67
const char * name
Definition: command.h:235
Represents a driver for a debugging interface.
Definition: interface.h:182
int(* execute_queue)(struct jtag_command *cmd_queue)
Execute commands in the supplied queue.
Definition: interface.h:195
int first
First bit position in tdo_buffer to read.
Definition: arm-jtag-ew.c:513
int length
Number of bits to read.
Definition: arm-jtag-ew.c:514
uint8_t * buffer
Location to store the result.
Definition: arm-jtag-ew.c:516
struct scan_command * command
Definition: arm-jtag-ew.c:515
The scan_command provide a means of encapsulating a set of scan_field structures that should be scann...
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