OpenOCD
jlink.c File Reference
Include dependency graph for jlink.c:

Go to the source code of this file.

Data Structures

struct  device_config
 
struct  pending_scan_result
 

Macros

#define JLINK_MAX_SPEED   12000
 
#define JLINK_TAP_BUFFER_SIZE   2048
 
#define MAX_PENDING_SCAN_RESULTS   256
 

Functions

struct device_config __attribute__ ((packed))
 
static bool adjust_swd_buffer_size (void)
 
static uint32_t calculate_trace_buffer_size (void)
 
static bool check_trace_freq (struct jaylink_swo_speed speed, uint32_t trace_freq)
 
 COMMAND_HANDLER (jlink_usb_command)
 
 COMMAND_HANDLER (jlink_serial_command)
 
 COMMAND_HANDLER (jlink_handle_hwstatus_command)
 
 COMMAND_HANDLER (jlink_handle_free_memory_command)
 
 COMMAND_HANDLER (jlink_handle_jlink_jtag_command)
 
 COMMAND_HANDLER (jlink_handle_target_power_command)
 
 COMMAND_HANDLER (jlink_handle_config_usb_address_command)
 
 COMMAND_HANDLER (jlink_handle_config_target_power_command)
 
 COMMAND_HANDLER (jlink_handle_config_mac_address_command)
 
 COMMAND_HANDLER (jlink_handle_config_ip_address_command)
 
 COMMAND_HANDLER (jlink_handle_config_reset_command)
 
 COMMAND_HANDLER (jlink_handle_config_write_command)
 
 COMMAND_HANDLER (jlink_handle_config_command)
 
 COMMAND_HANDLER (jlink_handle_emucom_write_command)
 
 COMMAND_HANDLER (jlink_handle_emucom_read_command)
 
static int config_trace (bool enabled, enum tpio_pin_protocol pin_protocol, uint32_t port_size, unsigned int *trace_freq)
 
static void cpy_ip (uint8_t *dst, uint8_t *src)
 
static void fill_buffer (uint8_t *buf, uint32_t val, uint32_t len)
 
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 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. More...
 
static void jlink_end_state (tap_state_t state)
 
static int jlink_execute_command (struct jtag_command *cmd)
 
static void jlink_execute_pathmove (struct jtag_command *cmd)
 
static int jlink_execute_queue (void)
 
static void jlink_execute_reset (struct jtag_command *cmd)
 
static void jlink_execute_runtest (struct jtag_command *cmd)
 
static void jlink_execute_scan (struct jtag_command *cmd)
 
static void jlink_execute_sleep (struct jtag_command *cmd)
 
static void jlink_execute_stableclocks (struct jtag_command *cmd)
 
static void jlink_execute_statemove (struct jtag_command *cmd)
 
static int jlink_flush (void)
 
static int jlink_init (void)
 
static int jlink_khz (int khz, int *jtag_speed)
 
static void jlink_path_move (int num_states, tap_state_t *path)
 
static void jlink_queue_data_in (uint32_t len)
 
static void jlink_queue_data_out (const uint8_t *data, uint32_t len)
 
static int jlink_quit (void)
 
static int jlink_register (void)
 
static void jlink_reset (int trst, int srst)
 
static void jlink_runtest (int num_cycles)
 
static int jlink_speed (int speed)
 
static int jlink_speed_div (int speed, int *khz)
 
static void jlink_stableclocks (int num_cycles)
 
static void jlink_state_move (void)
 
static int_least32_t jlink_swd_frequency (int_least32_t hz)
 
static int jlink_swd_init (void)
 
