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

48 lines
810 B
Python
Raw Normal View History

2016-03-10 20:27:07 +01:00
import myhdl
2006-02-21 09:24:55 +00:00
from myhdl import *
2006-09-19 19:58:18 +00:00
from myhdl.conversion import analyze
2006-02-21 09:24:55 +00:00
def dff(q, d, clk):
@always(clk.posedge)
def logic():
q.next = d
return logic
from random import randrange
def test_dff():
q, d, clk = [Signal(bool(0)) for i in range(3)]
dff_inst = dff(q, d, clk)
@always(delay(10))
def clkgen():
clk.next = not clk
@always(clk.negedge)
def stimulus():
d.next = randrange(2)
return dff_inst, clkgen, stimulus
def simulate(timesteps):
traceSignals.timescale = "1ps"
2006-02-21 09:24:55 +00:00
tb = traceSignals(test_dff)
sim = Simulation(tb)
sim.run(timesteps)
sim.quit()
2006-02-21 09:24:55 +00:00
simulate(2000)
def convert():
q, d, clk = [Signal(bool(0)) for i in range(3)]
toVerilog(dff, q, d, clk)
2006-09-19 19:58:18 +00:00
analyze(dff, q, d, clk)
2006-02-21 09:24:55 +00:00
convert()