-
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.
Generalize period<->frequency conversion, use (#2436)
`periodToHz`, `hzToPeriod`, `fsToHz` and `hzToFs` can be generalized so they can be more easily used in cases where we don't want `Natural` and `Ratio Natural` as the types. However, the common use of `vPeriod=hzToPeriod 33e6` means we want the argument to `hzToPeriod` to be monomorphic. Making it polymorphic means it defaults to the inferior `Double` and warns about this defaulting. So we merely generalize the return types of these functions. These functions used to throw exceptions without call stacks when called with zero. By changing that to `ErrorCall` we can get a stack trace, solving an immense frustration in debugging a Clash design. Currently, the frequency calculation in for the Intel PLLs depends 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. This use case is what prompted this PR. Harmonized and slightly improved some documentation.
- Loading branch information
1 parent
222462d
commit 0dea9cd
Showing
4 changed files
with
83 additions
and
40 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,6 @@ | ||
CHANGED: Generalized the return types of `periodToHz` and `hzToPeriod`. Use a | ||
type application (`periodToHz @(Ratio Natural)`, `hzToPeriod @Natural`) to get | ||
the old behavior back, in case type errors arise. | ||
CHANGED: `periodToHz` and `hzToPeriod` now throw an `ErrorCall` with call stack | ||
when called with the argument 0 (zero), instead of a `RatioZeroDenominator :: | ||
ArithException`. |
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