warning: fix silly -O3 warning
[openocd.git] / src / jtag / core.c
index a09472a76c0133a5c6fc2784da75bb54d3ccf80c..dd3a2a61646c0037567947e121f0d95b6f576452 100644 (file)
 
 #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);
@@ -52,9 +59,9 @@ static void jtag_add_scan_check(struct jtag_tap *active,
  * when an error occurs during processing that should be reported during
  * jtag_execute_queue().
  *
- * Tts value may be checked with jtag_get_error() and cleared with
- * jtag_error_clear().  This value is returned (and cleared) by
- * jtag_execute_queue().
+ * The value is set and cleared, but never read by normal application code.
+ *
+ * This value is returned (and cleared) by jtag_execute_queue().
  */
 static int jtag_error = ERROR_OK;
 
@@ -86,7 +93,6 @@ static struct jtag_tap *__jtag_all_taps = NULL;
 static unsigned jtag_num_taps = 0;
 
 static enum reset_types jtag_reset_config = RESET_NONE;
-static tap_state_t cmd_queue_end_state = TAP_RESET;
 tap_state_t cmd_queue_cur_state = TAP_RESET;
 
 static bool jtag_verify_capture_ir = true;
@@ -126,16 +132,18 @@ static struct jtag_interface *jtag = 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))
                return;
        jtag_error = error;
 }
-int jtag_get_error(void)
-{
-       return jtag_error;
-}
+
 int jtag_error_clear(void)
 {
        int temp = jtag_error;
@@ -717,7 +725,6 @@ void jtag_add_reset(int req_tlr_or_trst, int req_srst)
         */
        if (trst_with_tlr) {
                LOG_DEBUG("JTAG reset with TLR instead of TRST");
-               jtag_set_end_state(TAP_RESET);
                jtag_add_tlr();
 
        } else if (jtag_trst != new_trst) {
@@ -743,24 +750,6 @@ void jtag_add_reset(int req_tlr_or_trst, int req_srst)
        }
 }
 
-/* DEPRECATED! store such global state outside JTAG layer */
-void jtag_set_end_state(tap_state_t state)
-{
-       if ((state == TAP_DRSHIFT)||(state == TAP_IRSHIFT))
-       {
-               LOG_ERROR("BUG: TAP_DRSHIFT/IRSHIFT can't be end state. Calling code should use a larger scan field");
-       }
-
-       if (state != TAP_INVALID)
-               cmd_queue_end_state = state;
-}
-
-/* DEPRECATED! store such global state outside JTAG layer */
-tap_state_t jtag_get_end_state(void)
-{
-       return cmd_queue_end_state;
-}
-
 void jtag_add_sleep(uint32_t us)
 {
        /// @todo Here, keep_alive() appears to be a layering violation!!!
@@ -845,6 +834,15 @@ void jtag_execute_queue_noclear(void)
 {
        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)
@@ -1371,6 +1369,19 @@ int adapter_init(struct command_context *cmd_ctx)
                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);
@@ -1434,17 +1445,19 @@ int jtag_init_inner(struct command_context *cmd_ctx)
        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
@@ -1455,7 +1468,13 @@ int jtag_init_inner(struct command_context *cmd_ctx)
         */
        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);
@@ -1615,7 +1634,7 @@ int jtag_config_rclk(unsigned fallback_speed_khz)
 
 int jtag_get_speed(void)
 {
-       int speed;
+       int speed = 0; /* avoid -O3 warning */
        switch(clock_mode)
        {
                case CLOCK_MODE_SPEED:
@@ -1729,3 +1748,44 @@ unsigned jtag_get_ntrst_assert_width(void)
 {
        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;
+}

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)