Super basic first try of testmem with load store unit interface
authorMichael Nolan <mtnolan2640@gmail.com>
Wed, 24 Jun 2020 16:59:40 +0000 (12:59 -0400)
committerMichael Nolan <mtnolan2640@gmail.com>
Wed, 24 Jun 2020 17:09:34 +0000 (13:09 -0400)
src/soc/experiment/lsmem.py
src/soc/minerva/units/loadstore.py

index 4594be89e52415b878384a09fc91b4fcdc02cd68..2760a55ca63dac7f044f66119cc7661b4ad933fc 100644 (file)
@@ -1,2 +1,65 @@
 from soc.minerva.units.loadstore import LoadStoreUnitInterface
-from nmigen import Signal
+from nmigen import Signal, Module, Elaboratable
+from soc.experiment.testmem import TestMemory # TODO: replace with TMLSUI
+
+from nmigen.back.pysim import Simulator
+
+
+class TestMemLoadStoreUnit(LoadStoreUnitInterface, Elaboratable):
+    def __init__(self, regwid, addrwid):
+        super().__init__()
+        self.regwid = regwid
+        self.addrwid = addrwid
+    def elaborate(self, platform):
+        m = Module()
+
+        m.submodules.mem = mem = TestMemory(
+            self.regwid, self.addrwid, granularity=self.regwid//8)
+
+        m.d.comb += [
+            mem.rdport.addr.eq(self.x_addr),
+            self.m_load_data.eq(mem.rdport.data),
+
+            mem.wrport.addr.eq(self.x_addr),
+            mem.wrport.en.eq(self.x_store),
+            mem.wrport.data.eq(self.x_store_data)
+            ]
+
+        m.d.sync += self.x_valid.eq(self.x_load)
+
+        return m
+
+
+def write_to_addr(dut, addr, value):
+    yield dut.x_addr.eq(addr)
+    yield dut.x_store_data.eq(value)
+    yield dut.x_store.eq(1)
+
+    yield
+    yield dut.x_store.eq(0)
+    while (yield dut.x_stall):
+        yield
+
+if __name__ == '__main__':
+    m = Module()
+    dut = TestMemLoadStoreUnit(regwid=32, addrwid=4)
+    m.submodules.dut = dut
+
+    sim = Simulator(m)
+    sim.add_clock(1e-6)
+
+    def process():
+
+        yield from write_to_addr(dut, 0xa, 0xbeef)
+        yield dut.x_addr.eq(0xa)
+        yield dut.x_load.eq(1)
+        yield
+        yield dut.x_load.eq(0)
+        #while not (yield dut.x_valid) and (yield dut.x_busy):
+            #yield
+        yield
+        yield
+
+    sim.add_sync_process(process)
+    with sim.write_vcd("lsmem.vcd", "lsmem.gtkw", traces=[]):
+        sim.run()
index 4fcc68b8f20aada239a54b0db459c6954a5d451f..379b2919e4319a3663515e4ddfc343e6143fa693 100644 (file)
@@ -151,8 +151,8 @@ class CachedLoadStoreUnit(LoadStoreUnitInterface, Elaboratable):
         m.d.comb += wrbuf_port.we.eq(Const(1))
 
         dcache_port = dbus_arbiter.port(priority=1)
+        cti = Mux(dcache.bus_last, Cycle.END, Cycle.INCREMENT)
         m.d.comb += [
-            cti = Mux(dcache.bus_last, Cycle.END, Cycle.INCREMENT)
             dcache_port.cyc.eq(dcache.bus_re),
             dcache_port.stb.eq(dcache.bus_re),
             dcache_port.adr.eq(dcache.bus_addr),