This is an automated email from Gerrit.

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

-- gerrit

commit cd0c8ede8993ff845248bd7a2a57ef11b193c466
Author: Tomas Vanek <[email protected]>
Date:   Tue Apr 6 13:59:14 2021 +0200

    jtag/tcl: introduce multidrop_targetsel and its configuration
    
    Target selection is possible in both JTAG and SWD according to
    ARM IHI 0031C. Although we're going to implement SWD part only,
    define multidrop_targetsel as a struct jtag_tap member.
    
    Based on Graham Sanderson's http://openocd.zylin.com/4935
    
    Change-Id: Ibb93abb5f50b3665c320a10c1497421035762134
    Signed-off-by: Tomas Vanek <[email protected]>

diff --git a/doc/openocd.texi b/doc/openocd.texi
index b3fe854..7541015 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -4021,6 +4021,18 @@ there seems to be no problems with JTAG scan chain 
operations.
 register during initial examination and when checking the sticky error bit.
 This bit is normally checked after setting the CSYSPWRUPREQ bit, but some
 devices do not set the ack bit until sometime later.
+@item @code{-dp-id} @var{number}
+@*Debug port identification number for SWD DPv2 multidrop.
+The @var{number} is written to bits 0..27 of DP TARGETSEL during DP selection.
+To find the id number of a single connected device read DP TARGETID:
+@code{device.dap dpreg 0x24}
+Use bits 0..27 of TARGETID.
+@item @code{-instance-id} @var{number}
+@*Instance identification number for SWD DPv2 multidrop.
+The @var{number} is written to bits 28..31 of DP TARGETSEL during DP selection.
+To find the instance number of a single connected device read DP DLPIDR:
+@code{device.dap dpreg 0x34}
+The instance number is in bits 28..31 of DLPIDR value.
 @end itemize
 @end deffn
 
diff --git a/src/jtag/jtag.h b/src/jtag/jtag.h
index 86091e6..ba5baa9 100644
--- a/src/jtag/jtag.h
+++ b/src/jtag/jtag.h
@@ -141,6 +141,10 @@ struct jtag_tap {
 
        struct jtag_tap_event_action *event_action;
 
+       /* Value to use with DP_TARGETSEL in SWD multidrop mode, otherwise
+        * DP_TARGETSEL_INVALID*/
+       uint32_t multidrop_targetsel;
+
        struct jtag_tap *next_tap;
        /* private pointer to support none-jtag specific functions */
        void *priv;
diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c
index 2fa162e..171f946 100644
--- a/src/jtag/tcl.c
+++ b/src/jtag/tcl.c
@@ -475,6 +475,9 @@ static int jim_newtap_expected_id(Jim_Nvp *n, 
Jim_GetOptInfo *goi,
 #define NTAP_OPT_DISABLED  4
 #define NTAP_OPT_EXPECTED_ID 5
 #define NTAP_OPT_VERSION   6
+#define NTAP_OPT_DP_ID 7
+#define NTAP_OPT_INSTANCE_ID 8
+
 
 static int jim_newtap_ir_param(Jim_Nvp *n, Jim_GetOptInfo *goi,
        struct jtag_tap *pTap)
@@ -522,6 +525,38 @@ static int jim_newtap_ir_param(Jim_Nvp *n, Jim_GetOptInfo 
*goi,
        return JIM_OK;
 }
 
+static int jim_newtap_md_param(Jim_Nvp *n, Jim_GetOptInfo *goi, struct 
jtag_tap *pTap)
+{
+       jim_wide w;
+       int e = Jim_GetOpt_Wide(goi, &w);
+       if (e != JIM_OK) {
+               Jim_SetResultFormatted(goi->interp,
+                               "option: %s bad parameter", n->name);
+               return e;
+       }
+       switch (n->value) {
+               case NTAP_OPT_INSTANCE_ID:
+                       if (w < 0 || w > 15) {
+                               LOG_ERROR("%s: invalid multidrop instance-id 
%d",
+                                               pTap->dotted_name, (int) w);
+                               return JIM_ERR;
+                       }
+                       pTap->multidrop_targetsel = (pTap->multidrop_targetsel 
& DP_TARGETSEL_DPID_MASK) |
+                                       (w << DP_TARGETSEL_INSTANCEID_SHIFT);
+                       break;
+               case NTAP_OPT_DP_ID:
+                       if (w < 0 || w > DP_TARGETSEL_DPID_MASK) {
+                               LOG_ERROR("%s: invalid multidrop target-id %d",
+                                               pTap->dotted_name, (int) w);
+                       }
+                       pTap->multidrop_targetsel = (pTap->multidrop_targetsel 
& DP_TARGETSEL_INSTANCEID_MASK) | w;
+                       break;
+               default:
+                       return JIM_ERR;
+       }
+       return JIM_OK;
+}
+
 static int jim_newtap_cmd(Jim_GetOptInfo *goi)
 {
        struct jtag_tap *pTap;
@@ -537,6 +572,8 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi)
                { .name = "-disable",       .value = NTAP_OPT_DISABLED },
                { .name = "-expected-id",       .value = NTAP_OPT_EXPECTED_ID },
                { .name = "-ignore-version",       .value = NTAP_OPT_VERSION },
+               { .name = "-dp-id",       .value = NTAP_OPT_DP_ID },
+               { .name = "-instance-id",       .value = NTAP_OPT_INSTANCE_ID },
                { .name = NULL,       .value = -1 },
        };
 
@@ -567,16 +604,13 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi)
        cp = malloc(x);
        sprintf(cp, "%s.%s", pTap->chip, pTap->tapname);
        pTap->dotted_name = cp;
