Skip to content

Commit ee63617

Browse files
committed
Add ReqResp Protocol
A simple protocol for request-response transactions
1 parent 5e8ad7a commit ee63617

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

clash-protocols.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ library
177177
Protocols.Internal.Units.TH
178178
Protocols.Plugin
179179
Protocols.Plugin.Internal
180+
Protocols.ReqResp
180181
Protocols.Wishbone
181182
Protocols.Wishbone.Standard
182183
Protocols.Wishbone.Standard.Hedgehog

src/Protocols/ReqResp.hs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{- |
2+
Simple protocol for request-response communication.
3+
The forward channel channel has type @Signal dom (Maybe req)@ and is used to send requests.
4+
The backward channel has type @Signal dom (Maybe resp)@ and is used to send responses.
5+
The protocol must obey the following rules:
6+
* When the forward channel is @Just a@, it must not change until the transaction is completed.
7+
* The forward channel can not depend on the backward channel.
8+
* When the forward channel is @Nothing@, the backward channel may be undefined.
9+
-}
10+
module Protocols.ReqResp where
11+
12+
import qualified Clash.Prelude as C
13+
import Data.Kind (Type)
14+
import Protocols
15+
import Protocols.Internal.Classes
16+
import Prelude as P
17+
18+
{- | For simple request-response protocols. The forward channel is used to send requests
19+
and the backward channel is used to send responses.
20+
Rules:
21+
* When the forward channel is @Just a@, it must not change until the transaction
22+
is completed.
23+
* The forward channel can not depend on the backward channel.
24+
* When the forward channel is @Nothing@, the backward channel may be undefined.
25+
-}
26+
data ReqResp (dom :: C.Domain) (req :: Type) (resp :: Type)
27+
28+
instance Protocol (ReqResp dom req resp) where
29+
-- \| Forward channel for ReqResp protocol:
30+
type Fwd (ReqResp dom req resp) = C.Signal dom (Maybe req)
31+
32+
-- \| Backward channel for ReqResp protocol:
33+
type Bwd (ReqResp dom req resp) = C.Signal dom (Maybe resp)
34+
35+
instance IdleCircuit (ReqResp dom req resp) where
36+
idleFwd _ = pure Nothing
37+
idleBwd _ = pure Nothing
38+
39+
{- | Force a @Nothing@ on the backward channel and @Nothing@ on the forward
40+
channel if reset is asserted.
41+
-}
42+
forceResetSanity ::
43+
forall dom req resp.
44+
(C.HiddenReset dom) =>
45+
Circuit (ReqResp dom req resp) (ReqResp dom req resp)
46+
forceResetSanity = forceResetSanityGeneric

0 commit comments

Comments
 (0)