From 351becc03c6649fd6f1846c57444425ed63dc768 Mon Sep 17 00:00:00 2001 From: t-wallet Date: Fri, 8 Mar 2024 14:24:47 +0100 Subject: [PATCH] component now handles backpressure and changed definition to return a Circuit --- src/Clash/Lattice/ECP5/UART.hs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Clash/Lattice/ECP5/UART.hs b/src/Clash/Lattice/ECP5/UART.hs index 8b586ae2..f9855637 100644 --- a/src/Clash/Lattice/ECP5/UART.hs +++ b/src/Clash/Lattice/ECP5/UART.hs @@ -1,26 +1,31 @@ {-#language FlexibleContexts #-} -module Clash.Lattice.ECP5.UART (uartTx') where +module Clash.Lattice.ECP5.UART + (uartTxC) where import Data.Maybe -import Clash.Cores.Ethernet.PacketStream + import Clash.Prelude -import Protocols +import Clash.Cores.Ethernet.PacketStream import Clash.Cores.UART +import Protocols +import Protocols.Internal + -convert :: Fwd (PacketStream dom 1 ()) -> Signal dom (Maybe (BitVector 8)) -convert = fmap $ fmap $ (head . _data) +convertToTx :: Signal dom (Maybe (PacketStreamM2S 1 ())) -> Signal dom (Maybe (BitVector 8)) +convertToTx = fmap $ fmap $ (head . _data) -uartTx' +uartTxC :: forall (dom :: Domain) (baud :: Nat) . HiddenClockResetEnable dom => ValidBaud dom baud => SNat baud -- ^ The UART baud - -> Signal dom (Maybe (PacketStreamM2S 1 ())) - -- ^ The word to transmit - -> (Signal dom Bit, Signal dom Bool) - -- ^ The output bits for the tx line and an acknowledgement that the word - -- to transmit has been received -uartTx' baud mWord = uartTx baud (convert mWord) + -> 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 = fromSignals ckt + where + ckt (fwd, _) = (PacketStreamS2M <$> ack, CSignal txBit) + where + (txBit, ack) = uartTx baud (convertToTx fwd)