Last active
August 29, 2015 14:20
-
-
Save hgomersall/59e3d2b151e7931b1965 to your computer and use it in GitHub Desktop.
An example myhdl sim showing two sims running concurrently in different threads with no problem. In such an example, it is necessary to have separate signals, otherwise they *will* step on each other.
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 myhdl import * | |
import threading | |
a = Signal(intbv(0)[5:]) | |
b = Signal(intbv(0)[5:]) | |
clock1 = Signal(False) | |
clock2 = Signal(False) | |
reset1 = ResetSignal(False, active=True, async=False) | |
reset2 = ResetSignal(False, active=True, async=False) | |
lock = threading.Lock() | |
def clockgen(clock): | |
@instance | |
def clkgen(): | |
while True: | |
yield delay(10) | |
clock.next = not clock | |
return clkgen | |
def stimulus(sig, clock, reset): | |
data = [0] | |
@always(clock.posedge, reset) | |
def stimulus_inst(): | |
sig.next = data[0] | |
data[0] += 1 | |
return stimulus_inst | |
def printer(sig, clock, reset): | |
@always_seq(clock.posedge, reset) | |
def printer_inst(): | |
with lock: | |
print threading.current_thread(), now(), sig | |
return printer_inst | |
sim1 = Simulation([clockgen(clock1), stimulus(a, clock1, reset1), | |
printer(a, clock1, reset1)]) | |
sim2 = Simulation([clockgen(clock2), stimulus(b, clock2, reset2), | |
printer(b, clock2, reset2)]) | |
sim1_thread = threading.Thread(target=sim1.run, args=(200,)) | |
sim2_thread = threading.Thread(target=sim2.run, args=(300,)) | |
sim1_thread.start() | |
sim2_thread.start() | |
sim1_thread.join() | |
sim2_thread.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output from the above is something like:
myhdl 0.9 will just run forever.