-
-
Save nevercast/982b7243adcc33ce2d025c0b6f90444e to your computer and use it in GitHub Desktop.
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
from sys import argv | |
from typing import Callable, List | |
from nmigen.build.plat import Platform | |
from nmigen.hdl.ir import Elaboratable | |
from nmigen.back.pysim import Simulator | |
def sim_or_program(top: Elaboratable, platform: Platform, clock:int=1E-6, sync:List[Callable]=None) -> None: | |
_ = argv.pop(0) # executable | |
if '--program' in argv: | |
print("Programming...") | |
platform.build(top, do_program=True) | |
elif '--build' in argv: | |
print("Building only...") | |
platform.build(top, do_program=False) | |
else: # sim | |
print("Simulating...") | |
sim = Simulator(top) | |
sim.add_clock(clock) | |
def sync_defer_gen(dut, entrypoint): | |
def deferred(): | |
yield from entrypoint(dut) | |
return deferred | |
for sync_process in sync: | |
sim.add_sync_process(sync_defer_gen(dut=top, entrypoint=sync_process)) | |
with sim.write_vcd("dump.vcd", "dump.gtkw"): | |
sim.run_until(1E-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment