From d96e9f57aff0393cfe168f004ebab42c48c7ba46 Mon Sep 17 00:00:00 2001 From: Lucas Bollen Date: Fri, 28 Jun 2024 11:32:28 +0200 Subject: [PATCH] Add `ReqResp` Protocol A simple protocol for request-response transactions --- clash-protocols.cabal | 1 + src/Protocols/ReqResp.hs | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/Protocols/ReqResp.hs diff --git a/clash-protocols.cabal b/clash-protocols.cabal index 811b853e..862be025 100644 --- a/clash-protocols.cabal +++ b/clash-protocols.cabal @@ -179,6 +179,7 @@ library Protocols.Internal.Units.TH Protocols.Plugin Protocols.Plugin.Internal + Protocols.ReqResp Protocols.Wishbone Protocols.Wishbone.Standard Protocols.Wishbone.Standard.Hedgehog diff --git a/src/Protocols/ReqResp.hs b/src/Protocols/ReqResp.hs new file mode 100644 index 00000000..fc589a67 --- /dev/null +++ b/src/Protocols/ReqResp.hs @@ -0,0 +1,46 @@ +{- | +Simple protocol for request-response communication. +The forward channel channel has type @Signal dom (Maybe req)@ and is used to send requests. +The backward channel has type @Signal dom (Maybe resp)@ and is used to send responses. +The protocol must obey the following rules: +* When the forward channel is @Just a@, it must not change until the transaction is completed. +* The forward channel can not depend on the backward channel. +* When the forward channel is @Nothing@, the backward channel may be undefined. +-} +module Protocols.ReqResp where + +import qualified Clash.Prelude as C +import Data.Kind (Type) +import Protocols +import Protocols.Internal.Classes +import Prelude as P + +{- | For simple request-response protocols. The forward channel is used to send requests +and the backward channel is used to send responses. +Rules: +* When the forward channel is @Just a@, it must not change until the transaction + is completed. +* The forward channel can not depend on the backward channel. +* When the forward channel is @Nothing@, the backward channel may be undefined. +-} +data ReqResp (dom :: C.Domain) (req :: Type) (resp :: Type) + +instance Protocol (ReqResp dom req resp) where + -- \| Forward channel for ReqResp protocol: + type Fwd (ReqResp dom req resp) = C.Signal dom (Maybe req) + + -- \| Backward channel for ReqResp protocol: + type Bwd (ReqResp dom req resp) = C.Signal dom (Maybe resp) + +instance IdleCircuit (ReqResp dom req resp) where + idleFwd _ = pure Nothing + idleBwd _ = pure Nothing + +{- | Force a @Nothing@ on the backward channel and @Nothing@ on the forward +channel if reset is asserted. +-} +forceResetSanity :: + forall dom req resp. + (C.HiddenReset dom) => + Circuit (ReqResp dom req resp) (ReqResp dom req resp) +forceResetSanity = forceResetSanityGeneric