2003-08-03 19:53:23 +00:00
|
|
|
from myhdl import Signal, Simulation, delay, always_comb
|
|
|
|
|
2005-12-10 22:49:34 +00:00
|
|
|
def Mux(z, a, b, sel):
|
2005-12-10 23:12:01 +00:00
|
|
|
|
2003-08-03 19:53:23 +00:00
|
|
|
""" Multiplexer.
|
|
|
|
|
|
|
|
z -- mux output
|
|
|
|
a, b -- data inputs
|
|
|
|
sel -- control input: select a if asserted, otherwise b
|
2003-08-04 17:06:57 +00:00
|
|
|
|
2003-08-03 19:53:23 +00:00
|
|
|
"""
|
2005-12-10 23:12:01 +00:00
|
|
|
|
2005-12-10 22:49:34 +00:00
|
|
|
@always_comb
|
2005-12-10 23:12:01 +00:00
|
|
|
def muxLogic():
|
2003-08-03 19:53:23 +00:00
|
|
|
if sel == 1:
|
|
|
|
z.next = a
|
|
|
|
else:
|
|
|
|
z.next = b
|
|
|
|
|
2005-12-10 23:12:01 +00:00
|
|
|
return muxLogic
|
2003-08-03 19:53:23 +00:00
|
|
|
|
|
|
|
from random import randrange
|
|
|
|
|
2005-12-10 22:49:34 +00:00
|
|
|
z, a, b, sel = [Signal(0) for i in range(4)]
|
2003-08-03 19:53:23 +00:00
|
|
|
|
2005-12-10 22:49:34 +00:00
|
|
|
mux_1 = Mux(z, a, b, sel)
|
2003-08-03 19:53:23 +00:00
|
|
|
|
|
|
|
def test():
|
|
|
|
print "z a b sel"
|
|
|
|
for i in range(8):
|
|
|
|
a.next, b.next, sel.next = randrange(8), randrange(8), randrange(2)
|
|
|
|
yield delay(10)
|
|
|
|
print "%s %s %s %s" % (z, a, b, sel)
|
|
|
|
|
2005-12-10 22:49:34 +00:00
|
|
|
test_1 = test()
|
|
|
|
|
2003-08-03 19:53:23 +00:00
|
|
|
def main():
|
2005-12-10 22:49:34 +00:00
|
|
|
sim = Simulation(mux_1, test_1)
|
|
|
|
sim.run()
|
2003-08-03 19:53:23 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|