-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Xilinx clock wizard support through Tcl
- Loading branch information
Showing
6 changed files
with
235 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
{-| | ||
Copyright : (C) 2023, QBayLogic B.V. | ||
2023, Google Inc. | ||
License : BSD2 (see the file LICENSE) | ||
Maintainer : QBayLogic B.V. <devops@qbaylogic.com> | ||
Blackbox template functions for | ||
Clash.Xilinx.ClockGen.{clockWizard,clockWizardDifferential} | ||
-} | ||
|
||
{-# LANGUAGE QuasiQuotes #-} | ||
|
||
module Clash.Primitives.Xilinx.ClockGen where | ||
|
||
import Clash.Backend (Backend) | ||
import Clash.Netlist.BlackBox.Util (exprToString) | ||
import Clash.Netlist.Types | ||
import Clash.Netlist.Util (stripVoid) | ||
|
||
import Control.Monad.State (State) | ||
import qualified Data.String.Interpolate as I | ||
import Data.Text.Prettyprint.Doc.Extra (Doc) | ||
|
||
|
||
clockWizardTclTF :: TemplateFunction | ||
clockWizardTclTF = | ||
TemplateFunction used valid clockWizardTclTemplate | ||
where | ||
used = [0..4] | ||
valid bbCtx | ||
| [_,_,_,(nm,_,_),_,_] <- bbInputs bbCtx | ||
, Just _ <- exprToString nm | ||
, [(Identifier _ Nothing,Product {})] <- bbResults bbCtx | ||
= True | ||
valid _ = False | ||
|
||
clockWizardTclTemplate | ||
:: Backend s | ||
=> BlackBoxContext | ||
-> State s Doc | ||
clockWizardTclTemplate bbCtx = pure bbText | ||
where | ||
((_,stripVoid -> kdIn,_):(_,stripVoid -> kdOut,_):_:(nm,_,_):_) = bbInputs bbCtx | ||
Just compName = exprToString nm | ||
KnownDomain _ clkInPeriod _ _ _ _ = kdIn | ||
KnownDomain _ clkOutPeriod _ _ _ _ = kdOut | ||
clkInFreq :: Double | ||
clkInFreq = (1.0 / (fromInteger clkInPeriod * 1.0e-12)) / 1e6 | ||
clkOutFreq :: Double | ||
clkOutFreq = (1.0 / (fromInteger clkOutPeriod * 1.0e-12)) / 1e6 | ||
|
||
bbText = [I.__i| | ||
namespace eval $tclIface { | ||
variable api 1 | ||
variable scriptPurpose createIp | ||
variable ipName {#{compName}} | ||
|
||
proc createIp {ipName0 args} { | ||
create_ip \\ | ||
-name clk_wiz \\ | ||
-vendor xilinx.com \\ | ||
-library ip \\ | ||
-version 6.0 \\ | ||
-module_name $ipName0 \\ | ||
{*}$args | ||
|
||
set_property \\ | ||
-dict [list \\ | ||
CONFIG.PRIM_IN_FREQ #{clkInFreq} \\ | ||
CONFIG.CLKOUT1_REQUESTED_OUT_FREQ #{clkOutFreq} \\ | ||
] [get_ips $ipName0] | ||
return | ||
} | ||
}|] | ||
|
||
clockWizardDifferentialTclTF :: TemplateFunction | ||
clockWizardDifferentialTclTF = | ||
TemplateFunction used valid clockWizardDifferentialTclTemplate | ||
where | ||
used = [0..5] | ||
valid bbCtx | ||
| [_,_,_,(nm,_,_),_,_,_] <- bbInputs bbCtx | ||
, Just _ <- exprToString nm | ||
, [(Identifier _ Nothing,Product {})] <- bbResults bbCtx | ||
= True | ||
valid _ = False | ||
|
||
clockWizardDifferentialTclTemplate | ||
:: Backend s | ||
=> BlackBoxContext | ||
-> State s Doc | ||
clockWizardDifferentialTclTemplate bbCtx = pure bbText | ||
where | ||
((_,stripVoid -> kdIn,_):(_,stripVoid -> kdOut,_):_:(nm,_,_):_) = bbInputs bbCtx | ||
Just compName = exprToString nm | ||
KnownDomain _ clkInPeriod _ _ _ _ = kdIn | ||
KnownDomain _ clkOutPeriod _ _ _ _ = kdOut | ||
clkInFreq :: Double | ||
clkInFreq = (1.0 / (fromInteger clkInPeriod * 1.0e-12)) / 1e6 | ||
clkOutFreq :: Double | ||
clkOutFreq = (1.0 / (fromInteger clkOutPeriod * 1.0e-12)) / 1e6 | ||
|
||
bbText = [I.__i| | ||
namespace eval $tclIface { | ||
variable api 1 | ||
variable scriptPurpose createIp | ||
variable ipName {#{compName}} | ||
|
||
proc createIp {ipName0 args} { | ||
create_ip \\ | ||
-name clk_wiz \\ | ||
-vendor xilinx.com \\ | ||
-library ip \\ | ||
-version 6.0 \\ | ||
-module_name $ipName0 \\ | ||
{*}$args | ||
|
||
set_property \\ | ||
-dict [list \\ | ||
CONFIG.PRIM_SOURCE Differential_clock_capable_pin \\ | ||
CONFIG.PRIM_IN_FREQ #{clkInFreq} \\ | ||
CONFIG.CLKOUT1_REQUESTED_OUT_FREQ #{clkOutFreq} \\ | ||
] [get_ips $ipName0] | ||
return | ||
} | ||
}|] |
Oops, something went wrong.