Skip to content

Instantly share code, notes, and snippets.

@ravijain056
Created June 7, 2016 19:38
Show Gist options
  • Save ravijain056/e31cde7045eb4a8d3ae003f6ff1dafe0 to your computer and use it in GitHub Desktop.
Save ravijain056/e31cde7045eb4a8d3ae003f6ff1dafe0 to your computer and use it in GitHub Desktop.
from myhdl import Signal, TristateSignal, block, instance, delay, always_comb, always_seq
@block
def foo(clk, iopin):
tri = Signal(bool(0))
iopindriver = iopin.driver()
"""
@always_comb
def statedriver():
iopindriver.next = clk if tri else None
"""
@always_seq(clk.posedge, reset=None)
def seqdriver1():
iopindriver.next = False
@always_seq(clk.negedge, reset=None)
def seqdriver2():
iopindriver.next = True
"""
@instance
def statechange():
while True:
iopindriver.next = False
# tri.next = False
yield delay(50) # can implement clkwait as you said
iopindriver.next = True
# tri.next = True
yield delay(50) # can implement clkwait as you said
"""
return seqdriver1, seqdriver2 #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