{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-missing-fields #-}
module Protocols.Experimental.Axi4.ReadData (
M2S_ReadData (..),
S2M_ReadData (..),
Axi4ReadData,
Axi4ReadDataConfig (..),
KnownAxi4ReadDataConfig,
RKeepResponse,
RIdWidth,
forceResetSanity,
) where
import Data.Coerce (coerce)
import Data.Kind (Type)
import GHC.Generics (Generic)
import Prelude hiding (
const,
either,
filter,
fst,
map,
pure,
snd,
zip,
zipWith,
(!!),
)
import Clash.Prelude qualified as C
import Protocols.Experimental.Axi4.Common
import Protocols.Experimental.Simulate
import Protocols.Idle
import Protocols.Internal
data Axi4ReadDataConfig = Axi4ReadDataConfig
{ _rKeepResponse :: Bool
, _rIdWidth :: C.Nat
}
type family RKeepResponse (conf :: Axi4ReadDataConfig) where
RKeepResponse ('Axi4ReadDataConfig a _) = a
type family RIdWidth (conf :: Axi4ReadDataConfig) where
RIdWidth ('Axi4ReadDataConfig _ a) = a
data
Axi4ReadData
(dom :: C.Domain)
(conf :: Axi4ReadDataConfig)
(userType :: Type)
(dataType :: Type)
instance Protocol (Axi4ReadData dom conf userType dataType) where
type
Fwd (Axi4ReadData dom conf userType dataType) =
C.Signal dom (S2M_ReadData conf userType dataType)
type
Bwd (Axi4ReadData dom conf userType dataType) =
C.Signal dom M2S_ReadData
instance Backpressure (Axi4ReadData dom conf userType dataType) where
boolsToBwd _ = C.fromList_lazy . coerce
data
S2M_ReadData
(conf :: Axi4ReadDataConfig)
(userType :: Type)
(dataType :: Type)
= S2M_NoReadData
| S2M_ReadData
{ _rid :: C.BitVector (RIdWidth conf)
, _rdata :: dataType
, _rresp :: ResponseType (RKeepResponse conf)
, _rlast :: Bool
, _ruser :: userType
}
deriving (Generic)
newtype M2S_ReadData = M2S_ReadData {_rready :: Bool}
deriving stock (Show, Eq, Generic)
deriving anyclass (C.ShowX, C.NFDataX, C.BitPack)
type KnownAxi4ReadDataConfig conf =
( KeepTypeClass (RKeepResponse conf)
, C.KnownNat (RIdWidth conf)
, Show (ResponseType (RKeepResponse conf))
, C.ShowX (ResponseType (RKeepResponse conf))
, Eq (ResponseType (RKeepResponse conf))
, C.NFDataX (ResponseType (RKeepResponse conf))
, C.BitPack (ResponseType (RKeepResponse conf))
)
deriving instance
( KnownAxi4ReadDataConfig conf
, Show userType
, Show dataType
) =>
Show (S2M_ReadData conf userType dataType)
deriving instance
( KnownAxi4ReadDataConfig conf
, C.ShowX userType
, C.ShowX dataType
) =>
C.ShowX (S2M_ReadData conf userType dataType)
deriving instance
( KnownAxi4ReadDataConfig conf
, Eq userType
, Eq dataType
) =>
Eq (S2M_ReadData conf userType dataType)
deriving instance
( KnownAxi4ReadDataConfig conf
, C.NFDataX userType
, C.NFDataX dataType
) =>
C.NFDataX (S2M_ReadData conf userType dataType)
instance IdleCircuit (Axi4ReadData dom conf userType dataType) where
idleFwd _ = C.pure S2M_NoReadData
idleBwd _ = C.pure $ M2S_ReadData False
forceResetSanity ::
forall dom conf userType dataType.
(C.KnownDomain dom, C.HiddenReset dom) =>
Circuit
(Axi4ReadData dom conf userType dataType)
(Axi4ReadData dom conf userType dataType)
forceResetSanity = forceResetSanityGeneric