Skip to content

Commit

Permalink
Slap unsafe on abortOnBackpressureC
Browse files Browse the repository at this point in the history
  • Loading branch information
t-wallet committed Sep 16, 2024
1 parent d5f6541 commit dac1bc4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions clash-protocols/src/Protocols/PacketStream/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Protocols.PacketStream.Base (
fanout,
forceResetSanity,
zeroOutInvalidBytesC,
abortOnBackPressureC,
unsafeAbortOnBackpressureC,

-- * Skid buffers
registerBoth,
Expand Down Expand Up @@ -252,16 +252,19 @@ unsafeDropBackpressure ::
(CSignal dom (Maybe (PacketStreamM2S dataWidth meta)))
unsafeDropBackpressure ckt = unsafeFromCSignal |> ckt |> toCSignal

-- | A circuit that sets `_abort` upon backpressure from the forward circuit.
abortOnBackPressureC ::
forall (dom :: Domain) (dataWidth :: Nat) (meta :: Type).
{- |
Sets '_abort' upon receiving backpressure from the subordinate.
__UNSAFE__: because @fwdOut@ depends on @bwdIn@, this may introduce
combinatorial loops.
-}
unsafeAbortOnBackpressureC ::
forall (dataWidth :: Nat) (meta :: Type) (dom :: Domain).
(HiddenClockResetEnable dom) =>
(KnownNat dataWidth) =>
(NFDataX meta) =>
Circuit
(CSignal dom (Maybe (PacketStreamM2S dataWidth meta)))
(PacketStream dom dataWidth meta)
abortOnBackPressureC = Circuit $ \(fwdInS, bwdInS) -> (pure (), go <$> bundle (fwdInS, bwdInS))
unsafeAbortOnBackpressureC = Circuit $ \(fwdInS, bwdInS) -> (pure (), go <$> bundle (fwdInS, bwdInS))
where
go (fwdIn, bwdIn) = fmap (\pkt -> pkt{_abort = _abort pkt || not (_ready bwdIn)}) fwdIn

Expand Down
2 changes: 1 addition & 1 deletion clash-protocols/src/Protocols/PacketStream/PacketFifo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ packetFifoC cSizeBits mSizeBits mode = case mode of
|> fromSignals (packetFifoImpl cSizeBits mSizeBits)
Drop ->
toCSignal
|> abortOnBackPressureC
|> unsafeAbortOnBackpressureC
|> forceResetSanity
|> fromSignals (packetFifoImpl cSizeBits mSizeBits)

Expand Down

0 comments on commit dac1bc4

Please sign in to comment.