interconnect/wishbone/Wishbone2CSR: add registered version and use it as default.
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 13 Aug 2020 22:47:05 +0000 (00:47 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 13 Aug 2020 22:47:05 +0000 (00:47 +0200)
litex/soc/interconnect/wishbone.py

index d61edbea1c223f43a52514d3b3769ef742c63efd..1e7efbd0d96565a224b1812b87ae99ffa10b722e 100644 (file)
@@ -366,7 +366,7 @@ class SRAM(Module):
 # Wishbone To CSR ----------------------------------------------------------------------------------
 
 class Wishbone2CSR(Module):
-    def __init__(self, bus_wishbone=None, bus_csr=None):
+    def __init__(self, bus_wishbone=None, bus_csr=None, register=True):
         self.csr = bus_csr
         if self.csr is None:
             # If no CSR bus provided, create it with default parameters.
@@ -378,24 +378,43 @@ class Wishbone2CSR(Module):
 
         # # #
 
-        self.comb += [
-            self.csr.dat_w.eq(self.wishbone.dat_w),
-            self.wishbone.dat_r.eq(self.csr.dat_r)
-        ]
-
-        fsm = FSM(reset_state="WRITE-READ")
-        self.submodules += fsm
-        fsm.act("WRITE-READ",
-            If(self.wishbone.cyc & self.wishbone.stb,
-                self.csr.adr.eq(self.wishbone.adr),
-                self.csr.we.eq(self.wishbone.we & (self.wishbone.sel != 0)),
+        if register:
+            fsm = FSM(reset_state="IDLE")
+            self.submodules += fsm
+            fsm.act("IDLE",
+                NextValue(self.csr.dat_w, self.wishbone.dat_w),
+                If(self.wishbone.cyc & self.wishbone.stb,
+                    NextValue(self.csr.adr, self.wishbone.adr),
+                    NextValue(self.csr.we, self.wishbone.we & (self.wishbone.sel != 0)),
+                    NextState("WRITE-READ")
+                )
+            )
+            fsm.act("WRITE-READ",
+                NextValue(self.csr.adr, 0),
+                NextValue(self.csr.we, 0),
                 NextState("ACK")
             )
-        )
-        fsm.act("ACK",
-            self.wishbone.ack.eq(1),
-            NextState("WRITE-READ")
-        )
+            fsm.act("ACK",
+                self.wishbone.ack.eq(1),
+                self.wishbone.dat_r.eq(self.csr.dat_r),
+                NextState("IDLE")
+            )
+        else:
+            fsm = FSM(reset_state="WRITE-READ")
+            self.submodules += fsm
+            fsm.act("WRITE-READ",
+                self.csr.dat_w.eq(self.wishbone.dat_w),
+                If(self.wishbone.cyc & self.wishbone.stb,
+                    self.csr.adr.eq(self.wishbone.adr),
+                    self.csr.we.eq(self.wishbone.we & (self.wishbone.sel != 0)),
+                    NextState("ACK")
+                )
+            )
+            fsm.act("ACK",
+                self.wishbone.ack.eq(1),
+                self.wishbone.dat_r.eq(self.csr.dat_r),
+                NextState("WRITE-READ")
+            )
 
 # Wishbone Cache -----------------------------------------------------------------------------------