From 675349055b2f6f2129ffa1447b904742ae3fdfc2 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 18 Mar 2021 13:47:10 +0100 Subject: [PATCH] inteconnect/stream: Increase io_lcm size when io_lcm/i_dw or io_lcm/o_dw < 2. Allow supporting all cases. --- litex/soc/interconnect/stream.py | 4 ++++ test/test_gearbox.py | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/litex/soc/interconnect/stream.py b/litex/soc/interconnect/stream.py index 5c117e717..e425cb347 100644 --- a/litex/soc/interconnect/stream.py +++ b/litex/soc/interconnect/stream.py @@ -519,6 +519,10 @@ class Gearbox(Module): # # # io_lcm = lcm(i_dw, o_dw) + if (io_lcm//i_dw) < 2: + io_lcm = io_lcm * 2 + if (io_lcm//o_dw) < 2: + io_lcm = io_lcm * 2 # Control path diff --git a/test/test_gearbox.py b/test/test_gearbox.py index 70de10e27..db49f5b48 100644 --- a/test/test_gearbox.py +++ b/test/test_gearbox.py @@ -42,20 +42,29 @@ def data_checker(dut, gearbox, datas): class GearboxDUT(Module): - def __init__(self): - self.submodules.gearbox0 = Gearbox(20, 32) - self.submodules.gearbox1 = Gearbox(32, 20) + def __init__(self, dw0=20, dw1=32): + self.submodules.gearbox0 = Gearbox(dw0, dw1) + self.submodules.gearbox1 = Gearbox(dw1, dw0) self.comb += self.gearbox0.source.connect(self.gearbox1.sink) class TestGearbox(unittest.TestCase): - def test_gearbox(self): + def gearbox_test(self, dw0, dw1): prng = random.Random(42) - dut = GearboxDUT() - datas = [prng.randrange(2**20) for i in range(128)] + dut = GearboxDUT(dw0, dw1) + datas = [prng.randrange(2**dw0) for i in range(128)] generators = [ data_generator(dut, dut.gearbox0, datas), data_checker(dut, dut.gearbox1, datas) ] run_simulation(dut, generators) self.assertEqual(dut.errors, 0) + + def test_gearbox_20_32(self): + self.gearbox_test(20, 32) + + def test_gearbox_10_2(self): + self.gearbox_test(10, 2) + + def test_gearbox_10_4(self): + self.gearbox_test(10, 4)