static void jlink_scan(bool ir_scan, enum scan_type type, uint8_t *buffer,
int scan_size, struct scan_command *command);
static void jlink_reset(int trst, int srst);
-static int jlink_swd_run_queue(struct adiv5_dap *dap);
-static void jlink_swd_queue_cmd(struct adiv5_dap *dap, uint8_t cmd,
- uint32_t *dst, uint32_t data);
-static int jlink_swd_switch_seq(struct adiv5_dap *dap,
- enum swd_special_seq seq);
+static int jlink_swd_run_queue(void);
+static void jlink_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk);
+static int jlink_swd_switch_seq(enum swd_special_seq seq);
/* J-Link tap buffer functions */
static void jlink_tap_init(void);
static int jlink_speed(int speed)
{
int ret;
+ uint32_t freq;
+ uint16_t div;
+ int max_speed;
+
+ if (jaylink_has_cap(caps, JAYLINK_DEV_CAP_GET_SPEEDS)) {
+ ret = jaylink_get_speeds(devh, &freq, &div);
+
+ if (ret != JAYLINK_OK) {
+ LOG_ERROR("jaylink_get_speeds() failed: %s.",
+ jaylink_strerror_name(ret));
+ return ERROR_JTAG_DEVICE_ERROR;
+ }
- if (speed > JLINK_MAX_SPEED) {
- LOG_INFO("Reduce speed from %d kHz to %d kHz (maximum).", speed,
- JLINK_MAX_SPEED);
- speed = JLINK_MAX_SPEED;
+ freq = freq / 1000;
+ max_speed = freq / div;
+ } else {
+ max_speed = JLINK_MAX_SPEED;
}
if (!speed) {
}
speed = JAYLINK_SPEED_ADAPTIVE_CLOCKING;
+ } else if (speed > max_speed) {
+ LOG_INFO("Reduced speed from %d kHz to %d kHz (maximum).", speed,
+ max_speed);
+ speed = max_speed;
}
ret = jaylink_set_speed(devh, speed);
return ERROR_OK;
}
-static void jlink_swd_write_reg(struct adiv5_dap *dap, uint8_t cmd,
- uint32_t value)
+static void jlink_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
{
assert(!(cmd & SWD_CMD_RnW));
- jlink_swd_queue_cmd(dap, cmd, NULL, value);
+ jlink_swd_queue_cmd(cmd, NULL, value, ap_delay_clk);
}
-static void jlink_swd_read_reg(struct adiv5_dap *dap, uint8_t cmd,
- uint32_t *value)
+static void jlink_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
{
assert(cmd & SWD_CMD_RnW);
- jlink_swd_queue_cmd(dap, cmd, value, 0);
+ jlink_swd_queue_cmd(cmd, value, 0, ap_delay_clk);
}
-static int_least32_t jlink_swd_frequency(struct adiv5_dap *dap,
- int_least32_t hz)
+static int_least32_t jlink_swd_frequency(int_least32_t hz)
{
if (hz > 0)
jlink_speed(hz / 1000);
tap_length += len;
}
-static int jlink_swd_switch_seq(struct adiv5_dap *dap, enum swd_special_seq seq)
+static int jlink_swd_switch_seq(enum swd_special_seq seq)
{
const uint8_t *s;
unsigned int s_len;
return ERROR_OK;
}
-static int jlink_swd_run_queue(struct adiv5_dap *dap)
+static int jlink_swd_run_queue(void)
{
int i;
int ret;
return ret;
}
-static void jlink_swd_queue_cmd(struct adiv5_dap *dap, uint8_t cmd,
- uint32_t *dst, uint32_t data)
+static void jlink_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
{
uint8_t data_parity_trn[DIV_ROUND_UP(32 + 1, 8)];
-
- if (tap_length + 46 + 8 + dap->memaccess_tck >= swd_buffer_size * 8 ||
- pending_scan_results_length == MAX_PENDING_SCAN_RESULTS) {
+ if (tap_length + 46 + 8 + ap_delay_clk >= sizeof(tdi_buffer) * 8 ||
+ pending_scan_results_length == MAX_PENDING_SCAN_RESULTS) {
/* Not enough room in the queue. Run the queue. */
- queued_retval = jlink_swd_run_queue(dap);
+ queued_retval = jlink_swd_run_queue();
}
if (queued_retval != ERROR_OK)
/* Insert idle cycles after AP accesses to avoid WAIT. */
if (cmd & SWD_CMD_APnDP)
- jlink_queue_data_out(NULL, dap->memaccess_tck);
+ jlink_queue_data_out(NULL, ap_delay_clk);
}
static const struct swd_driver jlink_swd = {