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

48 lines
695 B
Python
Raw Normal View History

2006-02-21 09:24:55 +00:00
from myhdl import *
def latch(q, d, g):
@always_comb
def logic():
if g == 1:
q.next = d
return logic
from random import randrange
def test_latch():
q, d, g = [Signal(bool(0)) for i in range(3)]
latch_inst = latch(q, d, g)
@always(delay(7))
def dgen():
d.next = randrange(2)
@always(delay(41))
def ggen():
g.next = randrange(2)
return latch_inst, dgen, ggen
def simulate(timesteps):
tb = traceSignals(test_latch)
sim = Simulation(tb)
sim.run(timesteps)
simulate(20000)
def convert():
q, d, g = [Signal(bool(0)) for i in range(3)]
toVerilog(latch, q, d, g)
convert()