Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #41 from GiPHouse/3-wrap-existing-clashcores-uart-…
Browse files Browse the repository at this point in the history
…transmit-in-packetstream-protocol

3 wrap existing clashcores uart transmit in packetstream protocol :)
  • Loading branch information
rowanG077 authored Mar 9, 2024
2 parents ae8c99a + 8a18559 commit 552ffb3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions clash-eth.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,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:
Expand Down
39 changes: 39 additions & 0 deletions src/Clash/Lattice/ECP5/UART.hs
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 552ffb3

Please sign in to comment.