Skip to content

Commit f901f98

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

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
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
@@ -117,8 +117,8 @@ import Clash.Annotations.Primitive (HDL (..), Primitive (..))
117117
import Clash.Annotations.SynthesisAttributes (Attr)
118118
import Clash.Backend hiding (Usage, fromBV, toBV)
119119
import Clash.Backend.VHDL (VHDLState)
120-
import Clash.Explicit.Signal (ResetPolarity(..))
121-
import Clash.Netlist.BlackBox.Util (exprToString, renderElem)
120+
import Clash.Explicit.Signal (ResetPolarity(..), vResetPolarity)
121+
import Clash.Netlist.BlackBox.Util (exprToString, getDomainConf, renderElem)
122122
import Clash.Netlist.BlackBox.Types
123123
(BlackBoxTemplate, Element(Component, Text), Decl(..))
124124
import qualified Clash.Netlist.Id as Id
@@ -203,6 +203,17 @@ instance Backend backend => HasIdentifierSet (BlockState backend) where
203203
instance HasUsageMap backend => HasUsageMap (BlockState backend) where
204204
usageMap = bsBackend.usageMap
205205

206+
liftToBlockState
207+
:: forall backend a. Backend backend
208+
=> State backend a -> State (BlockState backend) a
209+
liftToBlockState (StateT f) = StateT g
210+
where
211+
g :: BlockState backend -> Identity (a, BlockState backend)
212+
g sbsIn = do
213+
let sIn = _bsBackend sbsIn
214+
(res,sOut) <- f sIn
215+
pure (res, sbsIn{_bsBackend = sOut})
216+
206217
-- | A typed expression.
207218
data TExpr = TExpr
208219
{ ety :: HWType
@@ -992,32 +1003,26 @@ unsafeToActiveHigh
9921003
:: Backend backend
9931004
=> Text
9941005
-- ^ Name hint
995-
-> HWType
996-
-- ^ 'KnownDomain'
9971006
-> TExpr
9981007
-- ^ Reset signal
9991008
-> State (BlockState backend) TExpr
1000-
unsafeToActiveHigh nm dom rExpr =
1001-
case extrResetPolarity dom of
1009+
unsafeToActiveHigh nm rExpr = do
1010+
resetLevel <- vResetPolarity <$> liftToBlockState (getDomainConf (ety rExpr))
1011+
case resetLevel of
10021012
ActiveHigh -> pure rExpr
10031013
ActiveLow -> notExpr nm rExpr
10041014

1005-
extrResetPolarity :: HWType -> ResetPolarity
1006-
extrResetPolarity (Void (Just (KnownDomain _ _ _ _ _ p))) = p
1007-
extrResetPolarity p = error ("Internal error: expected KnownDomain, got: " <> show p)
1008-
10091015
-- | Massage a reset to work as active-low reset.
10101016
unsafeToActiveLow
10111017
:: Backend backend
10121018
=> Text
10131019
-- ^ Name hint
1014-
-> HWType
1015-
-- ^ 'KnownDomain'
10161020
-> TExpr
10171021
-- ^ Reset signal
10181022
-> State (BlockState backend) TExpr
1019-
unsafeToActiveLow nm dom rExpr =
1020-
case extrResetPolarity dom of
1023+
unsafeToActiveLow nm rExpr = do
1024+
resetLevel <- vResetPolarity <$> liftToBlockState (getDomainConf (ety rExpr))
1025+
case resetLevel of
10211026
ActiveLow -> pure rExpr
10221027
ActiveHigh -> notExpr nm rExpr
10231028

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ clockWizardDifferentialTF :: TemplateFunction
3333
clockWizardDifferentialTF =
3434
TemplateFunction used valid clockWizardDifferentialTemplate
3535
where
36-
knownDomIn
37-
:< knownDomOut
36+
_knownDomIn
37+
:< _knownDomOut
3838
:< name
3939
:< clk
4040
:< rst
4141
:< _ = (0...)
42-
used = [knownDomIn, knownDomOut, name, clk, rst]
42+
used = [name, clk, rst]
4343
valid = const True
4444

4545

@@ -48,7 +48,7 @@ clockWizardDifferentialTemplate
4848
=> BlackBoxContext
4949
-> State s Doc
5050
clockWizardDifferentialTemplate bbCtx
51-
| knownDomIn
51+
| _knownDomIn
5252
: _knownDomOut
5353
: name0
5454
: clk
@@ -64,7 +64,7 @@ clockWizardDifferentialTemplate bbCtx
6464
clkWizInstName <- Id.makeBasic "clockWizardDifferential_inst"
6565
DSL.declarationReturn bbCtx "clockWizardDifferential" $ do
6666

67-
rstHigh <- DSL.unsafeToActiveHigh "reset" (DSL.ety knownDomIn) rst
67+
rstHigh <- DSL.unsafeToActiveHigh "reset" rst
6868
pllOut <- DSL.declare "pllOut" Bit
6969
locked <- DSL.declare "locked" Bit
7070
pllLock <- DSL.boolFromBit "pllLock" locked

0 commit comments

Comments
 (0)