#include "jtag.h"
#include "interface.h"
+#include "transport.h"
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
+/* SVF and XSVF are higher level JTAG command sets (for boundary scan) */
+#include "svf/svf.h"
+#include "xsvf/xsvf.h"
/// The number of JTAG queue flushes (for profiling and debugging purposes).
static int jtag_flush_queue_count;
+// Sleep this # of ms after flushing the queue
+static int jtag_flush_queue_sleep = 0;
+
static void jtag_add_scan_check(struct jtag_tap *active,
void (*jtag_add_scan)(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state),
int in_num_fields, struct scan_field *in_fields, tap_state_t state);
static struct jtag_interface *jtag = NULL;
+
+const struct swd_driver *swd = NULL;
+
/* configuration */
struct jtag_interface *jtag_interface = NULL;
+void jtag_set_flush_queue_sleep(int ms)
+{
+ jtag_flush_queue_sleep = ms;
+}
+
void jtag_set_error(int error)
{
if ((error == ERROR_OK) || (jtag_error != ERROR_OK))
int jtag_unregister_event_callback(jtag_event_handler_t callback, void *priv)
{
- struct jtag_event_callback **callbacks_p;
- struct jtag_event_callback **next;
+ struct jtag_event_callback **p = &jtag_event_callbacks, *temp;
if (callback == NULL)
{
return ERROR_INVALID_ARGUMENTS;
}
- for (callbacks_p = &jtag_event_callbacks;
- *callbacks_p != NULL;
- callbacks_p = next)
+ while (*p)
{
- next = &((*callbacks_p)->next);
-
- if ((*callbacks_p)->priv != priv)
- continue;
-
- if ((*callbacks_p)->callback == callback)
+ if (((*p)->priv != priv) || ((*p)->callback != callback))
{
- free(*callbacks_p);
- *callbacks_p = *next;
+ p = &(*p)->next;
+ continue;
}
+
+ temp = *p;
+ *p = (*p)->next;
+ free(temp);
}
return ERROR_OK;
{
jtag_flush_queue_count++;
jtag_set_error(interface_jtag_execute_queue());
+
+ if (jtag_flush_queue_sleep > 0)
+ {
+ /* For debug purposes it can be useful to test performance
+ * or behavior when delaying after flushing the queue,
+ * e.g. to simulate long roundtrip times.
+ */
+ usleep(jtag_flush_queue_sleep * 1000);
+ }
}
int jtag_get_flush_queue_count(void)
return ERROR_JTAG_INIT_FAILED;
}
+ /* LEGACY SUPPORT ... adapter drivers must declare what
+ * transports they allow. Until they all do so, assume
+ * the legacy drivers are JTAG-only
+ */
+ if (!transports_are_declared()) {
+ LOG_ERROR("Adapter driver '%s' did not declare "
+ "which transports it allows; assuming "
+ "JTAG-only", jtag->name);
+ int retval = allow_transports(cmd_ctx, jtag_only);
+ if (retval != ERROR_OK)
+ return retval;
+ }
+
int requested_khz = jtag_get_speed_khz();
int actual_khz = requested_khz;
- int retval = jtag_get_speed_readable(&actual_khz);
+ int jtag_speed_var;
+ int retval = jtag_get_speed(&jtag_speed_var);
+ if (retval != ERROR_OK)
+ return retval;
+ retval = jtag_get_speed_readable(&actual_khz);
if (ERROR_OK != retval)
- LOG_INFO("adapter-specific clock speed value %d", jtag_get_speed());
+ LOG_INFO("adapter-specific clock speed value %d", jtag_speed_var);
else if (actual_khz)
{
/* Adaptive clocking -- JTAG-specific */
case ERROR_OK:
/* complete success */
break;
- case ERROR_JTAG_INIT_SOFT_FAIL:
+ default:
/* For backward compatibility reasons, try coping with
* configuration errors involving only ID mismatches.
* We might be able to talk to the devices.
+ *
+ * Also the device might be powered down during startup.
+ *
+ * After OpenOCD starts, we can try to power on the device
+ * and run a reset.
*/
LOG_ERROR("Trying to use configured scan chain anyway...");
issue_setup = false;
break;
- default:
- /* some hard error; already issued diagnostics */
- return retval;
}
/* Now look at IR values. Problems here will prevent real
*/
retval = jtag_validate_ircapture();
if (retval != ERROR_OK)
- return retval;
+ {
+ /* The target might be powered down. The user
+ * can power it up and reset it after firing
+ * up OpenOCD.
+ */
+ issue_setup = false;
+ }
if (issue_setup)
jtag_notify_event(JTAG_TAP_EVENT_SETUP);
return (ERROR_OK != retval) ? retval : jtag_set_speed(speed);
}
-int jtag_get_speed(void)
+int jtag_get_speed(int *speed)
{
- int speed;
switch(clock_mode)
{
case CLOCK_MODE_SPEED:
- speed = jtag_speed;
+ *speed = jtag_speed;
break;
case CLOCK_MODE_KHZ:
- adapter_khz_to_speed(jtag_get_speed_khz(), &speed);
+ adapter_khz_to_speed(jtag_get_speed_khz(), speed);
break;
case CLOCK_MODE_RCLK:
- jtag_rclk_to_speed(rclk_fallback_speed_khz, &speed);
+ jtag_rclk_to_speed(rclk_fallback_speed_khz, speed);
break;
default:
LOG_ERROR("BUG: unknown jtag clock mode");
- speed = 0;
- break;
+ return ERROR_FAIL;
}
- return speed;
+ return ERROR_OK;
}
int jtag_get_speed_readable(int *khz)
{
- return jtag ? jtag->speed_div(jtag_get_speed(), khz) : ERROR_OK;
+ int jtag_speed_var;
+ int retval = jtag_get_speed(&jtag_speed_var);
+ if (retval != ERROR_OK)
+ return retval;
+ return jtag ? jtag->speed_div(jtag_speed_var, khz) : ERROR_OK;
}
void jtag_set_verify(bool enable)
{
return jtag_ntrst_assert_width;
}
+
+static int jtag_select(struct command_context *ctx)
+{
+ int retval;
+
+ /* NOTE: interface init must already have been done.
+ * That works with only C code ... no Tcl glue required.
+ */
+
+ retval = jtag_register_commands(ctx);
+
+ if (retval != ERROR_OK)
+ return retval;
+
+ retval = svf_register_commands(ctx);
+
+ if (retval != ERROR_OK)
+ return retval;
+
+ return xsvf_register_commands(ctx);
+}
+
+static struct transport jtag_transport = {
+ .name = "jtag",
+ .select = jtag_select,
+ .init = jtag_init,
+};
+
+static void jtag_constructor(void) __attribute__((constructor));
+static void jtag_constructor(void)
+{
+ transport_register(&jtag_transport);
+}
+
+/** Returns true if the current debug session
+ * is using JTAG as its transport.
+ */
+bool transport_is_jtag(void)
+{
+ return get_current_transport() == &jtag_transport;
+}