Commits

wump committed 9026b9b

add diagnose utility

  • Participants
  • Parent commits dedb8e8

Comments (0)

Files changed (1)

+"""
+Check JTAG connection for stable state.
+"""
+import logging,sys
+from HW.fx2 import FX2
+from support.ByteArray import B,Bhex
+import time
+
+logging.basicConfig(level=logging.DEBUG,
+            datefmt='%a, %d %b %Y %H:%M:%S',
+            format='%(asctime)s %(levelname)-8s %(name)-8s %(message)s',
+            stream=sys.stdout)
+
+logger = logging.getLogger("test")
+
+dev = FX2(0)
+
+def read_data(dev, n):
+    recv = B([])
+    while len(recv)<n:
+        data = dev.ep1in()
+        recv += B(data)
+    return recv
+
+# USB blaster command bits
+BYTEMODE = 0x80
+READBIT  = 0x40
+OE       = 0x20
+TDI      = 0x10
+NCS      = 0x08
+NCE      = 0x04
+TMS      = 0x02
+TCK      = 0x01
+
+# JTAG test
+# Endpoints: EP1IN (0x81) EP2OUT (0x02)
+#while True:
+
+print "Resetting TAP controller"
+dev.ep2out(B([0x00]))
+time.sleep(0.1)
+
+dev.ep2out(B([OE]))
+dev.ep2out(B([OE]))
+time.sleep(0.1)
+
+"""
+while True:
+    dev.ep2out(B([OE|READBIT]))
+    print read_data(dev,1)[0]&1
+"""
+"""
+time.sleep(1.0)
+dev.ep2out(B([OE|TCK]))
+time.sleep(0.5)
+dev.ep2out(B([OE|TMS]))
+time.sleep(0.5)
+dev.ep2out(B([OE|TDI]))
+
+time.sleep(1.0)
+dev.ep2out(B([OE]))
+
+exit(1)
+"""
+def JTAG_clock(x):
+    """
+    Send JTAG data and assert clock.
+    """
+    dev.ep2out(B([OE|x]))
+    dev.ep2out(B([OE|x|TCK]))
+
+def JTAG_clock_srcv(x):
+    """
+    Send and receive JTAG data and assert clock.
+    """
+    dev.ep2out(B([OE|x]))
+    dev.ep2out(B([OE|x|TCK|READBIT]))
+    d = read_data(dev, 1)
+    #print "in:", x, "out:",d[0]&1
+    return d[0]&1
+
+JTAG_clock = JTAG_clock_srcv
+
+print "Reset TMS"
+for x in xrange(5):
+    JTAG_clock(TMS)
+
+print "Go to Shift-DR"
+JTAG_clock(0)
+JTAG_clock(TMS)
+JTAG_clock(0)
+JTAG_clock(0)
+
+x = 0
+errors = 0
+last = 1
+while True:
+    if x&1:
+        i = JTAG_clock_srcv(TDI)
+    else:
+        i = JTAG_clock_srcv(0)
+    sys.stdout.write(str(i))
+    sys.stdout.flush()
+    if x>33 and i!=(1-last):
+        errors += 1
+    x += 1
+    if (x%32) == 0:
+        sys.stdout.write("%8i\r"% errors)
+    last = i
+