{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-missing-fields #-}
module Protocols.Experimental.Axi4.WriteResponse (
M2S_WriteResponse (..),
S2M_WriteResponse (..),
Axi4WriteResponse,
Axi4WriteResponseConfig (..),
KnownAxi4WriteResponseConfig,
BKeepResponse,
BIdWidth,
) where
import Data.Coerce (coerce)
import Data.Kind (Type)
import GHC.Generics (Generic)
import Clash.Prelude qualified as C
import Protocols.Experimental.Axi4.Common
import Protocols.Experimental.Simulate
import Protocols.Idle
import Protocols.Internal
data Axi4WriteResponseConfig = Axi4WriteResponseConfig
{ _bKeepResponse :: Bool
, _bIdWidth :: C.Nat
}
type family BKeepResponse (conf :: Axi4WriteResponseConfig) where
BKeepResponse ('Axi4WriteResponseConfig a _) = a
type family BIdWidth (conf :: Axi4WriteResponseConfig) where
BIdWidth ('Axi4WriteResponseConfig _ a) = a
data
Axi4WriteResponse
(dom :: C.Domain)
(conf :: Axi4WriteResponseConfig)
(userType :: Type)
instance Protocol (Axi4WriteResponse dom conf userType) where
type
Fwd (Axi4WriteResponse dom conf userType) =
C.Signal dom (S2M_WriteResponse conf userType)
type
Bwd (Axi4WriteResponse dom conf userType) =
C.Signal dom M2S_WriteResponse
instance Backpressure (Axi4WriteResponse dom conf userType) where
boolsToBwd _ = C.fromList_lazy . coerce
data
S2M_WriteResponse
(conf :: Axi4WriteResponseConfig)
(userType :: Type)
= S2M_NoWriteResponse
| S2M_WriteResponse
{ _bid :: C.BitVector (BIdWidth conf)
, _bresp :: ResponseType (BKeepResponse conf)
, _buser :: userType
}
deriving (Generic)
newtype M2S_WriteResponse = M2S_WriteResponse {_bready :: Bool}
deriving stock (Show, Eq, Generic)
deriving anyclass (C.ShowX, C.NFDataX, C.BitPack)
type KnownAxi4WriteResponseConfig conf =
( KeepTypeClass (BKeepResponse conf)
, C.KnownNat (BIdWidth conf)
, Eq (ResponseType (BKeepResponse conf))
, Show (ResponseType (BKeepResponse conf))
, C.ShowX (ResponseType (BKeepResponse conf))
, C.NFDataX (ResponseType (BKeepResponse conf))
, C.BitPack (ResponseType (BKeepResponse conf))
)
deriving instance
( KnownAxi4WriteResponseConfig conf
, Eq userType
) =>
Eq (S2M_WriteResponse conf userType)
deriving instance
( KnownAxi4WriteResponseConfig conf
, Show userType
) =>
Show (S2M_WriteResponse conf userType)
deriving instance
( KnownAxi4WriteResponseConfig conf
, C.BitPack userType
) =>
C.BitPack (S2M_WriteResponse conf userType)
deriving instance
( KnownAxi4WriteResponseConfig conf
, C.ShowX userType
) =>
C.ShowX (S2M_WriteResponse conf userType)
deriving instance
( KnownAxi4WriteResponseConfig conf
, C.NFDataX userType
) =>
C.NFDataX (S2M_WriteResponse conf userType)
instance IdleCircuit (Axi4WriteResponse dom conf userType) where
idleFwd _ = pure S2M_NoWriteResponse
idleBwd _ = pure $ M2S_WriteResponse False