inteconnect/stream: Increase io_lcm size when io_lcm/i_dw or io_lcm/o_dw < 2.

Allow supporting all cases.
This commit is contained in:
Florent Kermarrec 2021-03-18 13:47:10 +01:00
parent a166a8dba3
commit 675349055b
2 changed files with 19 additions and 6 deletions

View File

@ -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

View File

@ -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)