periph.serial: add PHY as parameter, in order to use a blackbox.
authorJean-François Nguyen <jf@lambdaconcept.com>
Fri, 29 Oct 2021 16:55:33 +0000 (18:55 +0200)
committerJean-François Nguyen <jf@lambdaconcept.com>
Fri, 29 Oct 2021 16:55:33 +0000 (18:55 +0200)
lambdasoc/periph/serial.py

index 574f070e68a2aaaa732ac3ee606c6a23a93f22d9..e887d4804a7b954c46ae9cce2e412857a240a76b 100644 (file)
@@ -6,6 +6,7 @@ from nmigen_soc.periph import ConstantMap
 from nmigen_stdio.serial import AsyncSerial
 
 from . import Peripheral
+from ..sim.blackboxes.serial.wrapper import AsyncSerial_Blackbox
 
 
 __all__ = ["AsyncSerialPeripheral"]
@@ -71,10 +72,13 @@ class AsyncSerialPeripheral(Peripheral, Elaboratable):
     irq : :class:`IRQLine`
         Interrupt request line.
     """
-    def __init__(self, *, rx_depth=256, tx_depth=16, data_bits=8, **kwargs):
+    def __init__(self, *, core, rx_depth=256, tx_depth=16, **kwargs):
         super().__init__()
 
-        self._phy       = AsyncSerial(data_bits=data_bits, **kwargs)
+        if not isinstance(core, (AsyncSerial, AsyncSerial_Blackbox)):
+            raise TypeError("Core must be an instance of AsyncSerial or AsyncSerial_Blackbox, "
+                            "not {!r}".format(core))
+        self._phy       = core
         self._rx_fifo   = SyncFIFOBuffered(width=self._phy.rx.data.width, depth=rx_depth)
         self._tx_fifo   = SyncFIFOBuffered(width=self._phy.tx.data.width, depth=tx_depth)