From d813046609bc119995680f8ee35d9ad4744ccf34 Mon Sep 17 00:00:00 2001 From: Staf Verhaegen Date: Fri, 2 Apr 2021 19:11:04 +0200 Subject: [PATCH] Add helper class JTAGPin This will now group code for operation on pins. --- ls180/pre_pnr/test.py | 106 ++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/ls180/pre_pnr/test.py b/ls180/pre_pnr/test.py index f61bce6..9712a86 100644 --- a/ls180/pre_pnr/test.py +++ b/ls180/pre_pnr/test.py @@ -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() -- 2.30.2