soc/core/uart: add UartStub to enable fast simulation with cpu
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 6 Jul 2017 16:32:08 +0000 (18:32 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 6 Jul 2017 17:19:10 +0000 (19:19 +0200)
litex/soc/cores/uart.py
litex/soc/integration/soc_core.py

index 2edcf5c73d70c66df3b00084a140ff88cc89d146..a32b6e5b94c4dbab6d7115240e09d814b1709dd6 100644 (file)
@@ -185,6 +185,26 @@ class UART(Module, AutoCSR):
         ]
 
 
+class UARTStub(Module, AutoCSR):
+    def __init__(self):
+        self._rxtx = CSR(8)
+        self._txfull = CSRStatus()
+        self._rxempty = CSRStatus()
+
+        self.submodules.ev = EventManager()
+        self.ev.tx = EventSourceProcess()
+        self.ev.rx = EventSourceProcess()
+        self.ev.finalize()
+
+        # # #
+
+        self.comb += [
+            self._txfull.status.eq(0),
+            self.ev.tx.trigger.eq(~(self._rxtx.re & self._rxtx.r)),
+            self._rxempty.status.eq(1)
+        ]
+
+
 class UARTWishboneBridge(WishboneStreamingBridge):
     def __init__(self, pads, clk_freq, baudrate=115200):
         self.submodules.phy = RS232PHY(pads, clk_freq, baudrate)
index 5959bd60b47c02ff5c3780489155c91490478ac0..f31317840d40c0a2a3eb52c4f722d0d03a15cf7e 100644 (file)
@@ -41,7 +41,7 @@ class SoCCore(Module):
                 integrated_main_ram_size=0,
                 shadow_base=0x80000000,
                 csr_data_width=8, csr_address_width=14,
-                with_uart=True, uart_baudrate=115200,
+                with_uart=True, uart_baudrate=115200, uart_stub=False,
                 ident="",
                 with_timer=True):
         self.config = dict()
@@ -107,8 +107,11 @@ class SoCCore(Module):
         self.register_mem("csr", self.mem_map["csr"], self.wishbone2csr.wishbone)
 
         if with_uart:
-            self.submodules.uart_phy = uart.RS232PHY(platform.request("serial"), clk_freq, uart_baudrate)
-            self.submodules.uart = uart.UART(self.uart_phy)
+            if uart_stub:
+                self.submodules.uart  = uart.UARTStub()
+            else:
+                self.submodules.uart_phy = uart.RS232PHY(platform.request("serial"), clk_freq, uart_baudrate)
+                self.submodules.uart = uart.UART(self.uart_phy)
 
         if ident:
             self.submodules.identifier = identifier.Identifier(ident)