Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize period<->frequency conversion, use #2436

Merged
merged 1 commit into from
Mar 11, 2023
Merged

Conversation

DigitalBrains1
Copy link
Member

@DigitalBrains1 DigitalBrains1 commented Mar 9, 2023

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.

Still TODO:

  • Write a changelog entry (see changelog/README.md)
  • Check copyright notices are up to date in edited files

(part of this commit message pilfered from a message written by Hidde)

Copy link
Member

@martijnbastiaan martijnbastiaan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear improvement, minimal impact. LGTM!

`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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants