I'm in a situation where I'm doing a detect operation many times,
to determine the conditions under which a balky interface and chain
actually work. This can take a long time, especialy with slow
cables, or cables with their clock rate reduced.
urj_tap_detect_register_size() uses a constant,
#define MAX_REGISTER_LENGTH 1024
as the maximum possible total length of the current register (data or
instruction).
The attached patch adds an argument to urj_tap_detect_register_size(),
and arranges for urj_tap_detect() to accept an argument to override the
maximum register length used for determining the instruction register
length.
I'm using this from python, and it can reduce the time for detect on a
broken chain from over a minute to well under a second, depending on chain
length and frequency.
Might anyone find this useful from the text interface? If so, an optional
argument could be added "detect" by tweaking cmd_detect.c.
From the patch:
Setting a value just larger than the max total instruction register length
makes detect return failure much faster if the chain is broken.
Setting a larger value than the old default 1024 would be needed for long
chains of complex parts.
---
urjtag/include/urjtag/tap.h | 8 +++++---
urjtag/src/cmd/cmd_detect.c | 2 +-
urjtag/src/tap/detect.c | 10 +++++-----
urjtag/src/tap/discovery.c | 14 +++++++++-----
4 files changed, 20 insertions(+), 14 deletions(-)
From 3b2e5b747a02bbb9a6b618383a9ccc7b161c3e42 Mon Sep 17 00:00:00 2001
From: Steve Tell <[email protected]>
Date: Wed, 10 Aug 2011 23:54:43 -0400
Subject: [PATCH] Allow MAX_REGISTER_LENGTH used for "detect" to be overidden at
runtime.
Setting a value just larger than the max total instruction register length
makes detect return failure much faster if the chain is broken.
Setting a larger value than the old default 1024 would be needed for long
chains of complex parts.
---
urjtag/include/urjtag/tap.h | 8 +++++---
urjtag/src/cmd/cmd_detect.c | 2 +-
urjtag/src/tap/detect.c | 10 +++++-----
urjtag/src/tap/discovery.c | 14 +++++++++-----
4 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/urjtag/include/urjtag/tap.h b/urjtag/include/urjtag/tap.h
index 0957e1d..6fd7e89 100644
--- a/urjtag/include/urjtag/tap.h
+++ b/urjtag/include/urjtag/tap.h
@@ -44,11 +44,11 @@ void urj_tap_shift_register (urj_chain_t *chain,
/** API functions */
/** @return number of detected parts on success; -1 on error */
-int urj_tap_detect_parts (urj_chain_t *chain, const char *db_path);
+int urj_tap_detect_parts (urj_chain_t *chain, const char *db_path, int
maxirlen);
/** @return chain length on success; -1 on error */
int urj_tap_manual_add (urj_chain_t *chain, int instr_len);
/** @return register size on success; -1 on error */
-int urj_tap_detect_register_size (urj_chain_t *chain);
+int urj_tap_detect_register_size (urj_chain_t *chain, int maxlen);
/** @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 */
@@ -56,9 +56,11 @@ int urj_tap_idcode (urj_chain_t *chain, unsigned int bytes);
/**
* Convenience function that detects the parts, initialises them to BYPASS,
* and initialises the bus drivers.
+ * maxirlen is the maximum expected length of all concatenated instruction
+ * registers on the chain. If set to 0, a default is assumed.
*
* @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error
*/
-int urj_tap_detect (urj_chain_t *chain);
+int urj_tap_detect (urj_chain_t *chain, int maxirlen);
#endif /* URJ_TAP_H */
diff --git a/urjtag/src/cmd/cmd_detect.c b/urjtag/src/cmd/cmd_detect.c
index 7b5ddc3..3c56995 100644
--- a/urjtag/src/cmd/cmd_detect.c
+++ b/urjtag/src/cmd/cmd_detect.c
@@ -49,7 +49,7 @@ cmd_detect_run (urj_chain_t *chain, char *params[])
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
- if (urj_tap_detect (chain) != URJ_STATUS_OK)
+ if (urj_tap_detect (chain, 0) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
return URJ_STATUS_OK;
diff --git a/urjtag/src/tap/detect.c b/urjtag/src/tap/detect.c
index 7eebb7c..625cb0b 100644
--- a/urjtag/src/tap/detect.c
+++ b/urjtag/src/tap/detect.c
@@ -175,7 +175,7 @@ find_record (char *filename, urj_tap_register_t *key,
struct id_record *idr)
#define strncat_const(dst, src) strncat(dst, src, sizeof(dst) - strlen(dst) -
1)
int
-urj_tap_detect_parts (urj_chain_t *chain, const char *db_path)
+urj_tap_detect_parts (urj_chain_t *chain, const char *db_path, int maxirlen)
{
int irlen;
urj_tap_register_t *ir;
@@ -197,7 +197,7 @@ urj_tap_detect_parts (urj_chain_t *chain, const char
*db_path)
/* Detect IR length */
urj_tap_reset (chain);
urj_tap_capture_ir (chain);
- irlen = urj_tap_detect_register_size (chain);
+ irlen = urj_tap_detect_register_size (chain, maxirlen);
if (irlen < 1)
// retain error state
return -1;
@@ -215,7 +215,7 @@ urj_tap_detect_parts (urj_chain_t *chain, const char
*db_path)
/* Detect chain length */
urj_tap_capture_dr (chain);
- chlen = urj_tap_detect_register_size (chain);
+ chlen = urj_tap_detect_register_size (chain, 0);
if (chlen < 1)
{
// retain error state
@@ -540,7 +540,7 @@ urj_tap_manual_add (urj_chain_t *chain, int instr_len)
}
int
-urj_tap_detect (urj_chain_t *chain)
+urj_tap_detect (urj_chain_t *chain, int maxirlen)
{
int i;
urj_bus_t *abus;
@@ -548,7 +548,7 @@ urj_tap_detect (urj_chain_t *chain)
urj_bus_buses_free ();
urj_part_parts_free (chain->parts);
chain->parts = NULL;
- if (urj_tap_detect_parts (chain, urj_get_data_dir ()) == -1)
+ if (urj_tap_detect_parts (chain, urj_get_data_dir (), maxirlen) == -1)
// retain error state
return URJ_STATUS_FAIL;
if (!chain->parts)
diff --git a/urjtag/src/tap/discovery.c b/urjtag/src/tap/discovery.c
index a0479c6..92149cf 100644
--- a/urjtag/src/tap/discovery.c
+++ b/urjtag/src/tap/discovery.c
@@ -33,24 +33,28 @@
#define DETECT_PATTERN_SIZE 8
-#define MAX_REGISTER_LENGTH 1024
+#define MIN_REGISTER_LENGTH 2 /* anything less is silly */
+#define DEFAULT_MAX_REGISTER_LENGTH 1024
#define TEST_COUNT 1
#define TEST_THRESHOLD 100 /* in % */
#undef VERY_LOW_LEVEL_DEBUG
int
-urj_tap_detect_register_size (urj_chain_t *chain)
+urj_tap_detect_register_size (urj_chain_t *chain, int maxlen)
{
int len;
urj_tap_register_t *rz;
urj_tap_register_t *rout;
urj_tap_register_t *rpat;
+ if(maxlen < MIN_REGISTER_LENGTH)
+ maxlen = DEFAULT_MAX_REGISTER_LENGTH;
+
/* This seems to be a good place to check if TDO changes at all */
int tdo, tdo_stuck = -2;
- for (len = 1; len <= MAX_REGISTER_LENGTH; len++)
+ for (len = 1; len <= maxlen; len++)
{
int p;
int ok = 0;
@@ -143,7 +147,7 @@ urj_tap_discovery (urj_chain_t *chain)
fflush (stdout);
urj_tap_capture_ir (chain);
- irlen = urj_tap_detect_register_size (chain);
+ irlen = urj_tap_detect_register_size (chain, 0);
urj_log (URJ_LOG_LEVEL_NORMAL, _("%d\n"), irlen);
@@ -179,7 +183,7 @@ urj_tap_discovery (urj_chain_t *chain)
fflush (stdout);
urj_tap_capture_dr (chain);
- rs = urj_tap_detect_register_size (chain);
+ rs = urj_tap_detect_register_size (chain, 0);
urj_log (URJ_LOG_LEVEL_NORMAL, _("%d\n"), rs);
--
1.7.4
------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
user administration capabilities and model configuration. Take
the hassle out of deploying and managing Subversion and the
tools developers use with it.
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
UrJTAG-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/urjtag-development