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

Local clock domain can collide with global domain, causing assert failure #536

Open
korken89 opened this issue Nov 7, 2020 · 0 comments
Labels

Comments

@korken89
Copy link

korken89 commented Nov 7, 2020

Hi, after a short discussion with @whitequark I was asked to make an issue of this behavior.
What I have is a module which as a local clock domain, and if I make another global clock domain which has a colliding name I get an assert error.

This can quite easily happen when making a module, in which one has a local clock that might have a common enough name.

The generated assert error:

Traceback (most recent call last):
  File "/home/emifre/Git/alink-hdl/clock_error.py", line 31, in <module>
    sim = Simulator(m)
  File "/usr/lib/python3.8/site-packages/nmigen/back/pysim.py", line 916, in __init__
    self._fragment = Fragment.get(fragment, platform=None).prepare()
  File "/usr/lib/python3.8/site-packages/nmigen/hdl/ir.py", line 530, in prepare
    new_domains = fragment._propagate_domains(missing_domain)
  File "/usr/lib/python3.8/site-packages/nmigen/hdl/ir.py", line 378, in _propagate_domains
    self._propagate_domains_down()
  File "/usr/lib/python3.8/site-packages/nmigen/hdl/ir.py", line 340, in _propagate_domains_down
    assert self.domains[domain] is subfrag.domains[domain]

Minimal example:

from typing import List, Tuple

from nmigen import Module, Signal, Elaboratable, ClockDomain, ClockSignal
from nmigen.build import Platform
from nmigen.back.pysim import Simulator


class ClockSpiTest(Elaboratable):
    def elaborate(self, platform: Platform) -> Module:
        m = Module()

        m.domains += ClockDomain("spi_slave", local=True)

        return m


if __name__ == "__main__":
    # This causes colision with clock in ClockSpiTest,
    # even though it is set as `local=True`
    spi = ClockDomain(name="spi_slave")

    sync = ClockDomain(name="sync")

    m = Module()
    m.domains.sync = sync
    m.domains.spi_slave = spi

    m.submodules.test = test = ClockSpiTest()

    # Set up some simulation
    sim = Simulator(m)

Thanks for an awesome framework and keep up the amazing work!

@whitequark whitequark added the bug label Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants