Skip to content

Instantly share code, notes, and snippets.

@cr1901
Last active July 4, 2021 07:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cr1901/5de5b276fca539b66fe7f4493a5bfe7d to your computer and use it in GitHub Desktop.
Save cr1901/5de5b276fca539b66fe7f4493a5bfe7d to your computer and use it in GitHub Desktop.
Migen Clock Domain Summary

Migen Clock Domains Summary

Terminology

  • Declaring a clock domain:
    • self.clock_domains.cd_mycd = ClockDomain()
  • Referencing a clock domain:
    • self.sync.mycd += []
    • ClockSignal("mycd")
  • Requesting an I/O signal:
    • platform.request("clk12")

Local Clock Domains

If you declare a clock domain cd_mycd in a Module, references to mycd in sync/ClockSignal statements in the current Module refer to the mycd declared in the current Module.

Global Clock Domains

No Conflict

If you didn't declare a clock domain cd_mycd in your current Module, references to mycd reference whichever Module has declared a clock domain called mycd, if the clock domain name mycd can be uniquely resolved to said Module.

Conflict

If a clock domain name mycd can't be resolved uniquely, (i.e. two Modules that are the immediate submodules of another Module declared mycd), the offending clock domains will be deterministically renamed (see manual for rename algorithm). The renamed clock domains are considered unique and distinct clock domains from each other and distinct from the clock domain called mycd.

In this case, you must either declare mycd manually in the current module ("Local Clock Domains" section applies), declare mycd in a submodule at a depth where no naming conflict occurs ("Global Clock Domains" section applies), or the Verilog generator will create "mycd" for you (if create_clock_domains=True).

migen.fhdl.verilog.convert Behavior

If create_clock_domains=False, all clocks that are referenced in sync or ClockSignal statements, even the default sys clock domain, must be manually declared.

If create_clock_domains=True, verilog.convert will automatically add any clocks that were not declared in the input Module (including constituent submodules) to the output Verilog port list.

For clock domains which were manually declared, verilog.convert will not add such clk and rst signals to the output port list. It is up to the user to remember to add these clock domain signals (ios parameter to verilog.convert).

migen.build Behavior

If using the migen.build classes, create_clock_domains=False by necessity. However GenericPlatform.build will create a default sys clock domain (and I/O signal via GenericPlatform.request) in the simple case where the user has not declared any ClockDomains in the input Module and its corresponding submodules. In all other cases, the user must route clock and reset signals manually to the platform's I/O signals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment