Add helper class JTAGPin
authorStaf Verhaegen <staf@stafverhaegen.be>
Fri, 2 Apr 2021 17:11:04 +0000 (19:11 +0200)
committerStaf Verhaegen <staf@stafverhaegen.be>
Fri, 2 Apr 2021 17:11:04 +0000 (19:11 +0200)
This will now group code for operation on pins.

ls180/pre_pnr/test.py

index f61bce686c5fbbe3d268e223615688983821dc6c..9712a864ffab3338dfae3981f28d7d205ddaaa29 100644 (file)
@@ -17,6 +17,57 @@ from soc.debug.jtag import Pins
 # Helper functions
 #
 
+class JTAGPin:
+    def __init__(self, pin):
+        self.type_ = pin[2]
+        self.name = pin[3]
+
+    def log(self, dut):
+        if self.type_ == IOType.In:
+            core_i = getattr(dut.test_issuer, f"{self.name}__core__i").value
+            pad_i = getattr(dut.test_issuer, f"{self.name}__pad__i").value
+            dut._log.info(f"{self.name}: core.i={core_i}, pad.i={pad_i}")
+        elif self.type_ == IOType.Out:
+            core_o = getattr(dut.test_issuer, f"{self.name}__core__o").value
+            pad_o = getattr(dut.test_issuer, f"{self.name}__pad__o").value
+            dut._log.info(f"{self.name}: core.o={core_o}, pad.o={pad_o}")
+        elif self.type_ == IOType.TriOut:
+            core_o = getattr(dut.test_issuer, f"{self.name}__core__o").value
+            core_oe = getattr(dut.test_issuer, f"{self.name}__core__oe").value
+            pad_o = getattr(dut.test_issuer, f"{self.name}__pad__o").value
+            pad_oe = getattr(dut.test_issuer, f"{self.name}__pad__oe").value
+            dut._log.info(f"{self.name}: core.(o={core_o}, oe={core_oe}), pad.(o={pad_o}, oe={pad_oe})")
+        elif self.type_ == IOType.InTriOut:
+            core_i = getattr(dut.test_issuer, f"{self.name}__core__i").value
+            core_o = getattr(dut.test_issuer, f"{self.name}__core__o").value
+            core_oe = getattr(dut.test_issuer, f"{self.name}__core__oe").value
+            pad_i = getattr(dut.test_issuer, f"{self.name}__pad__i").value
+            pad_o = getattr(dut.test_issuer, f"{self.name}__pad__o").value
+            pad_oe = getattr(dut.test_issuer, f"{self.name}__pad__oe").value
+            dut._log.info(f"{self.name}: core.(i={core_i}, o={core_o}, oe={core_oe}), pad.(t={core_i}, o={pad_o}, oe={pad_oe})")
+        else:
+            raise ValueError(f"Unsupported pin type {self.type_}")
+
+    def check(self, dut, val):
+        if self.type_ == IOType.In:
+            assert getattr(dut.test_issuer, f"{self.name}__core__i").value == val
+        elif self.type_ == IOType.Out:
+            assert getattr(dut.test_issuer, f"{self.name}__pad__o").value == val
+        elif self.type_ == IOType.TriOut:
+            assert getattr(dut.test_issuer, f"{self.name}__core__o").value == val
+            assert getattr(dut.test_issuer, f"{self.name}__core__oe").value == 1
+        elif self.type_ == IOType.InTriOut:
+            assert getattr(dut.test_issuer, f"{self.name}__core__i").value == val
+            assert getattr(dut.test_issuer, f"{self.name}__pad__o").value == val
+            assert getattr(dut.test_issuer, f"{self.name}__pad__oe").value == val
+        else:
+            raise ValueError(f"Unsupported pin type {self.type_}")
+
+def log_pins(dut, pins):
+    for pin in pins:
+        pin.log(dut)
+
+
 def get_jtag_boundary():
     """gets the list of information for jtag boundary scan
     """
@@ -27,56 +78,9 @@ def get_jtag_boundary():
               # 'mspi1', - disabled for now
               # 'pwm', 'sd0', - disabled for now
                'sdr']
