Skip to content

Instantly share code, notes, and snippets.

@ravijain056
Created June 7, 2016 16:35
Show Gist options
  • Save ravijain056/6e7bf85fbe399f91115af820af84c2f1 to your computer and use it in GitHub Desktop.
Save ravijain056/6e7bf85fbe399f91115af820af84c2f1 to your computer and use it in GitHub Desktop.
from myhdl import Signal, TristateSignal, block, instance, delay, always_comb
@block
def foo(clk, iopin):
tri = Signal(bool(0))
iopindriver = iopin.driver()
@always_comb
def statedriver():
iopindriver.next = clk if tri else None
@instance
def statechange():
while True:
tri.next = False
yield delay(50) # can implement clkwait as you said
tri.next = True
yield delay(50) # can implement clkwait as you said
return statedriver, statechange
@block
def test_foo():
clk = Signal(bool(0))
iopin = TristateSignal(bool(0))
fooinst = foo(clk, iopin)
@instance
def clkdriver():
while True:
clk.next = not clk
yield delay(10)
return clkdriver, fooinst
testfooinst = test_foo()
testfooinst.config_sim(trace=True)
testfooinst.run_sim(duration=1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment