Skip to content

Commit 9838dcc

Browse files
Jean-François Nguyenwhitequark
authored andcommitted
wishbone.bus: fix Decoder case pattern.
Fixes #4.
1 parent 967a65f commit 9838dcc

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

nmigen_soc/test/test_wishbone_bus.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,27 @@ def sim_test():
351351
sim.add_process(sim_test())
352352
sim.run()
353353

354+
def test_coarse_granularity(self):
355+
dut = Decoder(addr_width=3, data_width=32)
356+
sub = Interface(addr_width=2, data_width=32)
357+
sub.memory_map = MemoryMap(addr_width=2, data_width=32)
358+
dut.add(sub)
359+
360+
def sim_test():
361+
yield dut.bus.cyc.eq(1)
362+
363+
yield dut.bus.adr.eq(0x0)
364+
yield Delay(1e-6)
365+
self.assertEqual((yield sub.cyc), 1)
366+
367+
yield dut.bus.adr.eq(0x4)
368+
yield Delay(1e-6)
369+
self.assertEqual((yield sub.cyc), 0)
370+
371+
with Simulator(dut, vcd_file=open("test.vcd", "w")) as sim:
372+
sim.add_process(sim_test())
373+
sim.run()
374+
354375

355376
class ArbiterTestCase(unittest.TestCase):
356377
def setUp(self):

nmigen_soc/wishbone/bus.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ def elaborate(self, platform):
289289
if hasattr(sub_bus, "bte"):
290290
m.d.comb += sub_bus.bte.eq(getattr(self.bus, "bte", BurstTypeExt.LINEAR))
291291

292-
with m.Case(sub_pat[:-log2_int(self.bus.data_width // self.bus.granularity)]):
292+
granularity_bits = log2_int(self.bus.data_width // self.bus.granularity)
293+
with m.Case(sub_pat[:-granularity_bits if granularity_bits > 0 else None]):
293294
m.d.comb += [
294295
sub_bus.cyc.eq(self.bus.cyc),
295296
self.bus.dat_r.eq(sub_bus.dat_r),

0 commit comments

Comments
 (0)