Skip to content

Commit 280890c

Browse files
committed
[WIP]wishbone.Connector class
Implementation of a module that allows to connect one initiator to one subordinate.bus. Currently connecting initiator bus with data width greater than the subordinate bus is not implemented. Implementation of that feature will need to instantiate multiple subordinate bus cycles for one initiator bus cycle.
1 parent 517638c commit 280890c

File tree

2 files changed

+398
-1
lines changed

2 files changed

+398
-1
lines changed

nmigen_soc/test/test_wishbone_bus.py

+255
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,261 @@ def test_set_map_wrong_addr_width(self):
123123
iface.memory_map = MemoryMap(addr_width=30, data_width=8)
124124

125125

126+
class ConnectorTestCase(unittest.TestCase):
127+
def test_wrong_intr(self):
128+
sub_bus = Interface(addr_width=10, data_width=8)
129+
with self.assertRaisesRegexp(TypeError,
130+
r"Initiator bus must be an instance of wishbone.Interface, not 'foo'"):
131+
Connector(intr_bus="foo", sub_bus=sub_bus)
132+
133+
def test_wrong_sub(self):
134+
intr_bus = Interface(addr_width=10, data_width=8)
135+
with self.assertRaisesRegexp(TypeError,
136+
r"Subordinate bus must be an instance of wishbone.Interface, not 'foo'"):
137+
Connector(intr_bus=intr_bus, sub_bus="foo")
138+
139+
def test_wrong_bitsize(self):
140+
intr_bus = Interface(addr_width=10, data_width=32)
141+
sub_bus = Interface(addr_width=10, data_width=8)
142+
with self.assertRaisesRegexp(ValueError,
143+
r"Total bit size of initiator and subordinate bus have to be the same"):
144+
Connector(intr_bus=intr_bus, sub_bus=sub_bus)
145+
146+
def test_wrong_granularity(self):
147+
intr_bus = Interface(addr_width=12, data_width=8)
148+
sub_bus = Interface(addr_width=10, data_width=32)
149+
with self.assertRaisesRegexp(ValueError,
150+
r"Granularity of subordinate bus has to be smaller or equal to "
151+
r"granulariy of initiator bus"):
152+
Connector(intr_bus=intr_bus, sub_bus=sub_bus)
153+
154+
def test_lock_mismatch(self):
155+
intr_bus = Interface(addr_width=10, data_width=8, features={"lock"})
156+
sub_bus = Interface(addr_width=10, data_width=8)
157+
with self.assertRaisesRegexp(ValueError,
158+
r"Initiator bus has optional output 'lock', but the suborbdinate bus "
159+
r"does not have a corresponding input"):
160+
Connector(intr_bus=intr_bus, sub_bus=sub_bus)
161+
162+
def test_err_mismatch(self):
163+
intr_bus = Interface(addr_width=10, data_width=8)
164+
sub_bus = Interface(addr_width=10, data_width=8, features={"err"})
165+
with self.assertRaisesRegexp(ValueError,
166+
r"Subordinate bus has optional output 'err', but the initiator bus "
167+
r"does not have a corresponding input"):
168+
Connector(intr_bus=intr_bus, sub_bus=sub_bus)
169+
170+
def test_rty_mismatch(self):
171+
intr_bus = Interface(addr_width=10, data_width=8)
172+
sub_bus = Interface(addr_width=10, data_width=8, features={"rty"})
173+
with self.assertRaisesRegexp(ValueError,
174+
r"Subordinate bus has optional output 'rty', but the initiator bus "
175+
r"does not have a corresponding input"):
176+
Connector(intr_bus=intr_bus, sub_bus=sub_bus)
177+
178+
def test_not_implemented_multicycle(self):
179+
intr_bus = Interface(addr_width=10, data_width=32)
180+
sub_bus = Interface(addr_width=12, data_width=8)
181+
with self.assertRaisesRegexp(NotImplementedError,
182+
r"Support for multi-cycle bus operation when initiator data_width is"
183+
r"bigger than the subordinate one is not implemented."):
184+
Connector(intr_bus=intr_bus, sub_bus=sub_bus)
185+
186+
187+
class ConnectorSimulationTestCase(unittest.TestCase):
188+
def test_same(self):
189+
intr_bus = Interface(addr_width=10, data_width=32, granularity=8)
190+
sub_bus = Interface(addr_width=10, data_width=32, granularity=8)
191+
dut = Connector(intr_bus=intr_bus, sub_bus=sub_bus)
192+
193+
def sim_test():
194+
yield intr_bus.adr.eq(1)
195+
yield intr_bus.we.eq(0)
196+
yield intr_bus.cyc.eq(1)
197+
yield intr_bus.stb.eq(1)
198+
yield intr_bus.sel.eq(5)
199+
yield Delay(1e-6)
200+
self.assertEqual((yield sub_bus.adr), 1)
201+
self.assertEqual((yield sub_bus.we), 0)
202+
self.assertEqual((yield sub_bus.cyc), 1)
203+
self.assertEqual((yield sub_bus.stb), 1)
204+
self.assertEqual((yield sub_bus.sel), 5)
205+
yield sub_bus.ack.eq(1)
206+
yield Delay(1e-6)
207+
self.assertEqual((yield intr_bus.ack), 1)
208+
yield intr_bus.adr.eq(127)
209+
yield intr_bus.we.eq(1)
210+
yield intr_bus.cyc.eq(1)
211+
yield intr_bus.stb.eq(0)
212+
yield intr_bus.sel.eq(10)
213+
yield Delay(1e-6)
214+
self.assertEqual((yield sub_bus.adr), 127)
215+
self.assertEqual((yield sub_bus.we), 1)
216+
self.assertEqual((yield sub_bus.cyc), 1)
217+
self.assertEqual((yield sub_bus.stb), 0)
218+
self.assertEqual((yield sub_bus.sel), 10)
219+
220+
with Simulator(dut, vcd_file=open("test.vcd", "w")) as sim:
221+
sim.add_process(sim_test())
222+
sim.run()
223+
224+
def test_same_pipelined(self):
225+
intr_bus = Interface(addr_width=10, data_width=8, features={"stall"})
226+
sub_bus = Interface(addr_width=10, data_width=8, features={"stall"})
227+
dut = Connector(intr_bus=intr_bus, sub_bus=sub_bus)
228+
229+
def sim_test():
230+
yield intr_bus.adr.eq(1)
231+
yield intr_bus.we.eq(0)
232+
yield intr_bus.cyc.eq(1)
233+
yield intr_bus.stb.eq(1)
234+
yield intr_bus.sel.eq(1)
235+
yield sub_bus.stall.eq(1)
236+
yield Delay(1e-6)
237+
self.assertEqual((yield sub_bus.adr), 1)
238+
self.assertEqual((yield sub_bus.we), 0)
239+
self.assertEqual((yield sub_bus.cyc), 1)
240+
self.assertEqual((yield sub_bus.stb), 1)
241+
self.assertEqual((yield sub_bus.sel), 1)
242+
self.assertEqual((yield intr_bus.stall), 1)
243+
yield sub_bus.stall.eq(0)
244+
yield Delay(1e-6)
245+
self.assertEqual((yield intr_bus.stall), 0)
246+
yield sub_bus.ack.eq(1)
247+
yield Delay(1e-6)
248+
self.assertEqual((yield intr_bus.ack), 1)
249+
250+
with Simulator(dut, vcd_file=open("test.vcd", "w")) as sim:
251+
sim.add_process(sim_test())
252+
sim.run()
253+
254+
def test_default(self):
255+
intr_bus = Interface(addr_width=10, data_width=8, features={"err", "rty"})
256+
sub_bus = Interface(addr_width=10, data_width=8, features={"lock", "cti", "bte"})
257+
dut = Connector(intr_bus=intr_bus, sub_bus=sub_bus)
258+
259+
def sim_test():
260+
yield Delay(1e-6)
261+
self.assertEqual((yield intr_bus.err), 0)
262+
self.assertEqual((yield intr_bus.rty), 0)
263+
self.assertEqual((yield sub_bus.lock), 0)
264+
self.assertEqual((yield sub_bus.cti), CycleType.CLASSIC.value)
265+
self.assertEqual((yield sub_bus.bte), BurstTypeExt.LINEAR.value)
266+
267+
with Simulator(dut, vcd_file=open("test.vcd", "w")) as sim:
268+
sim.add_process(sim_test())
269+
sim.run()
270+
271+
def test_conv_granularity(self):
272+
intr_bus = Interface(addr_width=10, data_width=32)
273+
sub_bus = Interface(addr_width=10, data_width=32, granularity=8)
274+
dut = Connector(intr_bus=intr_bus, sub_bus=sub_bus)
275+
276+
def sim_test():
277+
yield intr_bus.sel.eq(1)
278+
yield Delay(1e-6)
279+
self.assertEqual((yield sub_bus.sel), 0b1111)
280+
yield intr_bus.sel.eq(0)
281+
yield Delay(1e-6)
282+
self.assertEqual((yield sub_bus.sel), 0b0000)
283+
284+
with Simulator(dut, vcd_file=open("test.vcd", "w")) as sim:
285+
sim.add_process(sim_test())
286+
sim.run()
287+
288+
def test_conv_addr_width(self):
289+
intr_bus = Interface(addr_width=12, data_width=8)
290+
sub_bus = Interface(addr_width=10, data_width=32, granularity=8)
291+
dut = Connector(intr_bus=intr_bus, sub_bus=sub_bus)
292+
293+
def sim_test():
294+
yield intr_bus.adr.eq(1)
295+
yield intr_bus.sel.eq(1)
296+
yield intr_bus.dat_w.eq(0xA5)
297+
yield sub_bus.dat_r.eq(0x03020100)
298+
yield Delay(1e-6)
299+
self.assertEqual((yield sub_bus.sel), 0b0010)
300+
self.assertEqual((yield sub_bus.dat_w), 0xA5A5A5A5)
301+
self.assertEqual((yield intr_bus.dat_r), 0x01)
302+
303+
with Simulator(dut, vcd_file=open("test.vcd", "w")) as sim:
304+
sim.add_process(sim_test())
305+
sim.run()
306+
307+
def test_conv_granularity_addr_width(self):
308+
intr_bus = Interface(addr_width=11, data_width=16)
309+
sub_bus = Interface(addr_width=10, data_width=32, granularity=8)
310+
dut = Connector(intr_bus=intr_bus, sub_bus=sub_bus)
311+
312+
def sim_test():
313+
yield intr_bus.adr.eq(3)
314+
yield intr_bus.sel.eq(1)
315+
yield intr_bus.dat_w.eq(0xA55A)
316+
yield sub_bus.dat_r.eq(0x03020100)
317+
yield Delay(1e-6)
318+
self.assertEqual((yield sub_bus.sel), 0b1100)
319+
self.assertEqual((yield sub_bus.dat_w), 0xA55AA55A)
320+
self.assertEqual((yield intr_bus.dat_r), 0x0302)
321+
322+
with Simulator(dut, vcd_file=open("test.vcd", "w")) as sim:
323+
sim.add_process(sim_test())
324+
sim.run()
325+
326+
def test_pipelined_initiator(self):
327+
intr_bus = Interface(addr_width=10, data_width=8, features={"stall"})
328+
sub_bus = Interface(addr_width=10, data_width=8)
329+
dut = Connector(intr_bus=intr_bus, sub_bus=sub_bus)
330+
331+
def sim_test():
332+
yield intr_bus.adr.eq(1)
333+
yield intr_bus.sel.eq(1)
334+
yield intr_bus.cyc.eq(1)
335+
yield intr_bus.stb.eq(1)
336+
yield Delay(1e-7)
337+
self.assertEqual((yield sub_bus.cyc), 1)
338+
self.assertEqual((yield sub_bus.stb), 1)
339+
self.assertEqual((yield intr_bus.ack), 0)
340+
self.assertEqual((yield intr_bus.stall), 1)
341+
yield Delay(1e-7)
342+
yield sub_bus.ack.eq(1)
343+
yield Delay(1e-7)
344+
self.assertEqual((yield intr_bus.stall), 0)
345+
346+
with Simulator(dut, vcd_file=open("test.vcd", "w")) as sim:
347+
sim.add_process(sim_test())
348+
sim.run()
349+
350+
def test_pipelined_subordinate(self):
351+
intr_bus = Interface(addr_width=10, data_width=8)
352+
sub_bus = Interface(addr_width=10, data_width=8, features={"stall"})
353+
dut = Connector(intr_bus=intr_bus, sub_bus=sub_bus)
354+
355+
def sim_test():
356+
yield intr_bus.adr.eq(1)
357+
yield intr_bus.sel.eq(1)
358+
yield intr_bus.cyc.eq(1)
359+
yield intr_bus.stb.eq(1)
360+
yield Delay(1e-8)
361+
self.assertEqual((yield sub_bus.cyc), 1)
362+
self.assertEqual((yield sub_bus.stb), 1)
363+
self.assertEqual((yield intr_bus.ack), 0)
364+
yield
365+
yield sub_bus.ack.eq(1)
366+
yield Delay(1e-8)
367+
self.assertEqual((yield intr_bus.ack), 1)
368+
yield intr_bus.stb.eq(0)
369+
yield
370+
self.assertEqual((yield intr_bus.ack), 1)
371+
yield sub_bus.ack.eq(0)
372+
yield
373+
self.assertEqual((yield intr_bus.ack), 0)
374+
375+
with Simulator(dut, vcd_file=open("test_debug.vcd", "w")) as sim:
376+
sim.add_clock(1e-6)
377+
sim.add_sync_process(sim_test())
378+
sim.run()
379+
380+
126381
class DecoderTestCase(unittest.TestCase):
127382
def setUp(self):
128383
self.dut = Decoder(addr_width=31, data_width=32, granularity=16)

0 commit comments

Comments
 (0)