From 6a4004ef8d22cb92e3306dad7868d1f14f2555f1 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 13 Dec 2018 18:17:58 +0000 Subject: [PATCH] back.pysim: fix handling of process termination. --- examples/ctrl.py | 13 ++++++++++++- nmigen/back/pysim.py | 3 +-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/ctrl.py b/examples/ctrl.py index 17a9e94..4d33e26 100644 --- a/examples/ctrl.py +++ b/examples/ctrl.py @@ -1,5 +1,5 @@ from nmigen.fhdl import * -from nmigen.back import rtlil, verilog +from nmigen.back import rtlil, verilog, pysim class ClockDivisor: @@ -17,5 +17,16 @@ class ClockDivisor: ctr = ClockDivisor(factor=16) frag = ctr.get_fragment(platform=None) + # print(rtlil.convert(frag, ports=[ctr.o, ctr.ce])) print(verilog.convert(frag, ports=[ctr.o, ctr.ce])) + +sim = pysim.Simulator(frag, vcd_file=open("ctrl.vcd", "w")) +sim.add_clock("sync", 1e-6) +def sim_proc(): + yield pysim.Delay(15.25e-6) + yield ctr.ce.eq(Const(1)) + yield pysim.Delay(15e-6) + yield ctr.ce.eq(Const(0)) +sim.add_process(sim_proc()) +with sim: sim.run_until(100e-6, run_passive=True) diff --git a/nmigen/back/pysim.py b/nmigen/back/pysim.py index 2afffab..fc298cf 100644 --- a/nmigen/back/pysim.py +++ b/nmigen/back/pysim.py @@ -320,8 +320,7 @@ class Simulator: stmt = proc.send(None) except StopIteration: self._processes.remove(proc) - self._passive.remove(proc) - self._suspended.remove(proc) + self._passive.discard(proc) return if isinstance(stmt, Delay): -- 2.30.2