+       pTap->multidrop_targetsel = DP_TARGETSEL_INVALID;
 
        LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
                pTap->chip, pTap->tapname, pTap->dotted_name, goi->argc);
 
-       if (!transport_is_jtag()) {
-               /* SWD doesn't require any JTAG tap parameters */
-               pTap->enabled = true;
-               jtag_tap_init(pTap);
-               return JIM_OK;
-       }
+       bool target_id_specified = false;
+       bool instance_id_specified = false;
 
        /* IEEE specifies that the two LSBs of an IR scan are 01, so make
         * that the default.  The "-ircapture" and "-irmask" options are only
@@ -622,9 +656,30 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi)
                    case NTAP_OPT_VERSION:
                            pTap->ignore_version = true;
                            break;
+                       case NTAP_OPT_DP_ID:
+                               target_id_specified = true;
+                               e = jim_newtap_md_param(n, goi, pTap);
+                               break;
+                       case NTAP_OPT_INSTANCE_ID:
+                               instance_id_specified = true;
+                               e = jim_newtap_md_param(n, goi, pTap);
+                               break;
                }       /* switch (n->value) */
        }       /* while (goi->argc) */
 
+       if (instance_id_specified && !target_id_specified) {
+               LOG_ERROR("%s: If -instance-id is set -dp-id must be 
specified", pTap->dotted_name);
+               free(cp);
+               free(pTap);
+               return JIM_ERR;
+       }
+
+       if (!transport_is_jtag()) {
+               pTap->enabled = true;
+               jtag_tap_init(pTap);
+               return JIM_OK;
+       }
+
        /* default is enabled-after-reset */
        pTap->enabled = !pTap->disabled_after_reset;
 
diff --git a/src/target/arm_adi_v5.h b/src/target/arm_adi_v5.h
index 00e4ea2..16f8359 100644
--- a/src/target/arm_adi_v5.h
+++ b/src/target/arm_adi_v5.h
@@ -93,6 +93,11 @@
 #define DP_APSEL_MAX        (255)
 #define DP_APSEL_INVALID    (-1)
 
+#define DP_TARGETSEL_INVALID 0xFFFFFFFFU
+#define DP_TARGETSEL_DPID_MASK 0x0FFFFFFFU
+#define DP_TARGETSEL_INSTANCEID_MASK 0xF0000000U
+#define DP_TARGETSEL_INSTANCEID_SHIFT 28
+
 
 /* MEM-AP register addresses */
 #define MEM_AP_REG_CSW         0x00

-- 

Reply via email to