Skip to content

Commit 8dff0e2

Browse files
committed
Simplify Clash.Primitives.DSL.unsafeToActive[High,Low]
You don't need to provide a KnownDomain anymore
1 parent 729574f commit 8dff0e2

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

clash-cores/src/Clash/Cores/Xilinx/DcFifo/Internal/BlackBoxes.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ dcFifoBBTF DcConfig{..} bbCtx
178178
let domty = DSL.ety knownDomainWrite
179179
in case stripVoid domty of
180180
N.KnownDomain _ _ _ Synchronous _ _ ->
181-
DSL.unsafeToActiveHigh "wr_rst_high" domty wRst
181+
DSL.unsafeToActiveHigh "wr_rst_high" wRst
182182
N.KnownDomain _ _ _ Asynchronous _ _ ->
183183
error $
184184
show 'dcFifoTF <> ": dcFifo only supports synchronous resets"
@@ -190,7 +190,7 @@ dcFifoBBTF DcConfig{..} bbCtx
190190
let domty = DSL.ety knownDomainRead
191191
in case stripVoid domty of
192192
N.KnownDomain _ _ _ Synchronous _ _ ->
193-
DSL.unsafeToActiveHigh "rd_rst_high" domty rRst
193+
DSL.unsafeToActiveHigh "rd_rst_high" rRst
194194
N.KnownDomain _ _ _ Asynchronous _ _ ->
195195
error $
196196
show 'dcFifoTF <> ": dcFifo only supports synchronous resets"

clash-lib/src/Clash/Primitives/DSL.hs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ import Clash.Annotations.Primitive (HDL (..), Primitive (..))
118118
import Clash.Annotations.SynthesisAttributes (Attr)
119119
import Clash.Backend hiding (Usage, fromBV, toBV)
120120
import Clash.Backend.VHDL (VHDLState)
121-
import Clash.Explicit.Signal (ResetPolarity(..))
122-
import Clash.Netlist.BlackBox.Util (exprToString, renderElem)
121+
import Clash.Explicit.Signal (ResetPolarity(..), vResetPolarity)
122+
import Clash.Netlist.BlackBox.Util (exprToString, getDomainConf, renderElem)
123123
import Clash.Netlist.BlackBox.Types
124124
(BlackBoxTemplate, Element(Component, Text), Decl(..))
125125
import qualified Clash.Netlist.Id as Id
@@ -204,6 +204,17 @@ instance Backend backend => HasIdentifierSet (BlockState backend) where
204204
instance HasUsageMap backend => HasUsageMap (BlockState backend) where
205205
usageMap = bsBackend.usageMap
206206

207+
liftToBlockState
208+
:: forall backend a. Backend backend
209+
=> State backend a -> State (BlockState backend) a
210+
liftToBlockState (StateT f) = StateT g
211+
where
212+
g :: BlockState backend -> Identity (a, BlockState backend)
213+
g sbsIn = do
214+
let sIn = _bsBackend sbsIn
215+
(res,sOut) <- f sIn
216+
pure (res, sbsIn{_bsBackend = sOut})
217+
207218
-- | A typed expression.
208219
data TExpr = TExpr
209220
{ ety :: HWType
@@ -1012,32 +1023,26 @@ unsafeToActiveHigh
10121023
:: Backend backend
10131024
=> Text
10141025
-- ^ Name hint
1015-
-> HWType
1016-
-- ^ 'KnownDomain'
10171026
-> TExpr
10181027
-- ^ Reset signal
10191028
-> State (BlockState backend) TExpr
1020-
unsafeToActiveHigh nm dom rExpr =
1021-
case extrResetPolarity dom of
1029+
unsafeToActiveHigh nm rExpr = do
1030+
resetLevel <- vResetPolarity <$> liftToBlockState (getDomainConf (ety rExpr))
1031+
case resetLevel of
10221032
ActiveHigh -> pure rExpr
10231033
ActiveLow -> notExpr nm rExpr
10241034

1025-
extrResetPolarity :: HWType -> ResetPolarity
1026-
extrResetPolarity (Void (Just (KnownDomain _ _ _ _ _ p))) = p
1027-
extrResetPolarity p = error ("Internal error: expected KnownDomain, got: " <> show p)
1028-
10291035
-- | Massage a reset to work as active-low reset.
10301036
unsafeToActiveLow
10311037
:: Backend backend
10321038
=> Text
10331039
-- ^ Name hint
1034-
-> HWType
1035-
-- ^ 'KnownDomain'
10361040
-> TExpr
10371041
-- ^ Reset signal
10381042
-> State (BlockState backend) TExpr
1039-
unsafeToActiveLow nm dom rExpr =
1040-
case extrResetPolarity dom of
1043+
unsafeToActiveLow nm rExpr = do
1044+
resetLevel <- vResetPolarity <$> liftToBlockState (getDomainConf (ety rExpr))
1045+
case resetLevel of
10411046
ActiveLow -> pure rExpr
10421047
ActiveHigh -> notExpr nm rExpr
10431048

clash-lib/src/Clash/Primitives/Xilinx/ClockGen.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ clockWizardTemplate
6565
-> BlackBoxContext
6666
-> State s Doc
6767
clockWizardTemplate isDifferential bbCtx
68-
| [ knownDomIn
68+
| [ _knownDomIn
6969
, _clocksClass
7070
, _clocksCxt
7171
, _numOutClocks
@@ -79,7 +79,7 @@ clockWizardTemplate isDifferential bbCtx
7979
clkWizInstName <- Id.makeBasic $ fromMaybe "clk_wiz" $ bbCtxName bbCtx
8080
DSL.declarationReturn bbCtx blockName $ do
8181

82-
rstHigh <- DSL.unsafeToActiveHigh "reset" (DSL.ety knownDomIn) rst
82+
rstHigh <- DSL.unsafeToActiveHigh "reset" rst
8383
pllOuts <- DSL.declareN "pllOut" pllOutTys
8484
locked <- DSL.declare "locked" Bit
8585
pllLock <- DSL.boolFromBit "pllLock" locked

0 commit comments

Comments
 (0)