-    pins = Pins(get_pinspecs(subset=subset))
+    pins = tuple(JTAGPin(pin) for pin in Pins(get_pinspecs(subset=subset)))
     return pins
 
-def log_pin(dut, pin):
-    _, _, type_, name, _ = pin
-    if type_ == IOType.In:
-        core_i = getattr(dut.test_issuer, f"{name}__core__i").value
-        pad_i = getattr(dut.test_issuer, f"{name}__pad__i").value
-        dut._log.info(f"{name}: core.i={core_i}, pad.i={pad_i}")
-    elif type_ == IOType.Out:
-        core_o = getattr(dut.test_issuer, f"{name}__core__o").value
-        pad_o = getattr(dut.test_issuer, f"{name}__pad__o").value
-        dut._log.info(f"{name}: core.o={core_o}, pad.o={pad_o}")
-    elif type_ == IOType.TriOut:
-        core_o = getattr(dut.test_issuer, f"{name}__core__o").value
-        core_oe = getattr(dut.test_issuer, f"{name}__core__oe").value
-        pad_o = getattr(dut.test_issuer, f"{name}__pad__o").value
-        pad_oe = getattr(dut.test_issuer, f"{name}__pad__oe").value
-        dut._log.info(f"{name}: core.(o={core_o}, oe={core_oe}), pad.(o={pad_o}, oe={pad_oe})")
-    elif type_ == IOType.InTriOut:
-        core_i = getattr(dut.test_issuer, f"{name}__core__i").value
-        core_o = getattr(dut.test_issuer, f"{name}__core__o").value
-        core_oe = getattr(dut.test_issuer, f"{name}__core__oe").value
-        pad_i = getattr(dut.test_issuer, f"{name}__pad__i").value
-        pad_o = getattr(dut.test_issuer, f"{name}__pad__o").value
-        pad_oe = getattr(dut.test_issuer, f"{name}__pad__oe").value
-        dut._log.info(f"{name}: core.(i={core_i}, o={core_o}, oe={core_oe}), pad.(t={core_i}, o={pad_o}, oe={pad_oe})")
-    else:
-        raise ValueError(f"Unsupported pin type {type_}")
-
-def log_pins(dut, pins):
-    for pin in get_jtag_boundary():
-        log_pin(dut, pin)
-
-def check_pin(dut, pin, val):
-    _, _, type_, name, _ = pin
-    if type_ == IOType.In:
-        assert getattr(dut.test_issuer, f"{name}__core__i").value == val
-    elif type_ == IOType.Out:
-        assert getattr(dut.test_issuer, f"{name}__pad__o").value == val
-    elif type_ == IOType.TriOut:
-        assert getattr(dut.test_issuer, f"{name}__core__o").value == val
-        assert getattr(dut.test_issuer, f"{name}__core__oe").value == 1
-    elif type_ == IOType.InTriOut:
-        assert getattr(dut.test_issuer, f"{name}__core__i").value == val
-        assert getattr(dut.test_issuer, f"{name}__pad__o").value == val
-        assert getattr(dut.test_issuer, f"{name}__pad__oe").value == val
-    else:
-        raise ValueError(f"Unsupported pin type {type_}")
-
 
 def setup_sim(dut, *, clk_period, run):
     """Initialize CPU and setup clock"""
@@ -189,7 +193,7 @@ def idcodesvf_run(dut):
 #
 
 def boundary_scan(dut, *, jtag):
-    pins = tuple(get_jtag_boundary())
+    pins = get_jtag_boundary()
 
     yield jtag.reset()
 
@@ -201,13 +205,13 @@ def boundary_scan(dut, *, jtag):
 
     dut._log.info("After scan")
     log_pins(dut, pins)
-    check_pin(dut, pins[0], 1)
+    pins[0].check(dut, 1)
 
     yield jtag.reset()
 
     dut._log.info("After reset")
     log_pins(dut, pins)
-    check_pin(dut, pins[0], 0)
+    pins[0].check(dut, 0)
 
 
 @cocotb.test()