{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fplugin=GHC.TypeLits.Normalise #-}
{-# OPTIONS_GHC -fplugin=GHC.TypeLits.KnownNat.Solver #-}
module Clash.Explicit.Reset
(
resetSynchronizer
, resetGlitchFilter
, resetGlitchFilterWithReset
, unsafeResetGlitchFilter
, holdReset
, convertReset
, noReset
, andReset, unsafeAndReset
, orReset, unsafeOrReset
, Reset
, resetGen
, resetGenN
, resetKind
, systemResetGen
, unsafeToReset
, unsafeFromReset
, unsafeToActiveHigh
, unsafeToActiveLow
, unsafeFromActiveHigh
, unsafeFromActiveLow
, unsafeFromHighPolarity
, unsafeFromLowPolarity
, unsafeToHighPolarity
, unsafeToLowPolarity
) where
import Data.Type.Equality ((:~:)(Refl))
import Clash.Class.Num (satSucc, SaturationMode(SatBound))
import Clash.Explicit.Signal
import Clash.Explicit.Synchronizer (dualFlipFlopSynchronizer)
import Clash.Promoted.Nat
import Clash.Signal.Internal
import Clash.Sized.Index (Index)
import GHC.Stack (HasCallStack)
import GHC.TypeLits (type (+), type (<=))
noReset :: KnownDomain dom => Reset dom
noReset :: Reset dom
noReset = Signal dom Bool -> Reset dom
forall (dom :: Domain).
KnownDomain dom =>
Signal dom Bool -> Reset dom
unsafeFromActiveHigh (Bool -> Signal dom Bool
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure Bool
False)
orReset ::
forall dom .
HasSynchronousReset dom =>
Reset dom ->
Reset dom ->
Reset dom
orReset :: Reset dom -> Reset dom -> Reset dom
orReset = Reset dom -> Reset dom -> Reset dom
forall (dom :: Domain).
KnownDomain dom =>
Reset dom -> Reset dom -> Reset dom
unsafeOrReset
unsafeOrReset :: forall dom. KnownDomain dom => Reset dom -> Reset dom -> Reset dom
unsafeOrReset :: Reset dom -> Reset dom -> Reset dom
unsafeOrReset (Reset dom -> Signal dom Bool
forall (dom :: Domain). Reset dom -> Signal dom Bool
unsafeFromReset -> Signal dom Bool
rst0) (Reset dom -> Signal dom Bool
forall (dom :: Domain). Reset dom -> Signal dom Bool
unsafeFromReset -> Signal dom Bool
rst1) =
Signal dom Bool -> Reset dom
forall (dom :: Domain).
KnownDomain dom =>
Signal dom Bool -> Reset dom
unsafeToReset (Signal dom Bool -> Reset dom) -> Signal dom Bool -> Reset dom
forall a b. (a -> b) -> a -> b
$
case forall (dom :: Domain) (polarity :: ResetPolarity).
(KnownDomain dom, DomainResetPolarity dom ~ polarity) =>
SResetPolarity polarity
forall (polarity :: ResetPolarity).
(KnownDomain dom,
DomainConfigurationResetPolarity (KnownConf dom) ~ polarity) =>
SResetPolarity polarity
resetPolarity @dom of
SResetPolarity (DomainConfigurationResetPolarity (KnownConf dom))
SActiveHigh -> Signal dom Bool
rst0 Signal dom Bool -> Signal dom Bool -> Signal dom Bool
forall (f :: Type -> Type).
Applicative f =>
f Bool -> f Bool -> f Bool
.||. Signal dom Bool
rst1
SResetPolarity (DomainConfigurationResetPolarity (KnownConf dom))
SActiveLow -> Signal dom Bool
rst0 Signal dom Bool -> Signal dom Bool -> Signal dom Bool
forall (f :: Type -> Type).
Applicative f =>
f Bool -> f Bool -> f Bool
.&&. Signal dom Bool
rst1
andReset ::
forall dom .
HasSynchronousReset dom =>
Reset dom ->
Reset dom ->
Reset dom
andReset :: Reset dom -> Reset dom -> Reset dom
andReset = Reset dom -> Reset dom -> Reset dom
forall (dom :: Domain).
KnownDomain dom =>
Reset dom -> Reset dom -> Reset dom
unsafeAndReset
unsafeAndReset :: forall dom. KnownDomain dom => Reset dom -> Reset dom -> Reset dom
unsafeAndReset :: Reset dom -> Reset dom -> Reset dom
unsafeAndReset (Reset dom -> Signal dom Bool
forall (dom :: Domain). Reset dom -> Signal dom Bool
unsafeFromReset -> Signal dom Bool
rst0) (Reset dom -> Signal dom Bool
forall (dom :: Domain). Reset dom -> Signal dom Bool
unsafeFromReset -> Signal dom Bool
rst1) =
Signal dom Bool -> Reset dom
forall (dom :: Domain).
KnownDomain dom =>
Signal dom Bool -> Reset dom
unsafeToReset (Signal dom Bool -> Reset dom) -> Signal dom Bool -> Reset dom
forall a b. (a -> b) -> a -> b
$
case forall (dom :: Domain) (polarity :: ResetPolarity).
(KnownDomain dom, DomainResetPolarity dom ~ polarity) =>
SResetPolarity polarity
forall (polarity :: ResetPolarity).
(KnownDomain dom,
DomainConfigurationResetPolarity (KnownConf dom) ~ polarity) =>
SResetPolarity polarity
resetPolarity @dom of
SResetPolarity (DomainConfigurationResetPolarity (KnownConf dom))
SActiveHigh -> Signal dom Bool
rst0 Signal dom Bool -> Signal dom Bool -> Signal dom Bool
forall (f :: Type -> Type).
Applicative f =>
f Bool -> f Bool -> f Bool
.&&. Signal dom Bool
rst1
SResetPolarity (DomainConfigurationResetPolarity (KnownConf dom))
SActiveLow -> Signal dom Bool
rst0 Signal dom Bool -> Signal dom Bool -> Signal dom Bool
forall (f :: Type -> Type).
Applicative f =>
f Bool -> f Bool -> f Bool
.||. Signal dom Bool
rst1
resetSynchronizer
:: forall dom
. KnownDomain dom
=> Clock dom
-> Reset dom
-> Reset dom
resetSynchronizer :: Clock dom -> Reset dom -> Reset dom
resetSynchronizer Clock dom
clk Reset dom
rst = Reset dom
rstOut
where
isActiveHigh :: Bool
isActiveHigh = case forall (dom :: Domain) (polarity :: ResetPolarity).
(KnownDomain dom, DomainResetPolarity dom ~ polarity) =>
SResetPolarity polarity
forall (polarity :: ResetPolarity).
(KnownDomain dom,
DomainConfigurationResetPolarity (KnownConf dom) ~ polarity) =>
SResetPolarity polarity
resetPolarity @dom of { SResetPolarity (DomainConfigurationResetPolarity (KnownConf dom))
SActiveHigh -> Bool
True; SResetPolarity (DomainConfigurationResetPolarity (KnownConf dom))
_ -> Bool
False }
rstOut :: Reset dom
rstOut =
case (forall (dom :: Domain) (sync :: ResetKind).
(KnownDomain dom, DomainResetKind dom ~ sync) =>
SResetKind sync
forall (sync :: ResetKind).
(KnownDomain dom,
DomainConfigurationResetKind (KnownConf dom) ~ sync) =>
SResetKind sync
resetKind @dom) of
SResetKind (DomainConfigurationResetKind (KnownConf dom))
SAsynchronous -> Signal dom Bool -> Reset dom
forall (dom :: Domain).
KnownDomain dom =>
Signal dom Bool -> Reset dom
unsafeToReset
(Signal dom Bool -> Reset dom) -> Signal dom Bool -> Reset dom
forall a b. (a -> b) -> a -> b
$ Clock dom
-> Reset dom
-> Enable dom
-> Bool
-> Signal dom Bool
-> Signal dom Bool
forall (dom :: Domain) a.
(KnownDomain dom, NFDataX a) =>
Clock dom
-> Reset dom -> Enable dom -> a -> Signal dom a -> Signal dom a
register Clock dom
clk Reset dom
rst Enable dom
forall (dom :: Domain). Enable dom
enableGen Bool
isActiveHigh
(Signal dom Bool -> Signal dom Bool)
-> Signal dom Bool -> Signal dom Bool
forall a b. (a -> b) -> a -> b
$ Clock dom
-> Reset dom
-> Enable dom
-> Bool
-> Signal dom Bool
-> Signal dom Bool
forall (dom :: Domain) a.
(KnownDomain dom, NFDataX a) =>
Clock dom
-> Reset dom -> Enable dom -> a -> Signal dom a -> Signal dom a
register Clock dom
clk Reset dom
rst Enable dom
forall (dom :: Domain). Enable dom
enableGen Bool
isActiveHigh
(Signal dom Bool -> Signal dom Bool)
-> Signal dom Bool -> Signal dom Bool
forall a b. (a -> b) -> a -> b
$ Bool -> Signal dom Bool
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (Bool -> Bool
not Bool
isActiveHigh)
SResetKind (DomainConfigurationResetKind (KnownConf dom))
SSynchronous -> Signal dom Bool -> Reset dom
forall (dom :: Domain).
KnownDomain dom =>
Signal dom Bool -> Reset dom
unsafeToReset
(Signal dom Bool -> Reset dom) -> Signal dom Bool -> Reset dom
forall a b. (a -> b) -> a -> b
$ Clock dom
-> Enable dom -> Bool -> Signal dom Bool -> Signal dom Bool
forall (dom :: Domain) a.
(KnownDomain dom, NFDataX a) =>
Clock dom -> Enable dom -> a -> Signal dom a -> Signal dom a
delay Clock dom
clk Enable dom
forall (dom :: Domain). Enable dom
enableGen Bool
isActiveHigh
(Signal dom Bool -> Signal dom Bool)
-> Signal dom Bool -> Signal dom Bool
forall a b. (a -> b) -> a -> b
$ Clock dom
-> Enable dom -> Bool -> Signal dom Bool -> Signal dom Bool
forall (dom :: Domain) a.
(KnownDomain dom, NFDataX a) =>
Clock dom -> Enable dom -> a -> Signal dom a -> Signal dom a
delay Clock dom
clk Enable dom
forall (dom :: Domain). Enable dom
enableGen Bool
isActiveHigh
(Signal dom Bool -> Signal dom Bool)
-> Signal dom Bool -> Signal dom Bool
forall a b. (a -> b) -> a -> b
$ Reset dom -> Signal dom Bool
forall (dom :: Domain). Reset dom -> Signal dom Bool
unsafeFromReset Reset dom
rst
resetGlitchFilter
:: forall dom glitchlessPeriod
. ( HasCallStack
, HasDefinedInitialValues dom
, 1 <= glitchlessPeriod
)
=> SNat glitchlessPeriod
-> Clock dom
-> Reset dom
-> Reset dom
resetGlitchFilter :: SNat glitchlessPeriod -> Clock dom -> Reset dom -> Reset dom
resetGlitchFilter = SNat glitchlessPeriod -> Clock dom -> Reset dom -> Reset dom
forall (dom :: Domain) (glitchlessPeriod :: Nat).
(HasCallStack, KnownDomain dom, 1 <= glitchlessPeriod) =>
SNat glitchlessPeriod -> Clock dom -> Reset dom -> Reset dom
unsafeResetGlitchFilter
{-# INLINE resetGlitchFilter #-}
unsafeResetGlitchFilter
:: forall dom glitchlessPeriod
. ( HasCallStack
, KnownDomain dom
, 1 <= glitchlessPeriod
)
=> SNat glitchlessPeriod
-> Clock dom
-> Reset dom
-> Reset dom
unsafeResetGlitchFilter :: SNat glitchlessPeriod -> Clock dom -> Reset dom -> Reset dom
unsafeResetGlitchFilter SNat glitchlessPeriod
glitchlessPeriod Clock dom
clk =
SNat glitchlessPeriod
-> ((Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod))
-> (Bool -> Signal dom Bool -> Signal dom Bool)
-> Reset dom
-> Reset dom
forall (dom :: Domain) (glitchlessPeriod :: Nat) state.
(HasCallStack, KnownDomain dom, 1 <= glitchlessPeriod,
state ~ (Bool, Index glitchlessPeriod)) =>
SNat glitchlessPeriod
-> (state -> Signal dom state -> Signal dom state)
-> (Bool -> Signal dom Bool -> Signal dom Bool)
-> Reset dom
-> Reset dom
resetGlitchFilter# SNat glitchlessPeriod
glitchlessPeriod (Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod)
reg Bool -> Signal dom Bool -> Signal dom Bool
dffSync
where
reg :: (Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod)
reg = Clock dom
-> Enable dom
-> (Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod)
forall (dom :: Domain) a.
(KnownDomain dom, NFDataX a) =>
Clock dom -> Enable dom -> a -> Signal dom a -> Signal dom a
delay Clock dom
clk Enable dom
forall (dom :: Domain). Enable dom
enableGen
dffSync :: Bool -> Signal dom Bool -> Signal dom Bool
dffSync = Clock dom
-> Clock dom
-> Reset dom
-> Enable dom
-> Bool
-> Signal dom Bool
-> Signal dom Bool
forall a (dom1 :: Domain) (dom2 :: Domain).
(NFDataX a, KnownDomain dom1, KnownDomain dom2) =>
Clock dom1
-> Clock dom2
-> Reset dom2
-> Enable dom2
-> a
-> Signal dom1 a
-> Signal dom2 a
dualFlipFlopSynchronizer Clock dom
clk Clock dom
clk Reset dom
forall (dom :: Domain). KnownDomain dom => Reset dom
noReset Enable dom
forall (dom :: Domain). Enable dom
enableGen
{-# INLINE unsafeResetGlitchFilter #-}
resetGlitchFilterWithReset
:: forall dom glitchlessPeriod
. ( HasCallStack
, KnownDomain dom
, 1 <= glitchlessPeriod
)
=> SNat glitchlessPeriod
-> Clock dom
-> Reset dom
-> Reset dom
-> Reset dom
resetGlitchFilterWithReset :: SNat glitchlessPeriod
-> Clock dom -> Reset dom -> Reset dom -> Reset dom
resetGlitchFilterWithReset SNat glitchlessPeriod
glitchlessPeriod Clock dom
clk Reset dom
ownRst =
SNat glitchlessPeriod
-> ((Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod))
-> (Bool -> Signal dom Bool -> Signal dom Bool)
-> Reset dom
-> Reset dom
forall (dom :: Domain) (glitchlessPeriod :: Nat) state.
(HasCallStack, KnownDomain dom, 1 <= glitchlessPeriod,
state ~ (Bool, Index glitchlessPeriod)) =>
SNat glitchlessPeriod
-> (state -> Signal dom state -> Signal dom state)
-> (Bool -> Signal dom Bool -> Signal dom Bool)
-> Reset dom
-> Reset dom
resetGlitchFilter# SNat glitchlessPeriod
glitchlessPeriod (Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod)
reg Bool -> Signal dom Bool -> Signal dom Bool
dffSync
where
reg :: (Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod)
reg = Clock dom
-> Reset dom
-> Enable dom
-> (Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod)
-> Signal dom (Bool, Index glitchlessPeriod)
forall (dom :: Domain) a.
(KnownDomain dom, NFDataX a) =>
Clock dom
-> Reset dom -> Enable dom -> a -> Signal dom a -> Signal dom a
register Clock dom
clk Reset dom
ownRst Enable dom
forall (dom :: Domain). Enable dom
enableGen
dffSync :: Bool -> Signal dom Bool -> Signal dom Bool
dffSync = Clock dom
-> Clock dom
-> Reset dom
-> Enable dom
-> Bool
-> Signal dom Bool
-> Signal dom Bool
forall a (dom1 :: Domain) (dom2 :: Domain).
(NFDataX a, KnownDomain dom1, KnownDomain dom2) =>
Clock dom1
-> Clock dom2
-> Reset dom2
-> Enable dom2
-> a
-> Signal dom1 a
-> Signal dom2 a
dualFlipFlopSynchronizer Clock dom
clk Clock dom
clk Reset dom
ownRst Enable dom
forall (dom :: Domain). Enable dom
enableGen
{-# INLINE resetGlitchFilterWithReset #-}
resetGlitchFilter#
:: forall dom glitchlessPeriod state
. ( HasCallStack
, KnownDomain dom
, 1 <= glitchlessPeriod
, state ~ (Bool, Index glitchlessPeriod)
)
=> SNat glitchlessPeriod
-> ( state
-> Signal dom state
-> Signal dom state
)
-> ( Bool
-> Signal dom Bool
-> Signal dom Bool
)
-> Reset dom
-> Reset dom
resetGlitchFilter# :: SNat glitchlessPeriod
-> (state -> Signal dom state -> Signal dom state)
-> (Bool -> Signal dom Bool -> Signal dom Bool)
-> Reset dom
-> Reset dom
resetGlitchFilter# SNat glitchlessPeriod
SNat state -> Signal dom state -> Signal dom state
reg Bool -> Signal dom Bool -> Signal dom Bool
dffSync Reset dom
rstIn0 =
let s' :: Signal dom state
s' = state -> Bool -> state
go (state -> Bool -> state)
-> Signal dom state -> Signal dom (Bool -> state)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal dom state
s Signal dom (Bool -> state) -> Signal dom Bool -> Signal dom state
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Signal dom Bool
rstIn2
s :: Signal dom state
s = state -> Signal dom state -> Signal dom state
reg (Bool
asserted, Index glitchlessPeriod
0) Signal dom state
s'
in Signal dom Bool -> Reset dom
forall (dom :: Domain).
KnownDomain dom =>
Signal dom Bool -> Reset dom
unsafeToReset (Signal dom Bool -> Reset dom) -> Signal dom Bool -> Reset dom
forall a b. (a -> b) -> a -> b
$ (Bool, Index glitchlessPeriod) -> Bool
forall a b. (a, b) -> a
fst ((Bool, Index glitchlessPeriod) -> Bool)
-> Signal dom (Bool, Index glitchlessPeriod) -> Signal dom Bool
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal dom state
Signal dom (Bool, Index glitchlessPeriod)
s
where
rstIn1 :: Signal dom Bool
rstIn1 = Reset dom -> Signal dom Bool
forall (dom :: Domain). Reset dom -> Signal dom Bool
unsafeFromReset Reset dom
rstIn0
rstIn2 :: Signal dom Bool
rstIn2 =
case forall (dom :: Domain) (sync :: ResetKind).
(KnownDomain dom, DomainResetKind dom ~ sync) =>
SResetKind sync
forall (sync :: ResetKind).
(KnownDomain dom,
DomainConfigurationResetKind (KnownConf dom) ~ sync) =>
SResetKind sync
resetKind @dom of
SResetKind (DomainConfigurationResetKind (KnownConf dom))
SAsynchronous -> Bool -> Signal dom Bool -> Signal dom Bool
dffSync Bool
asserted Signal dom Bool
rstIn1
SResetKind (DomainConfigurationResetKind (KnownConf dom))
SSynchronous -> Signal dom Bool
rstIn1
go :: state -> Bool -> state
go :: state -> Bool -> state
go (state, count) Bool
reset
| Bool
reset Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
state = (Bool
state, Index glitchlessPeriod
0)
| Index glitchlessPeriod
count Index glitchlessPeriod -> Index glitchlessPeriod -> Bool
forall a. Eq a => a -> a -> Bool
== Index glitchlessPeriod
forall a. Bounded a => a
maxBound = (Bool -> Bool
not Bool
state, Index glitchlessPeriod
0)
| Bool
otherwise = (Bool
state, Index glitchlessPeriod
count Index glitchlessPeriod
-> Index glitchlessPeriod -> Index glitchlessPeriod
forall a. Num a => a -> a -> a
+ Index glitchlessPeriod
1)
asserted :: Bool
asserted :: Bool
asserted =
case forall (dom :: Domain) (polarity :: ResetPolarity).
(KnownDomain dom, DomainResetPolarity dom ~ polarity) =>
SResetPolarity polarity
forall (polarity :: ResetPolarity).
(KnownDomain dom,
DomainConfigurationResetPolarity (KnownConf dom) ~ polarity) =>
SResetPolarity polarity
resetPolarity @dom of
SResetPolarity (DomainConfigurationResetPolarity (KnownConf dom))
SActiveHigh -> Bool
True
SResetPolarity (DomainConfigurationResetPolarity (KnownConf dom))
SActiveLow -> Bool
False
holdReset
:: forall dom n
. KnownDomain dom
=> Clock dom
-> Enable dom
-> SNat n
-> Reset dom
-> Reset dom
holdReset :: Clock dom -> Enable dom -> SNat n -> Reset dom -> Reset dom
holdReset Clock dom
clk Enable dom
en SNat n
SNat Reset dom
rst =
Signal dom Bool -> Reset dom
forall (dom :: Domain).
KnownDomain dom =>
Signal dom Bool -> Reset dom
unsafeFromActiveHigh ((Index (n + 1) -> Index (n + 1) -> Bool
forall a. Eq a => a -> a -> Bool
/=Index (n + 1)
forall a. Bounded a => a
maxBound) (Index (n + 1) -> Bool)
-> Signal dom (Index (n + 1)) -> Signal dom Bool
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal dom (Index (n + 1))
counter)
where
counter :: Signal dom (Index (n+1))
counter :: Signal dom (Index (n + 1))
counter = Clock dom
-> Reset dom
-> Enable dom
-> Index (n + 1)
-> Signal dom (Index (n + 1))
-> Signal dom (Index (n + 1))
forall (dom :: Domain) a.
(KnownDomain dom, NFDataX a) =>
Clock dom
-> Reset dom -> Enable dom -> a -> Signal dom a -> Signal dom a
register Clock dom
clk Reset dom
rst Enable dom
en Index (n + 1)
0 (SaturationMode -> Index (n + 1) -> Index (n + 1)
forall a. SaturatingNum a => SaturationMode -> a -> a
satSucc SaturationMode
SatBound (Index (n + 1) -> Index (n + 1))
-> Signal dom (Index (n + 1)) -> Signal dom (Index (n + 1))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal dom (Index (n + 1))
counter)
convertReset
:: forall domA domB
. ( KnownDomain domA
, KnownDomain domB
)
=> Clock domA
-> Clock domB
-> Reset domA
-> Reset domB
convertReset :: Clock domA -> Clock domB -> Reset domA -> Reset domB
convertReset Clock domA
clkA Clock domB
clkB Reset domA
rstA0 = Reset domB
rstB1
where
rstA1 :: Signal domA Bool
rstA1 = Reset domA -> Signal domA Bool
forall (dom :: Domain). Reset dom -> Signal dom Bool
unsafeFromReset Reset domA
rstA0
rstA2 :: Signal domA Bool
rstA2 =
case (forall (dom :: Domain) (polarity :: ResetPolarity).
(KnownDomain dom, DomainResetPolarity dom ~ polarity) =>
SResetPolarity polarity
forall (polarity :: ResetPolarity).
(KnownDomain domA,
DomainConfigurationResetPolarity (KnownConf domA) ~ polarity) =>
SResetPolarity polarity
resetPolarity @domA, forall (dom :: Domain) (polarity :: ResetPolarity).
(KnownDomain dom, DomainResetPolarity dom ~ polarity) =>
SResetPolarity polarity
forall (polarity :: ResetPolarity).
(KnownDomain domB,
DomainConfigurationResetPolarity (KnownConf domB) ~ polarity) =>
SResetPolarity polarity
resetPolarity @domB) of
(SResetPolarity (DomainConfigurationResetPolarity (KnownConf domA))
SActiveLow, SResetPolarity (DomainConfigurationResetPolarity (KnownConf domB))
SActiveLow) -> Signal domA Bool
rstA1
(SResetPolarity (DomainConfigurationResetPolarity (KnownConf domA))
SActiveHigh, SResetPolarity (DomainConfigurationResetPolarity (KnownConf domB))
SActiveHigh) -> Signal domA Bool
rstA1
(SResetPolarity
(DomainConfigurationResetPolarity (KnownConf domA)),
SResetPolarity (DomainConfigurationResetPolarity (KnownConf domB)))
_ -> Bool -> Bool
not (Bool -> Bool) -> Signal domA Bool -> Signal domA Bool
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal domA Bool
rstA1
rstA3 :: Signal domA Bool
rstA3 =
case forall (dom :: Domain) (sync :: ResetKind).
(KnownDomain dom, DomainResetKind dom ~ sync) =>
SResetKind sync
forall (sync :: ResetKind).
(KnownDomain domA,
DomainConfigurationResetKind (KnownConf domA) ~ sync) =>
SResetKind sync
resetKind @domA of
SResetKind (DomainConfigurationResetKind (KnownConf domA))
SSynchronous -> Clock domA
-> Enable domA -> Bool -> Signal domA Bool -> Signal domA Bool
forall (dom :: Domain) a.
(KnownDomain dom, NFDataX a) =>
Clock dom -> Enable dom -> a -> Signal dom a -> Signal dom a
delay Clock domA
clkA Enable domA
forall (dom :: Domain). Enable dom
enableGen Bool
assertedA Signal domA Bool
rstA2
SResetKind (DomainConfigurationResetKind (KnownConf domA))
_ -> Signal domA Bool
rstA2
rstB0 :: Reset domB
rstB0 = Signal domB Bool -> Reset domB
forall (dom :: Domain).
KnownDomain dom =>
Signal dom Bool -> Reset dom
unsafeToReset (Signal domB Bool -> Reset domB) -> Signal domB Bool -> Reset domB
forall a b. (a -> b) -> a -> b
$ Clock domA -> Clock domB -> Signal domA Bool -> Signal domB Bool
forall (dom1 :: Domain) (dom2 :: Domain) a.
(KnownDomain dom1, KnownDomain dom2) =>
Clock dom1 -> Clock dom2 -> Signal dom1 a -> Signal dom2 a
unsafeSynchronizer Clock domA
clkA Clock domB
clkB Signal domA Bool
rstA3
rstB1 :: Reset domB
rstB1 =
case ((KnownDomain domA, KnownDomain domB) => Maybe (domA :~: domB)
forall (domA :: Domain) (domB :: Domain).
(KnownDomain domA, KnownDomain domB) =>
Maybe (domA :~: domB)
sameDomain @domA @domB) of
Just domA :~: domB
Refl -> Reset domA
Reset domB
rstA0
Maybe (domA :~: domB)
Nothing -> Clock domB -> Reset domB -> Reset domB
forall (dom :: Domain).
KnownDomain dom =>
Clock dom -> Reset dom -> Reset dom
resetSynchronizer Clock domB
clkB Reset domB
rstB0
assertedA :: Bool
assertedA :: Bool
assertedA =
case forall (dom :: Domain) (polarity :: ResetPolarity).
(KnownDomain dom, DomainResetPolarity dom ~ polarity) =>
SResetPolarity polarity
forall (polarity :: ResetPolarity).
(KnownDomain domA,
DomainConfigurationResetPolarity (KnownConf domA) ~ polarity) =>
SResetPolarity polarity
resetPolarity @domA of
SResetPolarity (DomainConfigurationResetPolarity (KnownConf domA))
SActiveHigh -> Bool
True
SResetPolarity (DomainConfigurationResetPolarity (KnownConf domA))
SActiveLow -> Bool
False