Commits

wump committed 95ad9ab

random pattern

Comments (0)

Files changed (1)

 """
-Check JTAG connection for stable state.
+Check JTAG connection for stable state by checking for a shifted/delayed pattern.
+
+Usage: jtag_diagnose.py (r|a)
+r  random pattern
+a  alternating 0/1 pattern
 """
 import logging,sys
 from HW.fx2 import FX2
 from support.ByteArray import B,Bhex
+from random import randint
 import time
 
 logging.basicConfig(level=logging.DEBUG,
 dev.ep2out(B([OE]))
 time.sleep(0.1)
 
+# read anything 'stuck'
+try:
+    dev.ep1in(timeout=50)
+except IOError:
+    pass
 """
 while True:
     dev.ep2out(B([OE|READBIT]))
 JTAG_clock(0)
 JTAG_clock(0)
 
+if len(sys.argv) > 1:
+    pattern_type =  sys.argv[1]
+else:
+    pattern_type = 'r' # default to random
+
 x = 0
 errors = 0
-last = 1
+pattern = [0]*32
 while True:
-    if x&1:
+    if pattern_type == 'r': # random
+        outbit = randint(0,1)
+    else: # alternating
+        outbit = x&1 
+    if outbit:
         i = JTAG_clock_srcv(TDI)
     else:
         i = JTAG_clock_srcv(0)
+    
+    if x>33 and i!=pattern[x%32]:
+        errors += 1
+    
+    pattern[x%32] = outbit
+    
+    # Increase and print results
+    x += 1    
     sys.stdout.write(str(i))
-    sys.stdout.flush()
-    if x>33 and i!=(1-last):
-        errors += 1
-    x += 1
+    sys.stdout.flush()    
     if (x%32) == 0:
         sys.stdout.write("%8i\r"% errors)
-    last = i