Skip to content

Commit

Permalink
Use setName for ClockGen functions
Browse files Browse the repository at this point in the history
The wizards in `Clash.Xilinx.ClockGen` now use the user-provided name as
the name of the /instance/ rather than the name of the /IP core/. This
change was also done for Intel in PR #1022. When the user is responsible
for creating the IP core/Qsys component, it makes sense to always set
the component name to the user-provided value. But when that is also
generated by Clash, that is no longer needed. Allowing users to set the
instance name makes it possible to match on the instance in SDC files
and such.

Instead of always needing a user-specified name for the Intel and Xilinx
PLL functions, the instance name can now be set through
`Clash.Magic.setName`. To accomodate the changed function arguments, the
functions are split into the deprecated old interface and a new
interface which marks the use _unsafe_. This is expanded upon in the
next commit.
  • Loading branch information
DigitalBrains1 committed Sep 28, 2023
1 parent 5bf8ded commit c06d513
Show file tree
Hide file tree
Showing 11 changed files with 388 additions and 201 deletions.
2 changes: 1 addition & 1 deletion PlayClocks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ myPll10 ::
myPll10 = clockWizardDifferentialSyncWithName (SSymbol @"foo")
{-# ANN myPll10 (defSyn "myPll10") #-}
{-# NOINLINE myPll10 #-}
-}

myPll11 ::
Clock System ->
Expand Down Expand Up @@ -140,7 +141,6 @@ myPll13 ::
myPll13 = clockWizard (SSymbol @"foo")
{-# ANN myPll13 (defSyn "myPll13") #-}
{-# NOINLINE myPll13 #-}
-}

myPll14 ::
Clock System ->
Expand Down
4 changes: 2 additions & 2 deletions clash-lib/prims/common/Clash_Intel_ClockGen.primitives.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- BlackBox:
name: Clash.Intel.ClockGen.altpll
name: Clash.Intel.ClockGen.unsafeAltpll
format: Haskell
includes:
- name: altpll
Expand All @@ -10,7 +10,7 @@
templateFunction: Clash.Primitives.Intel.ClockGen.altpllTF
workInfo: Always
- BlackBox:
name: Clash.Intel.ClockGen.alteraPll
name: Clash.Intel.ClockGen.unsafeAlteraPll
format: Haskell
includes:
- name: altera_pll
Expand Down
13 changes: 12 additions & 1 deletion clash-lib/prims/common/Clash_Xilinx_ClockGen.primitives.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
- BlackBox:
name: Clash.Xilinx.ClockGen.clockWizardDifferential
name: Clash.Xilinx.ClockGen.unsafeClockWizard
kind: Declaration
format: Haskell
templateFunction: Clash.Primitives.Xilinx.ClockGen.clockWizardTF
includes:
- name: clk_wiz
extension: clash.tcl
format: Haskell
templateFunction: Clash.Primitives.Xilinx.ClockGen.clockWizardTclTF
workInfo: Always
- BlackBox:
name: Clash.Xilinx.ClockGen.unsafeClockWizardDifferential
kind: Declaration
format: Haskell
templateFunction: Clash.Primitives.Xilinx.ClockGen.clockWizardDifferentialTF
Expand Down

This file was deleted.

36 changes: 0 additions & 36 deletions clash-lib/prims/vhdl/Clash_Xilinx_ClockGen.primitives.yaml

This file was deleted.

1 change: 1 addition & 0 deletions clash-lib/src/Clash/Driver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ knownTemplateFunctions =
, ('P.alteraPllTF, P.alteraPllTF)
, ('P.altpllTF, P.altpllTF)
, ('P.fromIntegerTFvhdl, P.fromIntegerTFvhdl)
, ('P.clockWizardTF, P.clockWizardTF)
, ('P.clockWizardDifferentialTF, P.clockWizardDifferentialTF)
, ('P.clockWizardTclTF, P.clockWizardTclTF)
, ('P.clockWizardDifferentialTclTF, P.clockWizardDifferentialTclTF)
Expand Down
29 changes: 10 additions & 19 deletions clash-lib/src/Clash/Primitives/Intel/ClockGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
module Clash.Primitives.Intel.ClockGen where

import Clash.Backend
import Clash.Netlist.BlackBox.Util
import qualified Clash.Netlist.Id as Id
import Clash.Netlist.Types
import Clash.Netlist.Util
Expand All @@ -24,6 +23,7 @@ import Clash.Signal (periodToHz)

import Control.Monad.State
import Data.List.Infinite (Infinite(..), (...))
import Data.Maybe (fromMaybe)
import qualified Data.String.Interpolate as I
import Data.Text.Prettyprint.Doc.Extra
import qualified Prettyprinter.Interpolate as I
Expand All @@ -37,15 +37,13 @@ altpllTF = TemplateFunction used valid altpllTemplate
where
knownDomIn
:< _knownDomOut
:< nm
:< _knownDomLock
:< clk
:< rst
:< _ = (0...)
used = [ knownDomIn, nm, clk, rst ]
used = [ knownDomIn, clk, rst ]
valid bbCtx
| (nm0,_,_) <- bbInputs bbCtx !! nm
, Just _ <- exprToString nm0
, [(_,Product {})] <- bbResults bbCtx
| [(_,Product {})] <- bbResults bbCtx
= True
valid _ = False

Expand All @@ -54,7 +52,7 @@ altpllQsysTF = TemplateFunction used valid altpllQsysTemplate
where
knownDomIn
:< knownDomOut
:< _name
:< _knownDomLock
:< _clk
:< _rst
:< _ = (0...)
Expand All @@ -67,15 +65,12 @@ alteraPllTF = TemplateFunction used valid alteraPllTemplate
_clocksClass
:< knownDomIn
:< _clocksCxt
:< nm
:< clk
:< rst
:< _ = (0...)
used = [ knownDomIn, nm, clk, rst ]
used = [ knownDomIn, clk, rst ]
valid bbCtx
| (nm0,_,_) <- bbInputs bbCtx !! nm
, Just _ <- exprToString nm0
, [(_,Product {})] <- bbResults bbCtx
| [(_,Product {})] <- bbResults bbCtx
= True
valid _ = False

Expand All @@ -85,7 +80,6 @@ alteraPllQsysTF = TemplateFunction used valid alteraPllQsysTemplate
_clocksClass
:< knownDomIn
:< clocksCxt
:< _name
:< _clk
:< _rst
:< _ = (0...)
Expand All @@ -101,16 +95,14 @@ alteraPllTemplate bbCtx
| [ _clocksClass
, knownDomIn
, _clocksCxt
, name0
, clk
, rst
] <- map fst (DSL.tInputs bbCtx)
, Just name1 <- DSL.getStr name0
, [DSL.ety -> resultTy] <- DSL.tResults bbCtx
, Product _ _ (init -> pllOutTys) <- resultTy
, [compName] <- bbQsysIncName bbCtx
= do
instName <- Id.makeBasic $ TextS.pack name1
instName <- Id.makeBasic $ fromMaybe "altera_pll" $ bbCtxName bbCtx

-- TODO: unsafeMake is dubious here: I don't think we take names in
-- TODO: bbQsysIncName into account when generating fresh ids
Expand Down Expand Up @@ -151,16 +143,15 @@ altpllTemplate
altpllTemplate bbCtx
| [ knownDomIn
, _knownDomOut
, name0
, _knownDomLock
, clk
, rst
] <- map fst (DSL.tInputs bbCtx)
, Just name1 <- DSL.getStr name0
, [DSL.ety -> resultTy] <- DSL.tResults bbCtx
, Product _ _ (pllOutTy:_) <- resultTy
, [compName] <- bbQsysIncName bbCtx
= do
instName <- Id.makeBasic $ TextS.pack name1
instName <- Id.makeBasic $ fromMaybe "altpll" $ bbCtxName bbCtx

-- TODO: unsafeMake is dubious here: I don't think we take names in
-- TODO: bbQsysIncName into account when generating fresh ids
Expand Down

0 comments on commit c06d513

Please sign in to comment.