Implement a memory in the bank simulator, check for R/W operations functionnality
authorJean THOMAS <git0@pub.jeanthomas.me>
Fri, 10 Jul 2020 12:09:21 +0000 (14:09 +0200)
committerJean THOMAS <git0@pub.jeanthomas.me>
Fri, 10 Jul 2020 12:09:21 +0000 (14:09 +0200)
gram/phy/fakephy.py
gram/test/test_soc.py

index 7b7326fa17ccc5a392f01e62c656b754b23d5ebc..16b5a4a5df770ca32b7747b1ecfea6738a517492 100644 (file)
@@ -73,37 +73,36 @@ class BankModel(Elaboratable):
                 row.eq(self.activate_row),
             ]
 
-        bank_mem_len   = nrows*ncols//(burst_length*self.nphases)
-        # mem            = Memory(width=data_width, depth=bank_mem_len, init=init)
-        # write_port     = mem.get_port(write_capable=True, we_granularity=we_granularity)
-        # read_port      = mem.get_port(async_read=True)
-        # m.submodules += mem, read_port, write_port
+        bank_mem_len = nrows*ncols//(burst_length*self.nphases)
+        mem = Memory(width=data_width, depth=100, init=init)
+        write_port = mem.write_port(granularity=we_granularity)
+        read_port = mem.read_port(domain="comb")
+        m.submodules += read_port, write_port
 
         wraddr         = Signal(range(bank_mem_len))
         rdaddr         = Signal(range(bank_mem_len))
 
         m.d.comb += [
-            wraddr.eq((row*ncols | self.write_col)[log2_int(burst_length*self.nphases):]),
-            rdaddr.eq((row*ncols | self.read_col)[log2_int(burst_length*self.nphases):]),
+            wraddr.eq((row*ncols | self.write_col)[log2_int(burst_length*self.nphases):] % 100),
+            rdaddr.eq((row*ncols | self.read_col)[log2_int(burst_length*self.nphases):] % 100),
         ]
 
         with m.If(active):
-            m.d.comb += [
-            #     write_port.adr.eq(wraddr),
-            #     write_port.dat_w.eq(self.write_data),
-            ]
+            m.d.comb += [
+                write_port.addr.eq(wraddr % 100),
+                write_port.data.eq(self.write_data),
+            ]
 
-            with m.If(we_granularity):
-            #     m.d.comb += write_port.we.eq(Replicate(self.write, data_width//8) & ~self.write_mask)
-            with m.Else():
-            #     m.d.comb += write_port.we.eq(self.write)
+            with m.If(we_granularity):
+                m.d.comb += write_port.en.eq(Repl(self.write, data_width//8) & ~self.write_mask)
+            with m.Else():
+                m.d.comb += write_port.en.eq(self.write)
 
             with m.If(self.read):
-                # m.d.comb += [
-                #     read_port.adr.eq(rdaddr),
-                #     self.read_data.eq(read_port.dat_r),
-                # ]
-                m.d.comb += self.read_data.eq(0xDEADBEEF)
+                m.d.comb += [
+                    read_port.addr.eq(rdaddr),
+                    self.read_data.eq(read_port.data),
+                ]
 
         return m
 
index 3813bf458eb0147e8d27cd42991161fa62c95584..e4b1c6e8b40790b860536971f84643da96793426 100644 (file)
@@ -148,7 +148,13 @@ class SocTestCase(FHDLTestCase):
             for i in range(2000):
                 yield
 
-            res = yield from wb_read(soc.bus, 0x10000000 >> 2, 0xF, 16384)
-            self.assertEqual(res, 0xDEADBEEF)
+            yield from wb_write(soc.bus, 0x10000000 >> 2, 0xACAB2020, 0xF, 128)
+            yield
+
+            # Check for data persistence
+            for i in range(10):
+                res = yield from wb_read(soc.bus, 0x10000000 >> 2, 0xF, 128)
+                self.assertEqual(res, 0xACAB2020)
+            
 
         runSimulation(m, process, "test_soc.vcd")