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, 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 commits.
  • Loading branch information
DigitalBrains1 committed Oct 24, 2023
1 parent e7d31e6 commit 4ddc3b6
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 217 deletions.
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
47 changes: 19 additions & 28 deletions clash-lib/src/Clash/Primitives/Intel/ClockGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
License : BSD2 (see the file LICENSE)
Maintainer : QBayLogic B.V. <devops@qbaylogic.com>
Blackbox template functions for Clash.Intel.ClockGen.{alteraPll,altpll}
Blackbox template functions for Clash.Intel.ClockGen
-}

{-# LANGUAGE OverloadedStrings #-}
Expand All @@ -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 @@ -25,6 +24,7 @@ import Data.Text.Extra (showt)

import Control.Monad.State
import Data.List.Infinite (Infinite(..), (...))
import Data.Maybe (fromMaybe)
import Data.Text.Prettyprint.Doc.Extra
import Text.Show.Pretty (ppShow)

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 @@ -64,28 +62,24 @@ altpllQsysTF = TemplateFunction used valid altpllQsysTemplate
alteraPllTF :: TemplateFunction
alteraPllTF = TemplateFunction used valid alteraPllTemplate
where
_clocksClass
:< knownDomIn
knownDomIn
:< _clocksClass
:< _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

alteraPllQsysTF :: TemplateFunction
alteraPllQsysTF = TemplateFunction used valid alteraPllQsysTemplate
where
_clocksClass
:< knownDomIn
knownDomIn
:< _clocksClass
:< clocksCxt
:< _name
:< _clk
:< _rst
:< _ = (0...)
Expand All @@ -98,19 +92,17 @@ alteraPllTemplate
=> BlackBoxContext
-> State s Doc
alteraPllTemplate bbCtx
| [ _clocksClass
, knownDomIn
| [ knownDomIn
, _clocksClass
, _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 Expand Up @@ -304,8 +295,8 @@ alteraPllQsysTemplate
=> BlackBoxContext
-> State s Doc
alteraPllQsysTemplate bbCtx
| _clocksClass
: (_,stripVoid -> kdIn,_)
| (_,stripVoid -> kdIn,_)
: _clocksClass
: (_,stripVoid -> Product _ _ (init -> kdOuts),_)
: _ <- bbInputs bbCtx
= let
Expand Down

0 comments on commit 4ddc3b6

Please sign in to comment.