|
| 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