static void jlink_swd_queue_cmd (uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
 
static void jlink_swd_read_reg (uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
 
static int jlink_swd_run_queue (void)
 
static int jlink_swd_switch_seq (enum swd_special_seq seq)
 
static void jlink_swd_write_reg (uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
 
static void jlink_tap_init (void)
 
static int poll_trace (uint8_t *buf, size_t *size)
 
static bool read_device_config (struct device_config *cfg)
 
static int select_interface (void)
 
static void show_config (struct command_context *ctx)
 
static void show_config_ip_address (struct command_context *ctx)
 
static void show_config_mac_address (struct command_context *ctx)
 
static void show_config_target_power (struct command_context *ctx)
 
static void show_config_usb_address (struct command_context *ctx)
 
static bool string_to_ip (const char *s, uint8_t *ip, int *pos)
 

Variables

struct pending_scan_result __attribute__
 
static uint8_t caps [JAYLINK_DEV_EXT_CAPS_SIZE]
 
static struct device_config config
 
static struct jaylink_connection conn
 
static struct jaylink_connection connlist [JAYLINK_MAX_CONNECTIONS]
 
static struct
jaylink_device_handle
devh
 
static enum
jaylink_target_interface 
iface = JAYLINK_TIF_JTAG
 
uint8_t ip_address [4]
 
static struct jaylink_contextjayctx
 
static const struct
command_registration 
jlink_command_handlers []
 
static const struct
command_registration 
jlink_config_subcommand_handlers []
 
static const struct
command_registration 
jlink_emucom_subcommand_handlers []
 
struct jtag_interface jlink_interface
 
static enum tap_state jlink_last_state = TAP_RESET
 
static const struct
command_registration 
jlink_subcommand_handlers []
 
static const struct swd_driver jlink_swd
 
static const char *const jlink_transports [] = { "jtag", "swd", NULL }
 
static enum jaylink_jtag_version jtag_command_version
 
uint8_t mac_address [6]
 
static struct pending_scan_result pending_scan_results_buffer [MAX_PENDING_SCAN_RESULTS]
 
static int pending_scan_results_length
 
static int queued_retval
 
uint8_t reserved_1 [3]
 
uint8_t reserved_2 [24]
 
uint8_t reserved_3 [8]
 
uint8_t reserved_4 [202]
 
static uint32_t serial_number
 
uint8_t subnet_mask [4]
 
static unsigned int swd_buffer_size = JLINK_TAP_BUFFER_SIZE
 
static unsigned tap_length
 
uint32_t target_power
 
static uint8_t tdi_buffer [JLINK_TAP_BUFFER_SIZE]
 
static uint8_t tdo_buffer [JLINK_TAP_BUFFER_SIZE]
 
static struct device_config tmp_config
 
static uint8_t tms_buffer [JLINK_TAP_BUFFER_SIZE]
 
static bool trace_enabled
 
static enum jaylink_usb_address usb_address
 
static bool use_serial_number
 
static bool use_usb_address
 

Macro Definition Documentation

#define JLINK_MAX_SPEED   12000

Definition at line 58 of file jlink.c.

Referenced by jlink_speed().

#define JLINK_TAP_BUFFER_SIZE   2048

Definition at line 59 of file jlink.c.

Referenced by adjust_swd_buffer_size(), and jlink_clock_data().

#define MAX_PENDING_SCAN_RESULTS   256

Definition at line 1919 of file jlink.c.

Referenced by jlink_clock_data(), and jlink_swd_queue_cmd().

Function Documentation

struct device_config __attribute__ ( (packed)  )
static bool adjust_swd_buffer_size ( void  )
static
static uint32_t calculate_trace_buffer_size ( void  )
static
static bool check_trace_freq ( struct jaylink_swo_speed  speed,
uint32_t  trace_freq 
)
static
COMMAND_HANDLER ( jlink_usb_command  )
COMMAND_HANDLER ( jlink_handle_free_memory_command  )
COMMAND_HANDLER ( jlink_handle_jlink_jtag_command  )
COMMAND_HANDLER ( jlink_handle_config_reset_command  )

Definition at line 1552 of file jlink.c.

References caps, config, ERROR_OK, JAYLINK_DEV_CAP_READ_CONFIG, jaylink_has_cap(), and tmp_config.

COMMAND_HANDLER ( jlink_handle_config_command  )
static void cpy_ip ( uint8_t *  dst,
uint8_t *  src 
)
static

Definition at line 1495 of file jlink.c.

Referenced by COMMAND_HANDLER().

static void fill_buffer ( uint8_t *  buf,
uint32_t  val,
uint32_t  len 
)
static

Definition at line 2008 of file jlink.c.

References buf_set_u32(), and tap_length.

Referenced by jlink_queue_data_in(), and jlink_queue_data_out().

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
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 
)
static

Queue data to go out and in, flushing the queue as many times as necessary.

Parameters
outA pointer to TDI data, if NULL, old stale data will be used.
out_offsetA bit offset for TDI data.
tms_outA pointer to TMS data, if NULL, zeroes will be emitted.
tms_offsetA bit offset for TMS data.
inA pointer to store TDO data to, if NULL the data will be discarded.
in_offsetA bit offset for TDO data.
lengthAmount of bits to transfer out and in.
Return values
Thisfunction doesn't return any value.

Definition at line 1932 of file jlink.c.

References buf_set_buf(), pending_scan_result::buffer, pending_scan_result::buffer_offset, ERROR_OK, pending_scan_result::first, jlink_flush(), JLINK_TAP_BUFFER_SIZE, pending_scan_result::length, length, MAX_PENDING_SCAN_RESULTS, pending_scan_results_buffer, pending_scan_results_length, and tap_length.

Referenced by jlink_execute_scan(), jlink_init(), jlink_path_move(), jlink_stableclocks(), and jlink_state_move().

static void jlink_end_state ( tap_state_t  state)
static
static void jlink_execute_pathmove ( struct jtag_command cmd)
static
static int jlink_execute_queue ( void  )
static
static void jlink_execute_reset ( struct jtag_command cmd)
static
static void jlink_execute_runtest ( struct jtag_command cmd)
static
static void jlink_execute_sleep ( struct jtag_command cmd)
static
static void jlink_execute_stableclocks ( struct jtag_command cmd)
static
static void jlink_execute_statemove ( struct jtag_command cmd)
static
static int jlink_init ( void  )
static

Definition at line 537 of file jlink.c.

References adjust_swd_buffer_size(), caps, jaylink_connection::cid, config, conn, devs, ERROR_JTAG_INIT_FAILED, ERROR_OK, jaylink_connection::handle, jaylink_connection::hid, iface, jaylink_connection::iid, JAYLINK_CAP_HIF_USB, jaylink_close(), JAYLINK_DEV_CAP_GET_EXT_CAPS, JAYLINK_DEV_CAP_GET_HW_VERSION, JAYLINK_DEV_CAP_READ_CONFIG, JAYLINK_DEV_EXT_CAPS_SIZE, jaylink_device_get_serial_number(), jaylink_device_get_usb_address(), jaylink_discovery_scan(), JAYLINK_ERR_NOT_AVAILABLE, JAYLINK_ERR_NOT_SUPPORTED, jaylink_exit(), jaylink_free_devices(), jaylink_get_caps(), jaylink_get_devices(), jaylink_get_extended_caps(), jaylink_get_firmware_version(), jaylink_get_hardware_status(), jaylink_get_hardware_version(), jaylink_has_cap(), JAYLINK_HIF_TCP, JAYLINK_HIF_USB, jaylink_init(), JAYLINK_JTAG_VERSION_2, JAYLINK_JTAG_VERSION_3, jaylink_library_has_cap(), jaylink_log_handler(), jaylink_log_set_callback(), JAYLINK_OK, jaylink_open(), jaylink_strerror(), JAYLINK_TIF_JTAG, JAYLINK_TIF_SWD, jaylink_version_package_get_string(), JAYLINK_VERSION_PACKAGE_STRING, jlink_clock_data(), jlink_flush(), jlink_register(), jlink_reset(), jlink_speed(), jlink_tap_init(), jtag_command_version, jtag_get_speed_khz(), jtag_sleep(), length, LOG_DEBUG, LOG_ERROR, LOG_INFO, LOG_WARNING, jaylink_hardware_version::major, jaylink_hardware_version::minor, NULL, jaylink_connection::pid, read_device_config(), select_interface(), serial_number, jaylink_hardware_status::target_voltage, tmp_config, jaylink_hardware_status::tms, usb_address, use_serial_number, and use_usb_address.

static int jlink_khz ( int  khz,
int *  jtag_speed 
)
static

Definition at line 366 of file jlink.c.

References ERROR_OK.

static void jlink_path_move ( int  num_states,
tap_state_t path 
)
static
static void jlink_queue_data_in ( uint32_t  len)
static

Definition at line 2035 of file jlink.c.

References fill_buffer().

Referenced by jlink_swd_queue_cmd().

static void jlink_queue_data_out ( const uint8_t *  data,
uint32_t  len 
)
static

Definition at line 2022 of file jlink.c.

References bit_copy(), and fill_buffer().

Referenced by jlink_swd_queue_cmd(), jlink_swd_run_queue(), and jlink_swd_switch_seq().

static int jlink_register ( void  )
static
static void jlink_reset ( int  trst,
int  srst 
)
static
static void jlink_runtest ( int  num_cycles)
static
static int jlink_speed_div ( int  speed,
int *  khz 
)
static

Definition at line 359 of file jlink.c.

References ERROR_OK, and speed.

static void jlink_stableclocks ( int  num_cycles)
static
static void jlink_state_move ( void  )
static
static int_least32_t jlink_swd_frequency ( int_least32_t  hz)
static

Definition at line 1891 of file jlink.c.

References jlink_speed().

static int jlink_swd_init ( void  )
static

Definition at line 1872 of file jlink.c.

References ERROR_OK, iface, and JAYLINK_TIF_SWD.

static void jlink_swd_read_reg ( uint8_t  cmd,
uint32_t *  value,
uint32_t  ap_delay_clk 
)
static

Definition at line 1885 of file jlink.c.

References jlink_swd_queue_cmd(), and SWD_CMD_RnW.

static void jlink_swd_write_reg ( uint8_t  cmd,
uint32_t  value,
uint32_t  ap_delay_clk 
)
static

Definition at line 1879 of file jlink.c.

References jlink_swd_queue_cmd(), NULL, and SWD_CMD_RnW.

static void jlink_tap_init ( void  )
static

Definition at line 1924 of file jlink.c.

Referenced by jlink_flush(), jlink_init(), and jlink_swd_run_queue().

static int poll_trace ( uint8_t *  buf,
size_t *  size 
)
static

Definition at line 1193 of file jlink.c.

References ERROR_FAIL, ERROR_OK, JAYLINK_OK, jaylink_strerror(), jaylink_swo_read(), length, and LOG_ERROR.

static bool read_device_config ( struct device_config cfg)
static
static void show_config_ip_address ( struct command_context ctx)
static
static void show_config_mac_address ( struct command_context ctx)
static

Definition at line 1138 of file jlink.c.

References command_print(), config, device_config::mac_address, and tmp_config.

Referenced by COMMAND_HANDLER(), and show_config().

static void show_config_target_power ( struct command_context ctx)
static

Definition at line 1156 of file jlink.c.

References command_print(), config, target_power, device_config::target_power, and tmp_config.

Referenced by COMMAND_HANDLER(), and show_config().

static void show_config_usb_address ( struct command_context ctx)
static

Definition at line 1104 of file jlink.c.

References command_print(), config, tmp_config, and device_config::usb_address.

Referenced by COMMAND_HANDLER(), and show_config().

static bool string_to_ip ( const char *  s,
uint8_t *  ip,
int *  pos 
)
static

Definition at line 1470 of file jlink.c.

Referenced by COMMAND_HANDLER().

Variable Documentation

static __attribute__

Definition at line 648 of file armv8.c.

struct jaylink_connection conn
static

Definition at line 46 of file jlink.c.

Referenced by jlink_init(), jlink_quit(), and jlink_register().

Definition at line 47 of file jlink.c.

Referenced by jlink_quit(), and jlink_register().

struct jaylink_device_handle* devh
static

Definition at line 45 of file jlink.c.

Referenced by aice_usb_open(), allocate_device_handle(), and opendous_usb_open().

uint8_t ip_address[4]

Definition at line 69 of file jlink.c.

Referenced by COMMAND_HANDLER().

struct jaylink_context* jayctx
static

Definition at line 44 of file jlink.c.

const struct command_registration jlink_command_handlers[]
static
Initial value:
= {
{
.name = "jlink",
.mode = COMMAND_ANY,
.help = "perform jlink management",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:222

Definition at line 1862 of file jlink.c.

const struct command_registration jlink_config_subcommand_handlers[]
static

Definition at line 1741 of file jlink.c.

const struct command_registration jlink_emucom_subcommand_handlers[]
static
Initial value:
= {
{
.name = "write",
.handler = &jlink_handle_emucom_write_command,
.mode = COMMAND_EXEC,
.help = "write to a channel",
.usage = "<channel> <data>",
},
{
.name = "read",
.handler = &jlink_handle_emucom_read_command,
.mode = COMMAND_EXEC,
.help = "read from a channel",
.usage = "<channel> <length>"
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:222

Definition at line 1786 of file jlink.c.

struct jtag_interface jlink_interface
Initial value:
= {
.name = "jlink",
.transports = jlink_transports,
.swd = &jlink_swd,
.execute_queue = &jlink_execute_queue,
.speed = &jlink_speed,
.speed_div = &jlink_speed_div,
.khz = &jlink_khz,
.init = &jlink_init,
.quit = &jlink_quit,
.config_trace = &config_trace,
.poll_trace = &poll_trace,
}

Definition at line 2183 of file jlink.c.

enum tap_state jlink_last_state = TAP_RESET
static

Definition at line 117 of file jlink.c.

const struct command_registration jlink_subcommand_handlers[]
static

Definition at line 1804 of file jlink.c.

const struct swd_driver jlink_swd
static
Initial value:
= {
.init = &jlink_swd_init,
.frequency = &jlink_swd_frequency,
.switch_seq = &jlink_swd_switch_seq,
.read_reg = &jlink_swd_read_reg,
.write_reg = &jlink_swd_write_reg,
}

Definition at line 2172 of file jlink.c.

const char* const jlink_transports[] = { "jtag", "swd", NULL }
static

Definition at line 2181 of file jlink.c.

enum jaylink_jtag_version jtag_command_version
static

Definition at line 48 of file jlink.c.

Referenced by COMMAND_HANDLER(), jlink_flush(), and jlink_init().

uint8_t mac_address[6]

Definition at line 73 of file jlink.c.

struct pending_scan_result pending_scan_results_buffer[MAX_PENDING_SCAN_RESULTS]
static

Definition at line 1922 of file jlink.c.

Referenced by jlink_clock_data(), jlink_flush(), jlink_swd_queue_cmd(), and jlink_swd_run_queue().

int pending_scan_results_length
static

Definition at line 1921 of file jlink.c.

Referenced by jlink_clock_data(), jlink_flush(), jlink_swd_queue_cmd(), and jlink_swd_run_queue().

int queued_retval
static

Definition at line 118 of file jlink.c.

Referenced by jlink_swd_run_queue().

uint8_t reserved_1[3]

Definition at line 64 of file jlink.c.

uint8_t reserved_2[24]

Definition at line 67 of file jlink.c.

uint8_t reserved_3[8]

Definition at line 72 of file jlink.c.

uint8_t reserved_4[202]

Definition at line 75 of file jlink.c.

uint32_t serial_number
static

Definition at line 51 of file jlink.c.

Referenced by COMMAND_HANDLER(), jlink_init(), and probe_device().

uint8_t subnet_mask[4]

Definition at line 70 of file jlink.c.

Referenced by COMMAND_HANDLER().

unsigned int swd_buffer_size = JLINK_TAP_BUFFER_SIZE
static

Definition at line 61 of file jlink.c.

Referenced by adjust_swd_buffer_size().

unsigned tap_length
static

Definition at line 1902 of file jlink.c.

Referenced by fill_buffer(), jlink_clock_data(), and jlink_swd_queue_cmd().

uint32_t target_power

Definition at line 65 of file jlink.c.

Referenced by show_config_target_power().

uint8_t tdi_buffer[JLINK_TAP_BUFFER_SIZE]
static

Definition at line 1905 of file jlink.c.

uint8_t tdo_buffer[JLINK_TAP_BUFFER_SIZE]
static

Definition at line 1906 of file jlink.c.

uint8_t tms_buffer[JLINK_TAP_BUFFER_SIZE]
static

Definition at line 1904 of file jlink.c.

bool trace_enabled
static

Definition at line 56 of file jlink.c.

Referenced by config_trace(), and jlink_quit().

uint8_t usb_address
static

Definition at line 53 of file jlink.c.

Referenced by COMMAND_HANDLER(), jlink_init(), and probe_device().

bool use_serial_number
static

Definition at line 52 of file jlink.c.

Referenced by COMMAND_HANDLER(), and jlink_init().

bool use_usb_address
static

Definition at line 54 of file jlink.c.

Referenced by COMMAND_HANDLER(), and jlink_init().