-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
Clash.Clocks
lock signal (#2417)
The lock signal is now `False` for the time that the input reset signal is asserted, and `True` when the input reset signal is not asserted. Before this commit, the lock signal output was defined in terms of the reset input as follows: ``` rstIn :: Reset domIn lockOut :: Signal pllOut Bool lockOut = unsafeCoerce rstIn ``` This is incorrect in three ways: * You can't coerce a `Reset` into a `Signal`, it segfaults. * The timebase is wrong: one input sample becomes one output sample even when the output clock has a different period than the input clock. * There is no handling of `ResetPolarity`; the simulation model is that lock is deasserted when reset is asserted.
- Loading branch information
1 parent
b019384
commit c60353e
Showing
5 changed files
with
75 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FIXED: The Haskell simulation of the PLL lock signal in `Clash.Clocks` (used by | ||
`Clash.Intel.ClockGen`) is fixed: the signal is now unasserted for the time the | ||
reset input is asserted and vice versa, and no longer crashes the simulation. | ||
HDL generation is unchanged. The PLL functions now have an additional | ||
constraint: `KnownDomain pllLock`. |
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,50 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
{-# OPTIONS_GHC -Wno-unused-top-binds #-} | ||
|
||
module Clash.Tests.Clocks(tests) where | ||
|
||
import qualified Prelude as P | ||
|
||
import Test.Tasty | ||
import Test.Tasty.HUnit | ||
|
||
import Clash.Explicit.Prelude | ||
import Clash.Intel.ClockGen (altpll) | ||
|
||
-- Ratio of clock periods in 'createDomain' and 'resetLen' are chosen, rest is | ||
-- derived from that | ||
|
||
createDomain vSystem{vName="ClocksSlow", vPeriod=3 * vPeriod vSystem} | ||
|
||
resetLen :: SNat 10 | ||
resetLen = SNat | ||
|
||
lockResampled :: Assertion | ||
lockResampled = | ||
unlockedLenSeen @?= unlockedLen | ||
where | ||
pll :: | ||
Clock ClocksSlow -> | ||
Reset ClocksSlow -> | ||
(Clock System, Signal System Bool) | ||
pll = altpll (SSymbol @"pll") | ||
|
||
unlockedLenSeen = | ||
P.length . P.takeWhile not . | ||
-- Arbitrary cut-off so simulation always ends | ||
sampleN (unlockedLen + 100) . | ||
snd $ pll clockGen (resetGenN resetLen) | ||
|
||
clockRatio :: Int | ||
clockRatio = fromIntegral $ snatToNatural (clockPeriod @ClocksSlow) `div` | ||
snatToNatural (clockPeriod @System) | ||
|
||
unlockedLen :: Int | ||
unlockedLen = snatToNum resetLen * clockRatio - clockRatio + 1 | ||
|
||
tests :: TestTree | ||
tests = | ||
testGroup "Clocks class" | ||
[ testCase "Lock is resampled from reset" lockResampled ] |
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