This is an automated email from Gerrit.

Antonio Borneo ([email protected]) just uploaded a new patch set to 
Gerrit, which you can find at http://openocd.zylin.com/4852

-- gerrit

commit afe5097dac9128cab0fffdc5319bd556edde2480
Author: Antonio Borneo <[email protected]>
Date:   Wed Aug 29 11:57:42 2018 +0200

    arm_adi_v5: rewrite dap_to_jtag and dap_to_swd
    
    The functions dap_to_jtag() and dap_to_swd() have been introduced by
    3ef9beb52cd0 ("ADIv5 DAP ops switching to JTAG or SWD modes") in
    arm_adi_v5.c by using the JTAG queue only.
    Later, in 6f8b8593d63b ("ADIv5 transport support moves to separate
    files") the functions has been moved in adi_v5_swd.c and adi_v5_jtag.c
    but keeping the dependency from JTAG queue.
    The functions does not work if the current transport is not JTAG.
    
    Move the functions in arm_dap.c, remove the input parameter "target",
    use the transport to detect if the JTAG queue is present, in case
    of SWD transport use the proper methods, for other transport report
    error.
    Reuse the ADI v5 sequences already present in jtag/swd.h.
    Also, OpenOCD does not support switching to another transport after
    the initial selection, so do not change DAP's ops vector.
    
    Change-Id: Ib681fbaa60cb342f732bc831eb92de25afa4e4db
    Signed-off-by: Antonio Borneo <[email protected]>

diff --git a/src/flash/nor/stellaris.c b/src/flash/nor/stellaris.c
index 79aaf3b..8f14b9f 100644
--- a/src/flash/nor/stellaris.c
+++ b/src/flash/nor/stellaris.c
@@ -1384,11 +1384,11 @@ COMMAND_HANDLER(stellaris_handle_recover_command)
        adapter_assert_reset();
 
        for (int i = 0; i < 5; i++) {
-               retval = dap_to_swd(bank->target);
+               retval = dap_to_swd();
                if (retval != ERROR_OK)
                        goto done;
 
-               retval = dap_to_jtag(bank->target);
+               retval = dap_to_jtag();
                if (retval != ERROR_OK)
                        goto done;
        }
diff --git a/src/target/adi_v5_jtag.c b/src/target/adi_v5_jtag.c
index ad4183b..a3867e1 100644
--- a/src/target/adi_v5_jtag.c
+++ b/src/target/adi_v5_jtag.c
@@ -726,52 +726,3 @@ const struct dap_ops jtag_dp_ops = {
        .run                 = jtag_dp_run,
        .sync                = jtag_dp_sync,
 };
-
-
-static const uint8_t swd2jtag_bitseq[] = {
-       /* More than 50 TCK/SWCLK cycles with TMS/SWDIO high,
-        * putting both JTAG and SWD logic into reset state.
-        */
-       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-       /* Switching equence disables SWD and enables JTAG
-        * NOTE: bits in the DP's IDCODE can expose the need for
-        * the old/deprecated sequence (0xae 0xde).
-        */
-       0x3c, 0xe7,
-       /* At least 50 TCK/SWCLK cycles with TMS/SWDIO high,
-        * putting both JTAG and SWD logic into reset state.
-        * NOTE:  some docs say "at least 5".
-        */
-       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-};
-
-/** Put the debug link into JTAG mode, if the target supports it.
- * The link's initial mode may be either SWD or JTAG.
- *
- * @param target Enters JTAG mode (if possible).
- *
- * Note that targets implemented with SW-DP do not support JTAG, and
- * that some targets which could otherwise support it may have been
- * configured to disable JTAG signaling
- *
- * @return ERROR_OK or else a fault code.
- */
-int dap_to_jtag(struct target *target)
-{
-       int retval;
-
-       LOG_DEBUG("Enter JTAG mode");
-
-       /* REVISIT it's nasty to need to make calls to a "jtag"
-        * subsystem if the link isn't in JTAG mode...
-        */
-
-       retval = jtag_add_tms_seq(8 * sizeof(swd2jtag_bitseq),
-                       swd2jtag_bitseq, TAP_RESET);
-       if (retval == ERROR_OK)
-               retval = jtag_execute_queue();
-
-       /* REVISIT set up the DAP's ops vector for JTAG mode. */
-
-       return retval;
-}
diff --git a/src/target/adi_v5_swd.c b/src/target/adi_v5_swd.c
index b520223..eb181cb 100644
--- a/src/target/adi_v5_swd.c
+++ b/src/target/adi_v5_swd.c
@@ -297,71 +297,6 @@ const struct dap_ops swd_dap_ops = {
        .quit = swd_quit,
 };
 
-/*
- * This represents the bits which must be sent out on TMS/SWDIO to
- * switch a DAP implemented using an SWJ-DP module into SWD mode.
- * These bits are stored (and transmitted) LSB-first.
- *
- * See the DAP-Lite specification, section 2.2.5 for information
- * about making the debug link select SWD or JTAG.  (Similar info
- * is in a few other ARM documents.)
- */
-static const uint8_t jtag2swd_bitseq[] = {
-       /* More than 50 TCK/SWCLK cycles with TMS/SWDIO high,
-        * putting both JTAG and SWD logic into reset state.
-        */
-       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-       /* Switching sequence enables SWD and disables JTAG
-        * NOTE: bits in the DP's IDCODE may expose the need for
-        * an old/obsolete/deprecated sequence (0xb6 0xed).
-        */
-       0x9e, 0xe7,
-       /* More than 50 TCK/SWCLK cycles with TMS/SWDIO high,
-        * putting both JTAG and SWD logic into reset state.
-        */
-       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-};
-
-/**
- * Put the debug link into SWD mode, if the target supports it.
- * The link's initial mode may be either JTAG (for example,
- * with SWJ-DP after reset) or SWD.
- *
- * @param target Enters SWD mode (if possible).
- *
- * Note that targets using the JTAG-DP do not support SWD, and that
- * some targets which could otherwise support it may have have been
- * configured to disable SWD signaling
- *
- * @return ERROR_OK or else a fault code.
- */
-int dap_to_swd(struct target *target)
-{
-       struct arm *arm = target_to_arm(target);
-       int retval;
-
-       if (!arm->dap) {
-               LOG_ERROR("SWD mode is not available");
-               return ERROR_FAIL;
-       }
-
-       LOG_DEBUG("Enter SWD mode");
-
-       /* REVISIT it's ugly to need to make calls to a "jtag"
-        * subsystem if the link may not be in JTAG mode...
-        */
-
-       retval =  jtag_add_tms_seq(8 * sizeof(jtag2swd_bitseq),
-                       jtag2swd_bitseq, TAP_INVALID);
-       if (retval == ERROR_OK)
-               retval = jtag_execute_queue();
-
-       /* set up the DAP's ops vector for SWD mode. */
-       arm->dap->ops = &swd_dap_ops;
-
-       return retval;
-}
-
 static const struct command_registration swd_commands[] = {
        {
                /*
diff --git a/src/target/arm_adi_v5.h b/src/target/arm_adi_v5.h
index a340b76..349a4ae 100644
--- a/src/target/arm_adi_v5.h
+++ b/src/target/arm_adi_v5.h
@@ -516,10 +516,10 @@ int dap_lookup_cs_component(struct adiv5_ap *ap,
 struct target;
 
 /* Put debug link into SWD mode */
-int dap_to_swd(struct target *target);
+int dap_to_swd(void);
 
 /* Put debug link into JTAG mode */
-int dap_to_jtag(struct target *target);
+int dap_to_jtag(void);
 
 extern const struct command_registration dap_instance_commands[];
 
diff --git a/src/target/arm_dap.c b/src/target/arm_dap.c
index 3adb4ed..e6e59b9 100644
--- a/src/target/arm_dap.c
+++ b/src/target/arm_dap.c
@@ -29,6 +29,7 @@
 #include "helper/command.h"
 #include "transport/transport.h"
 #include "jtag/interface.h"
+#include "jtag/swd.h"
 
 static LIST_HEAD(all_dap);
 
@@ -146,6 +147,75 @@ int dap_cleanup_all(void)
        return ERROR_OK;
 }
 
+/**
+ * Put the debug link into SWD mode, if the target supports it.
+ * The link's initial mode may be either JTAG (for example,
+ * with SWJ-DP after reset) or SWD.
+ *
+ * Note that targets using the JTAG-DP do not support SWD, and that
+ * some targets which could otherwise support it may have have been
+ * configured to disable SWD signaling
+ *
+ * @return ERROR_OK or else a fault code.
+ */
+int dap_to_swd(void)
+{
+       int retval;
+
+       LOG_DEBUG("Enter SWD mode");
+
+       if (transport_is_jtag()) {
+               retval =  jtag_add_tms_seq(swd_seq_jtag_to_swd_len,
+                               swd_seq_jtag_to_swd, TAP_INVALID);
+               if (retval == ERROR_OK)
+                       retval = jtag_execute_queue();
+               return retval;
+       }
+
+       if (transport_is_swd()) {
+               const struct swd_driver *swd = jtag_interface->swd;
+
+               return swd->switch_seq(JTAG_TO_SWD);
+       }
+
+       LOG_ERROR("Nor JTAG nor SWD transport");
+       return ERROR_FAIL;
+}
+
+/**
+ * Put the debug link into JTAG mode, if the target supports it.
+ * The link's initial mode may be either SWD or JTAG.
+ *
+ * Note that targets implemented with SW-DP do not support JTAG, and
+ * that some targets which could otherwise support it may have been
+ * configured to disable JTAG signaling
+ *
+ * @return ERROR_OK or else a fault code.
+ */
+int dap_to_jtag(void)
+{
+       int retval;
+
+       LOG_DEBUG("Enter JTAG mode");
+
+       if (transport_is_jtag()) {
+               retval = jtag_add_tms_seq(swd_seq_swd_to_jtag_len,
+                               swd_seq_swd_to_jtag, TAP_RESET);
+               if (retval == ERROR_OK)
+                       retval = jtag_execute_queue();
+               return retval;
+       }
+
+       if (transport_is_swd()) {
+               const struct swd_driver *swd = jtag_interface->swd;
+
+               return swd->switch_seq(SWD_TO_JTAG);
+       }
+
+       LOG_ERROR("Nor JTAG nor SWD transport");
+       return ERROR_FAIL;
+}
+
 enum dap_cfg_param {
        CFG_CHAIN_POSITION,
        CFG_IGNORE_SYSPWRUPACK,

-- 


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to