diff --git a/clash-eth.cabal b/clash-eth.cabal index bd12512a..0b955171 100644 --- a/clash-eth.cabal +++ b/clash-eth.cabal @@ -87,6 +87,7 @@ library Clash.Cores.Ethernet.RGMII Clash.Cores.Ethernet.PacketStream Clash.Lattice.ECP5.Prims + Clash.Lattice.ECP5.UART Clash.Lattice.ECP5.Colorlight.CRG default-language: Haskell2010 build-depends: diff --git a/src/Clash/Lattice/ECP5/UART.hs b/src/Clash/Lattice/ECP5/UART.hs new file mode 100644 index 00000000..f2928228 --- /dev/null +++ b/src/Clash/Lattice/ECP5/UART.hs @@ -0,0 +1,39 @@ +{-# language FlexibleContexts #-} + +module Clash.Lattice.ECP5.UART + (uartTxC, uartTxNoBaudGenC) where + +import Data.Maybe + +import Clash.Cores.Ethernet.PacketStream +import Clash.Cores.UART +import Clash.Prelude +import Protocols +import Protocols.Internal + + +convertToTx :: Signal dom (Maybe (PacketStreamM2S 1 ())) -> Signal dom (Maybe (BitVector 8)) +convertToTx = fmap $ fmap (head . _data) + +uartTxC + :: forall (dom :: Domain) + (baud :: Nat) + . HiddenClockResetEnable dom + => ValidBaud dom baud + => SNat baud + -- ^ The UART baud + -> Circuit (PacketStream dom 1 ()) (CSignal dom Bit) + -- ^ This component receives a PacketStream and converts it to the UART transmitter input while relaying backpressure from the UART +uartTxC baud = uartTxNoBaudGenC (baudGenerator baud) + +uartTxNoBaudGenC + :: HiddenClockResetEnable dom + => BaudGenerator dom + -- ^ The UART baud + -> Circuit (PacketStream dom 1 ()) (CSignal dom Bit) + -- ^ This component receives a PacketStream and converts it to the UART transmitter input while relaying backpressure from the UART +uartTxNoBaudGenC baudGen = fromSignals ckt + where + ckt (fwd, _) = (PacketStreamS2M <$> ack, CSignal txBit) + where + (txBit, ack) = uartTxNoBaudGen baudGen (convertToTx fwd)