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

How do I simulate? #208

Closed
RobertBaruch opened this issue Sep 15, 2019 · 4 comments
Closed

How do I simulate? #208

RobertBaruch opened this issue Sep 15, 2019 · 4 comments
Labels

Comments

@RobertBaruch
Copy link

I know it has something to do with running python3 <py file> simulate, but what is the structure of that py file? Preferably something that doesn't involve unittest or FHDLTestCase.

@whitequark
Copy link
Contributor

See examples/basic/uart.py for an example of how to simulate without using nmigen.cli.

@RobertBaruch
Copy link
Author

Perfect, thanks!

@RobertBaruch
Copy link
Author

Fun, it works! Although I wish I didn't have to specify the domain all the time. Because of my apparently poor choice of clock domain name :P

from nmigen import *
from nmigen.asserts import *
from nmigen.hdl.ast import *
from nmigen.back import pysim

from transparent_latch import TransparentLatch

if __name__ == "__main__":
    latch = TransparentLatch(8)
    ports = latch.ports()

    with pysim.Simulator(
            latch,
            vcd_file=open("transparent_latch.vcd", "w"),
            gtkw_file=open("transparent_latch.gtkw", "w"),
            traces=ports) as sim:
        sim.add_clock(1e-6, domain="pos")

        def process():
            # initial reset
            yield latch.input.eq(0)
            yield latch.en.eq(0)
            yield Tick(domain="pos")
            yield Tick(domain="pos")
            yield latch.input.eq(0xFF)
            yield Tick(domain="pos")
            yield latch.en.eq(1)
            yield Tick(domain="pos")
            yield latch.en.eq(0)
            yield Tick(domain="pos")

        # or add_process?
        sim.add_sync_process(process(), domain="pos")
        sim.run()

@whitequark
Copy link
Contributor

You should use add_sync_process and yield, or add_process and yield Tick(...); these are mutually exclusive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants