fix dependency problems caused by pypi
[c4m-jtag.git] / c4m / cocotb / jtag / c4m_jtag.py
index 1dd13b1ee0d1a0c3e47859421735bc27db5dd0a5..ac97ce3e00d8face513e79846ad7198a326fe4d5 100644 (file)
@@ -2,9 +2,11 @@ import cocotb
 from cocotb.triggers import Timer
 from cocotb.binary import BinaryValue
 
+
 class JTAGException(Exception):
     pass
 
+
 class JTAG_Clock(object):
     """
     Class for the JTAG clock, run cycle by cycle
@@ -28,13 +30,14 @@ class JTAG_Clock(object):
             self.signal <= 0
             yield self.t
 
+
 class JTAG_Master(object):
     """
     Class that will run JTAG commands, shift in and out data
     """
     #TODO: Handle a JTAG chain with more than one device
 
-    def __init__(self, tck, tms, tdi, tdo, trst_n=None, clk_period=1000):
+    def __init__(self, tck, tms, tdi, tdo, trst_n=None, clk_period=1000, ir_width=2):
         self.tck = tck
         self.clkgen = JTAG_Clock(tck, clk_period)
         tck <= 0
@@ -49,11 +52,11 @@ class JTAG_Master(object):
         self.period = Timer(clk_period)
 
         # Standard commands
-        # TODO: make IR length configurable; now 2 is assumed
-        self.BYPASS = [1, 1]
-        self.IDCODE = [0, 1]
-        self.SAMPLEPRELOAD = [1, 0]
-        self.EXTEST = [0, 0]
+        # TODO: Make values configurable
+        self.BYPASS = [1 for _ in range(ir_width)]
+        self.IDCODE = [1 if i == ir_width-1 else 0 for i in range(ir_width)]
+        self.SAMPLEPRELOAD = [1 if i == ir_width-2 else 0 for i in range(ir_width)]
+        self.EXTEST = [0 for _ in range(ir_width)]
 
         # After command we always leave the controller in reset or runidle state
         # If value is None we will always reset the interface
@@ -108,7 +111,7 @@ class JTAG_Master(object):
         isreset = False
         if self.state is None:
             yield self.reset()
-        if self.state is "Reset":
+        if self.state == "Reset":
             isreset = True
             self.tms <= 0
             yield self.cycle_clock()
@@ -118,8 +121,11 @@ class JTAG_Master(object):
 
     @cocotb.coroutine
     def load_ir(self, cmd):
-        cmd_copy = list(cmd)
-        result = BinaryValue(bits=len(cmd_copy))
+        if isinstance(cmd, BinaryValue):
+            cmd_copy = [int(c) for c in cmd.binstr]
+        else:
+            cmd_copy = list(cmd)
+        result = BinaryValue(n_bits=len(cmd_copy))
         l_result = list()
 
         yield self.change_to_run()
@@ -146,7 +152,7 @@ class JTAG_Master(object):
         result will contain the 32 bit IDCODE of the device
         """
 
-        result = BinaryValue(bits=32)
+        result = BinaryValue(n_bits=32)
         l_result = list()
 
         # Keep tdi 0 for the whole run