1
0
mirror of https://github.com/myhdl/myhdl.git synced 2025-01-24 21:52:56 +08:00
myhdl/example/manual/greetings.py

49 lines
1016 B
Python
Raw Normal View History

2005-12-09 17:01:07 +00:00
from myhdl import Signal, delay, instance, always, now, Simulation
2003-02-05 22:07:33 +00:00
2005-12-09 17:01:07 +00:00
def ClkDriver(clk, period=20):
2003-02-05 22:07:33 +00:00
lowTime = int(period/2)
highTime = period - lowTime
2005-12-09 17:01:07 +00:00
@instance
def driveClk():
while True:
yield delay(lowTime)
clk.next = 1
yield delay(highTime)
clk.next = 0
return driveClk
def Hello(clk, to="World!"):
@always(clk.posedge)
def sayHello():
2003-02-05 22:07:33 +00:00
print "%s Hello %s" % (now(), to)
2005-12-09 17:01:07 +00:00
return sayHello
2003-02-05 22:07:33 +00:00
def greetings():
clk1 = Signal(0)
clk2 = Signal(0)
2005-12-09 17:01:07 +00:00
clkdriver_1 = ClkDriver(clk1) # positional and default association
2005-12-19 14:16:17 +00:00
clkdriver_2 = ClkDriver(clk=clk2, period=19) # named association
2005-12-09 17:01:07 +00:00
hello_1 = Hello(clk=clk1) # named and default association
2005-12-19 14:16:17 +00:00
hello_2 = Hello(to="MyHDL", clk=clk2) # named association
2005-12-09 17:01:07 +00:00
return clkdriver_1, clkdriver_2, hello_1, hello_2
2003-02-05 22:07:33 +00:00
2003-06-30 14:24:23 +00:00
def main():
2005-12-09 17:01:07 +00:00
inst = greetings()
sim = Simulation(inst)
2003-06-30 14:24:23 +00:00
sim.run(50)
if __name__ == '__main__':
main()
2003-02-05 22:07:33 +00:00