34 #include <libjaylink/libjaylink.h>
36 static struct jaylink_context *
jayctx;
37 static struct jaylink_device_handle *
devh;
38 static struct jaylink_connection
conn;
39 static struct jaylink_connection
connlist[JAYLINK_MAX_CONNECTIONS];
41 static uint8_t
caps[JAYLINK_DEV_EXT_CAPS_SIZE];
48 static enum jaylink_target_interface
iface = JAYLINK_TIF_JTAG;
51 #define JLINK_MAX_SPEED 12000
52 #define JLINK_TAP_BUFFER_SIZE 2048
57 #define SWO_MAX_FREQ_DEV 0.03
108 const uint8_t *tms_out,
unsigned tms_offset,
109 uint8_t *in,
unsigned in_offset,
126 LOG_DEBUG_IO(
"runtest %i cycles, end in %i",
cmd->cmd.runtest->num_cycles,
127 cmd->cmd.runtest->end_state);
144 cmd->cmd.pathmove->num_states,
145 cmd->cmd.pathmove->path[
cmd->cmd.pathmove->num_states - 1]);
152 LOG_DEBUG_IO(
"%s type:%d",
cmd->cmd.scan->ir_scan ?
"IRSCAN" :
"DRSCAN",
156 while (
cmd->cmd.scan->num_fields > 0
157 &&
cmd->cmd.scan->fields[
cmd->cmd.scan->num_fields - 1].num_bits == 0) {
158 cmd->cmd.scan->num_fields--;
159 LOG_DEBUG(
"discarding trailing empty field");
162 if (
cmd->cmd.scan->num_fields == 0) {
167 if (
cmd->cmd.scan->ir_scan) {
182 unsigned scan_size = 0;
184 for (
int i = 0; i <
cmd->cmd.scan->num_fields; i++, field++) {
190 cmd->cmd.scan->num_fields,
203 uint8_t last_bit = 0;
206 uint8_t tms_bits = 0x01;
239 (
cmd->cmd.scan->ir_scan) ?
"IR" :
"DR", scan_size,
272 LOG_ERROR(
"BUG: Unknown JTAG command type encountered");
299 struct jaylink_speed tmp;
302 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_SPEEDS)) {
303 ret = jaylink_get_speeds(
devh, &tmp);
305 if (ret != JAYLINK_OK) {
306 LOG_ERROR(
"jaylink_get_speeds() failed: %s",
307 jaylink_strerror(ret));
312 max_speed = tmp.freq / tmp.div;
318 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_ADAPTIVE_CLOCKING)) {
319 LOG_ERROR(
"Adaptive clocking is not supported by the device");
323 speed = JAYLINK_SPEED_ADAPTIVE_CLOCKING;
324 }
else if (speed > max_speed) {
325 LOG_INFO(
"Reduced speed from %d kHz to %d kHz (maximum)", speed,
330 ret = jaylink_set_speed(
devh, speed);
332 if (ret != JAYLINK_OK) {
333 LOG_ERROR(
"jaylink_set_speed() failed: %s",
334 jaylink_strerror(ret));
359 ret = jaylink_read_raw_config(
devh, (uint8_t *)cfg);
361 if (ret != JAYLINK_OK) {
362 LOG_ERROR(
"jaylink_read_raw_config() failed: %s",
363 jaylink_strerror(ret));
381 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SELECT_TIF)) {
382 if (
iface != JAYLINK_TIF_JTAG) {
383 LOG_ERROR(
"Device supports JTAG transport only");
390 ret = jaylink_get_available_interfaces(
devh, &interfaces);
392 if (ret != JAYLINK_OK) {
393 LOG_ERROR(
"jaylink_get_available_interfaces() failed: %s",
394 jaylink_strerror(ret));
398 if (!(interfaces & (1 <<
iface))) {
399 LOG_ERROR(
"Selected transport is not supported by the device");
406 LOG_ERROR(
"jaylink_select_interface() failed: %s",
407 jaylink_strerror(ret));
421 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_REGISTER))
426 if (ret != JAYLINK_OK) {
427 LOG_ERROR(
"jaylink_register() failed: %s", jaylink_strerror(ret));
431 handle_found =
false;
433 for (i = 0; i <
count; i++) {
441 LOG_ERROR(
"Registration failed: maximum number of connections on the "
459 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_FREE_MEMORY))
462 ret = jaylink_get_free_memory(
devh, &tmp);
464 if (ret != JAYLINK_OK) {
465 LOG_ERROR(
"jaylink_get_free_memory() failed: %s",
466 jaylink_strerror(ret));
471 LOG_ERROR(
"Not enough free device internal memory: %" PRIu32
" bytes", tmp);
479 LOG_DEBUG(
"Adjusted SWD transaction buffer size to %u bytes",
487 enum jaylink_log_level level,
const char *format, va_list args,
493 case JAYLINK_LOG_LEVEL_ERROR:
496 case JAYLINK_LOG_LEVEL_WARNING:
503 case JAYLINK_LOG_LEVEL_INFO:
504 case JAYLINK_LOG_LEVEL_DEBUG:
507 case JAYLINK_LOG_LEVEL_DEBUG_IO:
527 retval = jaylink_device_get_usb_bus_ports(dev, &bus, &ports, &num_ports);
529 if (retval == JAYLINK_ERR_NOT_SUPPORTED) {
531 }
else if (retval != JAYLINK_OK) {
532 LOG_WARNING(
"jaylink_device_get_usb_bus_ports() failed: %s",
533 jaylink_strerror(retval));
546 int ret = jaylink_discovery_scan(
jayctx, ifaces);
547 if (ret != JAYLINK_OK) {
548 LOG_ERROR(
"jaylink_discovery_scan() failed: %s", jaylink_strerror(ret));
554 struct jaylink_device **
devs;
555 ret = jaylink_get_devices(
jayctx, &
devs, &num_devices);
557 if (ret != JAYLINK_OK) {
558 LOG_ERROR(
"jaylink_get_devices() failed: %s", jaylink_strerror(ret));
566 LOG_ERROR(
"Multiple devices found, specify the desired device");
567 jaylink_free_devices(
devs,
true);
572 *found_device =
false;
574 for (
size_t i = 0;
devs[i]; i++) {
575 struct jaylink_device *dev =
devs[i];
579 ret = jaylink_device_get_serial_number(dev, &tmp);
581 if (ret == JAYLINK_ERR_NOT_AVAILABLE) {
583 }
else if (ret != JAYLINK_OK) {
584 LOG_WARNING(
"jaylink_device_get_serial_number() failed: %s",
585 jaylink_strerror(ret));
594 enum jaylink_usb_address address;
595 ret = jaylink_device_get_usb_address(dev, &address);
597 if (ret == JAYLINK_ERR_NOT_SUPPORTED) {
599 }
else if (ret != JAYLINK_OK) {
600 LOG_WARNING(
"jaylink_device_get_usb_address() failed: %s",
601 jaylink_strerror(ret));
612 ret = jaylink_open(dev, &
devh);
614 if (ret == JAYLINK_OK) {
615 *found_device =
true;
619 LOG_ERROR(
"Failed to open device: %s", jaylink_strerror(ret));
622 jaylink_free_devices(
devs,
true);
630 char *firmware_version;
631 struct jaylink_hardware_version hwver;
632 struct jaylink_hardware_status hwstatus;
635 LOG_DEBUG(
"Using libjaylink %s (compiled with %s)",
636 jaylink_version_package_get_string(), JAYLINK_VERSION_PACKAGE_STRING);
638 if (!jaylink_library_has_cap(JAYLINK_CAP_HIF_USB) &&
use_usb_address) {
639 LOG_ERROR(
"J-Link driver does not support USB devices");
643 ret = jaylink_init(&
jayctx);
645 if (ret != JAYLINK_OK) {
646 LOG_ERROR(
"jaylink_init() failed: %s", jaylink_strerror(ret));
652 if (ret != JAYLINK_OK) {
653 LOG_ERROR(
"jaylink_log_set_callback() failed: %s",
654 jaylink_strerror(ret));
662 if (ret == JAYLINK_ERR) {
667 if (ret != JAYLINK_OK) {
668 LOG_ERROR(
"jaylink_parse_serial_number() failed: %s", jaylink_strerror(ret));
698 ret = jaylink_get_firmware_version(
devh, &firmware_version, &
length);
700 if (ret != JAYLINK_OK) {
701 LOG_ERROR(
"jaylink_get_firmware_version() failed: %s",
702 jaylink_strerror(ret));
708 free(firmware_version);
710 LOG_WARNING(
"Device responds empty firmware version string");
713 memset(
caps, 0, JAYLINK_DEV_EXT_CAPS_SIZE);
716 if (ret != JAYLINK_OK) {
717 LOG_ERROR(
"jaylink_get_caps() failed: %s", jaylink_strerror(ret));
723 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_EXT_CAPS)) {
724 ret = jaylink_get_extended_caps(
devh,
caps);
726 if (ret != JAYLINK_OK) {
727 LOG_ERROR(
"jaylink_get_extended_caps() failed: %s",
728 jaylink_strerror(ret));
737 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_HW_VERSION)) {
738 ret = jaylink_get_hardware_version(
devh, &hwver);
740 if (ret != JAYLINK_OK) {
741 LOG_ERROR(
"Failed to retrieve hardware version: %s",
742 jaylink_strerror(ret));
748 LOG_INFO(
"Hardware version: %u.%02u", hwver.major, hwver.minor);
750 if (hwver.major >= 5)
754 if (
iface == JAYLINK_TIF_SWD) {
768 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
770 LOG_ERROR(
"Failed to read device configuration data");
779 ret = jaylink_get_hardware_status(
devh, &hwstatus);
781 if (ret != JAYLINK_OK) {
782 LOG_ERROR(
"jaylink_get_hardware_status() failed: %s",
783 jaylink_strerror(ret));
789 LOG_INFO(
"VTarget = %u.%03u V", hwstatus.target_voltage / 1000,
790 hwstatus.target_voltage % 1000);
794 strcpy(
conn.hid,
"0.0.0.0");
820 if (
iface == JAYLINK_TIF_JTAG) {
841 ret = jaylink_swo_stop(
devh);
843 if (ret != JAYLINK_OK)
844 LOG_ERROR(
"jaylink_swo_stop() failed: %s", jaylink_strerror(ret));
847 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_REGISTER)) {
850 if (ret != JAYLINK_OK)
851 LOG_ERROR(
"jaylink_unregister() failed: %s",
852 jaylink_strerror(ret));
878 uint8_t tms_scan_bits;
893 for (i = 0; i < num_states; i++) {
899 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition",
916 for (i = 0; i < num_cycles; i++)
942 LOG_DEBUG(
"TRST: %i, SRST: %i", trst, srst);
946 jaylink_set_reset(
devh);
949 jaylink_clear_reset(
devh);
952 jaylink_jtag_clear_trst(
devh);
955 jaylink_jtag_set_trst(
devh);
974 if (sscanf(
CMD_ARGV[0],
"%i", &tmp) != 1) {
979 if (tmp < JAYLINK_USB_ADDRESS_0 || tmp > JAYLINK_USB_ADDRESS_3) {
994 struct jaylink_hardware_status
status;
996 ret = jaylink_get_hardware_status(
devh, &
status);
998 if (ret != JAYLINK_OK) {
1000 jaylink_strerror(ret));
1005 status.target_voltage / 1000,
status.target_voltage % 1000);
1011 if (
status.target_voltage < 1500)
1022 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_FREE_MEMORY)) {
1028 ret = jaylink_get_free_memory(
devh, &tmp);
1030 if (ret != JAYLINK_OK) {
1032 jaylink_strerror(ret));
1048 case JAYLINK_JTAG_VERSION_2:
1051 case JAYLINK_JTAG_VERSION_3:
1060 if (sscanf(
CMD_ARGV[0],
"%i", &tmp) != 1) {
1094 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SET_TARGET_POWER)) {
1102 }
else if (!strcmp(
CMD_ARGV[0],
"off")) {
1109 ret = jaylink_set_target_power(
devh, enable);
1111 if (ret != JAYLINK_OK) {
1113 jaylink_strerror(ret));
1163 "[%.02x:%.02x:%.02x:%.02x:%.02x:%.02x]",
1175 const char *current_target_power;
1183 current_target_power =
"off";
1185 current_target_power =
"on";
1189 current_target_power);
1200 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SET_TARGET_POWER))
1203 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_ETHERNET)) {
1218 if (ret != JAYLINK_OK) {
1219 LOG_ERROR(
"jaylink_swo_read() failed: %s", jaylink_strerror(ret));
1233 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_FREE_MEMORY))
1236 ret = jaylink_get_free_memory(
devh, &tmp);
1238 if (ret != JAYLINK_OK) {
1239 LOG_ERROR(
"jaylink_get_free_memory() failed: %s",
1240 jaylink_strerror(ret));
1244 if (tmp > 0x3fff || tmp <= 0x600)
1249 return tmp & 0xffffff00;
1253 uint32_t trace_freq, uint16_t *prescaler)
1255 unsigned int presc = (traceclkin_freq + trace_freq / 2) / trace_freq;
1260 unsigned int max_deviation = (traceclkin_freq * 3) / 100;
1261 if (presc * trace_freq < traceclkin_freq - max_deviation ||
1262 presc * trace_freq > traceclkin_freq + max_deviation)
1271 unsigned int traceclkin_freq,
unsigned int *trace_freq,
1272 uint16_t *prescaler)
1278 for (divider = speed.min_div; divider <= speed.max_div; divider++) {
1279 *trace_freq = speed.freq / divider;
1285 deviation = fabs(1.0 - ((
double)*trace_freq * presc / traceclkin_freq));
1297 uint32_t port_size,
unsigned int *trace_freq,
1298 unsigned int traceclkin_freq, uint16_t *prescaler)
1301 uint32_t buffer_size;
1302 struct jaylink_swo_speed speed;
1309 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SWO)) {
1313 LOG_ERROR(
"Trace capturing is not supported by the device");
1317 ret = jaylink_swo_stop(
devh);
1319 if (ret != JAYLINK_OK) {
1320 LOG_ERROR(
"jaylink_swo_stop() failed: %s", jaylink_strerror(ret));
1336 LOG_ERROR(
"Selected pin protocol is not supported");
1343 LOG_ERROR(
"Not enough free device memory to start trace capturing");
1347 ret = jaylink_swo_get_speeds(
devh, JAYLINK_SWO_MODE_UART, &speed);
1349 if (ret != JAYLINK_OK) {
1350 LOG_ERROR(
"jaylink_swo_get_speeds() failed: %s",
1351 jaylink_strerror(ret));
1355 if (*trace_freq > 0) {
1356 divider = speed.freq / *trace_freq;
1357 min_freq = speed.freq / speed.max_div;
1358 max_freq = speed.freq / speed.min_div;
1360 if (*trace_freq > max_freq) {
1361 LOG_INFO(
"Given SWO frequency too high, using %" PRIu32
" Hz instead",
1363 *trace_freq = max_freq;
1364 }
else if (*trace_freq < min_freq) {
1365 LOG_INFO(
"Given SWO frequency too low, using %" PRIu32
" Hz instead",
1367 *trace_freq = min_freq;
1368 }
else if (*trace_freq != speed.freq / divider) {
1369 *trace_freq = speed.freq / divider;
1371 LOG_INFO(
"Given SWO frequency is not supported by the device, "
1372 "using %u Hz instead", *trace_freq);
1377 LOG_ERROR(
"SWO frequency is not suitable. Please choose a "
1378 "different frequency or use auto-detection");
1382 LOG_INFO(
"Trying to auto-detect SWO frequency");
1386 LOG_ERROR(
"Maximum permitted frequency deviation of %.02f %% "
1388 LOG_ERROR(
"Auto-detection of SWO frequency failed");
1392 LOG_INFO(
"Using SWO frequency of %u Hz", *trace_freq);
1395 ret = jaylink_swo_start(
devh, JAYLINK_SWO_MODE_UART, *trace_freq,
1398 if (ret != JAYLINK_OK) {
1399 LOG_ERROR(
"jaylink_start_swo() failed: %s", jaylink_strerror(ret));
1403 LOG_DEBUG(
"Using %" PRIu32
" bytes device memory for trace capturing",
1420 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1429 if (sscanf(
CMD_ARGV[0],
"%" SCNd8, &tmp) != 1) {
1434 if (tmp > JAYLINK_USB_ADDRESS_3) {
1452 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1458 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SET_TARGET_POWER)) {
1469 }
else if (!strcmp(
CMD_ARGV[0],
"off")) {
1493 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1499 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_ETHERNET)) {
1510 if ((strlen(str) != 17) || (str[2] !=
':' || str[5] !=
':' ||
1511 str[8] !=
':' || str[11] !=
':' || str[14] !=
':')) {
1516 for (i = 5; i >= 0; i--) {
1517 addr[i] = strtoul(str, &e, 16);
1526 if (!(0x01 &
addr[0])) {
1544 const char *s_save = s;
1550 for (i = 0; i < 4; i++) {
1551 lip[i] = strtoul(s, &e, 10);
1553 if (*e !=
'.' && i != 3)
1560 memcpy(ip, lip,
sizeof(lip));
1565 static void cpy_ip(uint8_t *dst, uint8_t *src)
1569 for (i = 0, j = 3; i < 4; i++, j--)
1578 uint8_t subnet_bits = 24;
1580 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1586 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_ETHERNET)) {
1613 ((1ULL << subnet_bits) - 1) : 0xffffffff);
1624 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG))
1637 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1643 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_WRITE_CONFIG)) {
1651 "the configuration");
1655 ret = jaylink_write_raw_config(
devh, (
const uint8_t *)&
tmp_config);
1657 if (ret != JAYLINK_OK) {
1658 LOG_ERROR(
"jaylink_write_raw_config() failed: %s",
1659 jaylink_strerror(ret));
1664 LOG_ERROR(
"Failed to read device configuration for verification");
1669 LOG_ERROR(
"Verification of device configuration failed. Please check "
1676 "cycling the J-Link device");
1683 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1706 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_EMUCOM)) {
1707 LOG_ERROR(
"Device does not support EMUCOM");
1716 LOG_ERROR(
"Data must be encoded as hexadecimal pairs");
1720 buf = malloc(tmp / 2);
1729 if (
dummy != (tmp / 2)) {
1730 LOG_ERROR(
"Data must be encoded as hexadecimal pairs");
1736 ret = jaylink_emucom_write(
devh, channel, buf, &
length);
1740 if (ret == JAYLINK_ERR_DEV_NOT_SUPPORTED) {
1741 LOG_ERROR(
"Channel not supported by the device");
1743 }
else if (ret != JAYLINK_OK) {
1744 LOG_ERROR(
"Failed to write to channel: %s", jaylink_strerror(ret));
1765 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_EMUCOM)) {
1766 LOG_ERROR(
"Device does not support EMUCOM");
1773 buf = malloc(
length * 3 + 1);
1780 ret = jaylink_emucom_read(
devh, channel, buf, &
length);
1782 if (ret == JAYLINK_ERR_DEV_NOT_SUPPORTED) {
1783 LOG_ERROR(
"Channel is not supported by the device");
1786 }
else if (ret == JAYLINK_ERR_DEV_NOT_AVAILABLE) {
1787 LOG_ERROR(
"Channel is not available for the requested amount of data. "
1788 "%" PRIu32
" bytes are available",
length);
1791 }
else if (ret != JAYLINK_OK) {
1792 LOG_ERROR(
"Failed to read from channel: %s", jaylink_strerror(ret));
1800 LOG_ERROR(
"Failed to convert data into hexadecimal string");
1814 .handler = &jlink_handle_config_usb_address_command,
1816 .help =
"set the USB address",
1820 .name =
"targetpower",
1821 .handler = &jlink_handle_config_target_power_command,
1823 .help =
"set the target power supply",
1828 .handler = &jlink_handle_config_mac_address_command,
1830 .help =
"set the MAC Address",
1831 .usage =
"[ff:ff:ff:ff:ff:ff]",
1835 .handler = &jlink_handle_config_ip_address_command,
1837 .help =
"set the IP address, where A.B.C.D is the IP address, "
1838 "E the bit of the subnet mask, F.G.H.I the subnet mask",
1839 .usage =
"[A.B.C.D[/E] [F.G.H.I]]",
1843 .handler = &jlink_handle_config_reset_command,
1845 .help =
"undo configuration changes",
1850 .handler = &jlink_handle_config_write_command,
1852 .help =
"write configuration to the device",
1861 .handler = &jlink_handle_emucom_write_command,
1863 .help =
"write to a channel",
1864 .usage =
"<channel> <data>",
1868 .handler = &jlink_handle_emucom_read_command,
1870 .help =
"read from a channel",
1871 .usage =
"<channel> <length>"
1879 .handler = &jlink_handle_jlink_jtag_command,
1881 .help =
"select the JTAG command version",
1885 .name =
"targetpower",
1886 .handler = &jlink_handle_target_power_command,
1888 .help =
"set the target power supply",
1893 .handler = &jlink_handle_free_memory_command,
1895 .help =
"show free device memory",
1900 .handler = &jlink_handle_hwstatus_command,
1902 .help =
"show the hardware status",
1907 .handler = &jlink_usb_command,
1909 .help =
"set the USB address of the device that should be used",
1914 .handler = &jlink_handle_config_command,
1916 .help =
"access the device configuration. If no argument is given "
1917 "this will show the device configuration",
1924 .help =
"access EMUCOM channel",
1935 .help =
"perform jlink management",
1944 iface = JAYLINK_TIF_SWD;
1981 #define MAX_PENDING_SCAN_RESULTS 256
1995 const uint8_t *tms_out,
unsigned tms_offset,
1996 uint8_t *in,
unsigned in_offset,
2002 if (!available_length ||
2012 unsigned scan_length =
length > available_length ?
2013 available_length :
length;
2029 out_offset += scan_length;
2030 tms_offset += scan_length;
2031 in_offset += scan_length;
2050 if (ret != JAYLINK_OK) {
2051 LOG_ERROR(
"jaylink_jtag_io() failed: %s", jaylink_strerror(ret));
2086 const uint32_t dir_out = 0xffffffff;
2099 const uint32_t dir_in = 0;
2147 LOG_ERROR(
"Sequence %d not supported", seq);
2176 if (ret != JAYLINK_OK) {
2177 LOG_ERROR(
"jaylink_swd_io() failed: %s", jaylink_strerror(ret));
2194 LOG_ERROR(
"SWD: Read data parity mismatch");
const char * adapter_get_required_serial(void)
Retrieves the serial number set with command 'adapter serial'.
bool adapter_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, size_t path_len)
unsigned int adapter_get_speed_khz(void)
Retrieves the clock speed of the adapter in kHz.
const char * adapter_usb_get_location(void)
@ TPIU_PIN_PROTOCOL_ASYNC_UART
asynchronous output with NRZ coding
size_t hexify(char *hex, const uint8_t *bin, size_t count, size_t length)
Convert binary data into a string of hexadecimal pairs.
size_t unhexify(uint8_t *bin, const char *hex, size_t count)
Convert a string of hexadecimal pairs into its binary representation.
void * buf_set_buf(const void *_src, unsigned src_start, void *_dst, unsigned dst_start, unsigned len)
static void bit_copy(uint8_t *dst, unsigned dst_offset, const uint8_t *src, unsigned src_offset, unsigned bit_count)
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.
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.
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#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...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define ERROR_COMMAND_ARGUMENT_INVALID
struct jtag_command * jtag_command_queue
The current queue of jtag_command_s structures.
enum scan_type jtag_scan_type(const struct scan_command *cmd)
#define TPIU_ACPR_MAX_SWOSCALER
bool tap_is_state_stable(tap_state_t astate)
Function tap_is_state_stable returns true if the astate is stable.
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...
const char * tap_state_name(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
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 ...
tap_state_t tap_get_end_state(void)
For more information,.
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 ...
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...
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 ...
static tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf, unsigned tap_len, tap_state_t start_tap_state)
Prints verbose TAP state transitions for the given TMS/TDI buffers.
#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...
static void cpy_ip(uint8_t *dst, uint8_t *src)
static void jlink_queue_data_in(uint32_t len)
static uint8_t caps[JAYLINK_DEV_EXT_CAPS_SIZE]
#define MAX_PENDING_SCAN_RESULTS
static int config_trace(bool enabled, enum tpiu_pin_protocol pin_protocol, uint32_t port_size, unsigned int *trace_freq, unsigned int traceclkin_freq, uint16_t *prescaler)
static int poll_trace(uint8_t *buf, size_t *size)
static void show_config_ip_address(struct command_invocation *cmd)
static int jlink_quit(void)
static uint8_t tdi_buffer[JLINK_TAP_BUFFER_SIZE]
static int jlink_khz(int khz, int *jtag_speed)
static unsigned tap_length
static bool use_serial_number
static void jlink_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
static void jlink_queue_data_out(const uint8_t *data, uint32_t len)
static void jlink_execute_scan(struct jtag_command *cmd)
static const struct command_registration jlink_config_subcommand_handlers[]
struct pending_scan_result __attribute__
static int jlink_init(void)
static void jlink_reset(int trst, int srst)
static bool use_usb_location
static int jlink_swd_switch_seq(enum swd_special_seq seq)
static bool detect_swo_freq_and_prescaler(struct jaylink_swo_speed speed, unsigned int traceclkin_freq, unsigned int *trace_freq, uint16_t *prescaler)
static int jaylink_log_handler(const struct jaylink_context *ctx, enum jaylink_log_level level, const char *format, va_list args, void *user_data)
static bool string_to_ip(const char *s, uint8_t *ip, int *pos)
static bool calculate_swo_prescaler(unsigned int traceclkin_freq, uint32_t trace_freq, uint16_t *prescaler)
static void show_config_usb_address(struct command_invocation *cmd)
static void fill_buffer(uint8_t *buf, uint32_t val, uint32_t len)
#define JLINK_TAP_BUFFER_SIZE
static int jlink_open_device(uint32_t ifaces, bool *found_device)
static void jlink_end_state(tap_state_t state)
static void jlink_clock_data(const uint8_t *out, unsigned out_offset, const uint8_t *tms_out, unsigned tms_offset, uint8_t *in, unsigned in_offset, unsigned length)
Queue data to go out and in, flushing the queue as many times as necessary.
static void jlink_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
static int jlink_speed_div(int speed, int *khz)
static int jlink_swd_run_queue(void)
static void jlink_state_move(void)
static enum jaylink_jtag_version jtag_command_version
static void jlink_execute_runtest(struct jtag_command *cmd)
static void jlink_execute_pathmove(struct jtag_command *cmd)
static int jlink_register(void)
COMMAND_HANDLER(jlink_usb_command)
static void jlink_path_move(int num_states, tap_state_t *path)
static struct jaylink_connection connlist[JAYLINK_MAX_CONNECTIONS]
static enum jaylink_usb_address usb_address
static struct pending_scan_result pending_scan_results_buffer[MAX_PENDING_SCAN_RESULTS]
static int jlink_reset_safe(int trst, int srst)
static const struct command_registration jlink_emucom_subcommand_handlers[]
static uint32_t serial_number
static bool jlink_usb_location_equal(struct jaylink_device *dev)
static struct jtag_interface jlink_interface
static bool read_device_config(struct device_config *cfg)
static int select_interface(void)
static const struct command_registration jlink_command_handlers[]
static int jlink_speed(int speed)
static int jlink_execute_command(struct jtag_command *cmd)
static bool use_usb_address
static struct jaylink_connection conn
static void jlink_runtest(int num_cycles)
static void jlink_tap_init(void)
static int jlink_swd_init(void)
static struct jaylink_device_handle * devh
static struct device_config config
static void show_config_mac_address(struct command_invocation *cmd)
static void show_config_target_power(struct command_invocation *cmd)
static struct jaylink_context * jayctx
static int jlink_flush(void)
static struct device_config tmp_config
static const char *const jlink_transports[]
static void jlink_execute_statemove(struct jtag_command *cmd)
static void show_config(struct command_invocation *cmd)
static uint8_t tdo_buffer[JLINK_TAP_BUFFER_SIZE]
static int jlink_execute_queue(void)
static enum jaylink_target_interface iface
static bool adjust_swd_buffer_size(void)
static enum tap_state jlink_last_state
static void jlink_execute_sleep(struct jtag_command *cmd)
static const struct command_registration jlink_subcommand_handlers[]
static unsigned int swd_buffer_size
struct adapter_driver jlink_adapter_driver
static uint32_t calculate_trace_buffer_size(void)
static uint8_t tms_buffer[JLINK_TAP_BUFFER_SIZE]
static const struct swd_driver jlink_swd
static void jlink_execute_stableclocks(struct jtag_command *cmd)
static void jlink_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
static void jlink_stableclocks(int num_cycles)
static int pending_scan_results_length
static bool trace_enabled
void jtag_sleep(uint32_t us)
#define ERROR_JTAG_DEVICE_ERROR
tap_state
Defines JTAG Test Access Port states.
#define ERROR_JTAG_QUEUE_FAILED
#define ERROR_JTAG_INIT_FAILED
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
#define ERROR_JTAG_NOT_IMPLEMENTED
static struct libusb_device ** devs
The usb device list.
void log_vprintf_lf(enum log_levels level, const char *file, unsigned line, const char *function, const char *format, va_list args)
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
size_t size
Size of the control block search area.
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
When run_command is called, a new instance will be created on the stack, filled with the proper value...
const char * usage
a string listing the options and arguments, required or optional
Represents a driver for a debugging interface.
int(* execute_queue)(void)
Execute queued commands.
int first
First bit position in tdo_buffer to read.
void * buffer
Location to store the result.
int length
Number of bits to read.
uint8_t * buffer
Location to store the result.
unsigned buffer_offset
Offset in the destination buffer.
This structure defines a single scan field in the scan.
int num_bits
The number of bits this field specifies.
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
const uint8_t * out_value
A pointer to value to be scanned into the device.
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
static const unsigned swd_seq_swd_to_jtag_len
static const unsigned swd_seq_jtag_to_swd_len
static const uint8_t swd_seq_dormant_to_jtag[]
Dormant-to-JTAG sequence.
static const uint8_t swd_seq_dormant_to_swd[]
Dormant-to-SWD sequence.
static const uint8_t swd_seq_jtag_to_dormant[]
JTAG-to-dormant sequence.
static const unsigned swd_seq_dormant_to_swd_len
static const unsigned swd_seq_jtag_to_dormant_len
static const unsigned swd_seq_dormant_to_jtag_len
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
static const unsigned swd_seq_line_reset_len
static const unsigned swd_seq_swd_to_dormant_len
static const uint8_t swd_seq_jtag_to_swd[]
JTAG-to-SWD sequence.
static const uint8_t swd_seq_swd_to_jtag[]
SWD-to-JTAG sequence.
static const uint8_t swd_seq_swd_to_dormant[]
SWD-to-dormant sequence.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
static int parity_u32(uint32_t x)
Calculate the (even) parity of a 32-bit datum.
static unsigned int parity(unsigned int v)