From c64c6566045f2179afb7b4c7ab865729870e0714 Mon Sep 17 00:00:00 2001 From: Hidde Moll Date: Fri, 3 Mar 2023 10:47:07 +0100 Subject: [PATCH] Change frequency calculation to use `periodToHz` Currently, the frequency calculation dependens on the unit of the period of a `KnownDomain` (picoseconds). If this unit is to be changed internally in the future (to femtoseconds), this calculation would produce the wrong frequency. By using `periodToHz`, the unit of the period no longer matters and can be changed internally. --- clash-lib/src/Clash/Primitives/Xilinx/ClockGen.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/clash-lib/src/Clash/Primitives/Xilinx/ClockGen.hs b/clash-lib/src/Clash/Primitives/Xilinx/ClockGen.hs index e27d61c749..5c0d46d76b 100644 --- a/clash-lib/src/Clash/Primitives/Xilinx/ClockGen.hs +++ b/clash-lib/src/Clash/Primitives/Xilinx/ClockGen.hs @@ -15,6 +15,7 @@ import Clash.Backend (Backend) import Clash.Netlist.BlackBox.Util (exprToString) import Clash.Netlist.Types import Clash.Netlist.Util (stripVoid) +import Clash.Signal (periodToHz) import Control.Monad.State (State) import qualified Data.String.Interpolate as I @@ -47,9 +48,9 @@ clockWizardTclTemplate bbCtx = let clkInFreq :: Double - clkInFreq = (1.0 / (fromInteger clkInPeriod * 1e-12)) / 1e6 + clkInFreq = periodToHz clkInPeriod / 1e6 clkOutFreq :: Double - clkOutFreq = (1.0 / (fromInteger clkOutPeriod * 1e-12)) / 1e6 + clkOutFreq = periodToHz clkOutPeriod / 1e6 bbText = [I.__i| namespace eval $tclIface { @@ -105,9 +106,9 @@ clockWizardDifferentialTclTemplate bbCtx = let clkInFreq :: Double - clkInFreq = (1.0 / (fromInteger clkInPeriod * 1e-12)) / 1e6 + clkInFreq = periodToHz clkInPeriod / 1e6 clkOutFreq :: Double - clkOutFreq = (1.0 / (fromInteger clkOutPeriod * 1e-12)) / 1e6 + clkOutFreq = periodToHz clkOutPeriod / 1e6 bbText = [I.__i| namespace eval $tclIface {