Skip to content

Commit

Permalink
Change frequency calculation to use periodToHz
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hiddemoll committed Mar 3, 2023
1 parent b55d12c commit c64c656
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions clash-lib/src/Clash/Primitives/Xilinx/ClockGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c64c656

Please sign in to comment.