Sometimes I only want to detect the size of one DR without detecting
all possible instructions, which might be too long time when the IR is
long. This patch implements this. Any comments?

Jie
Index: include/urjtag/tap.h
===================================================================
--- include/urjtag/tap.h	(revision 1994)
+++ include/urjtag/tap.h	(working copy)
@@ -52,6 +52,8 @@ int urj_tap_detect_register_size (urj_ch
 /** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error */
 int urj_tap_discovery (urj_chain_t *chain);
 /** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error */
+int urj_tap_discovery_one_dr (urj_chain_t *chain, const char *instruction);
+/** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error */
 int urj_tap_idcode (urj_chain_t *chain, unsigned int bytes);
 /**
  * Convenience function that detects the parts, initialises them to BYPASS,
Index: src/tap/discovery.c
===================================================================
--- src/tap/discovery.c	(revision 1994)
+++ src/tap/discovery.c	(working copy)
@@ -26,10 +26,13 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 
 #include <urjtag/tap.h>
 #include <urjtag/tap_register.h>
 #include <urjtag/chain.h>
+#include <urjtag/part.h>
+#include <urjtag/part_instruction.h>
 
 
 #define DETECT_PATTERN_SIZE     8
@@ -192,3 +195,57 @@ urj_tap_discovery (urj_chain_t *chain)
 
     return URJ_STATUS_OK;
 }
+
+/* Discovery the size of DR for INSTRUCTION */
+int
+urj_tap_discovery_one_dr (urj_chain_t *chain, const char *instruction)
+{
+    int ret, rs;
+    urj_tap_register_t *ir = NULL;
+
+    if (instruction != NULL)
+    {
+        ir = urj_tap_register_alloc (chain->total_instr_len);
+        if (!ir)
+            return URJ_STATUS_FAIL;
+
+        ret = urj_tap_register_set_string (ir, instruction);
+        if (ret != URJ_STATUS_OK)
+        {
+            urj_tap_register_free (ir);
+            return ret;
+        }
+
+        urj_tap_capture_ir (chain);
+        urj_tap_shift_register (chain, ir, NULL, 1);
+
+        urj_log (URJ_LOG_LEVEL_NORMAL, _("Detecting DR length for IR %s ... "),
+                 urj_tap_register_get_string (ir));
+    }
+    else
+    {
+        int i;
+
+        urj_log (URJ_LOG_LEVEL_NORMAL, _("Detecting DR length for the current IR "));
+        for (i = chain->parts->len ; i > 0; i--)
+        {
+            urj_part_instruction_t *inst = chain->parts->parts[i - 1]->active_instruction;
+            if (inst == NULL)
+            {
+                urj_error_set (URJ_ERROR_INVALID, _("no active instruction is selected"));
+                return URJ_STATUS_FAIL;
+            }
+            urj_log (URJ_LOG_LEVEL_NORMAL, "%s", urj_tap_register_get_string (inst->value));
+        }
+        urj_log (URJ_LOG_LEVEL_NORMAL, " ... ");
+    }
+
+    fflush (stdout);
+    urj_tap_capture_dr (chain);
+    rs = urj_tap_detect_register_size (chain);
+
+    urj_log (URJ_LOG_LEVEL_NORMAL, _("%d\n"), rs);
+
+    urj_tap_register_free (ir);
+    return URJ_STATUS_OK;
+}
Index: src/cmd/cmd_discovery.c
===================================================================
--- src/cmd/cmd_discovery.c	(revision 1994)
+++ src/cmd/cmd_discovery.c	(working copy)
@@ -36,26 +36,41 @@
 static int
 cmd_discovery_run (urj_chain_t *chain, char *params[])
 {
-    if (urj_cmd_params (params) != 1)
-    {
-        urj_error_set (URJ_ERROR_SYNTAX,
-                       "%s: #parameters should be %d, not %d",
-                       params[0], 1, urj_cmd_params (params));
-        return URJ_STATUS_FAIL;
-    }
+    int ret;
 
     if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
         return URJ_STATUS_FAIL;
 
-    return urj_tap_discovery (chain);
+    switch (urj_cmd_params (params))
+    {
+    case 1:
+        ret = urj_tap_discovery (chain);
+        break;
+
+    case 2:
+        if (strcmp (params[1], "current") == 0)
+            ret = urj_tap_discovery_one_dr (chain, NULL);
+        else
+            ret = urj_tap_discovery_one_dr (chain, params[1]);
+        break;
+
+    default:
+        urj_error_set (URJ_ERROR_SYNTAX,
+                       "%s: #parameters should be 1 or 2, not %d",
+                       params[0], urj_cmd_params (params));
+        ret = URJ_STATUS_FAIL;
+        break;
+    }
+
+    return ret;
 }
 
 static void
 cmd_discovery_help (void)
 {
     urj_log (URJ_LOG_LEVEL_NORMAL,
-             _("Usage: %s\n"
-               "Discovery of unknown parts in the JTAG chain.\n"
+             _("Usage: %s [current|INSTRUCTION]\n"
+               "When no arguments, discovery of unknown parts in the JTAG chain.\n"
                "\n"
                "'%s' attempts to detect these parameters of an unknown JTAG\n"
                "chain:\n"
@@ -63,7 +78,10 @@ cmd_discovery_help (void)
                " 2. DR (data register) length for all possible instructions\n"
                "\n"
                "Warning: This may be dangerous for some parts (especially if the\n"
-               "part doesn't have TRST signal).\n"), "discovery",
+               "part doesn't have TRST signal).\n"
+               "\n"
+               "When there is an argument, discovery of the DR size of the current or\n"
+               "specified instruction.\n"), "discovery",
             "discovery");
 }
 
------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
UrJTAG-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/urjtag-development

Reply via email to