コード例 #1
0
def main():
	# Create graph
	g = DataFlowGraph()
	gen1 = ComposableSource(g, NumberGen())
	gen2 = ComposableSource(g, NumberGen())
	
	ps = gen1 + gen2
	result = ps*gen1 + ps*gen2
	
	g.add_connection(result.actor_node, ActorNode(Dumper()))

	gen1.actor_node.actor.name = "gen1"
	gen2.actor_node.actor.name = "gen2"
	result.actor_node.name = "result"
	
	# Elaborate
	print("is_abstract before elaboration: " + str(g.is_abstract()))
	draw(g)
	g.elaborate()
	print("is_abstract after elaboration : " + str(g.is_abstract()))
	draw(g)

	# Simulate
	c = CompositeActor(g)
	fragment = c.get_fragment()
	sim = Simulator(fragment, Runner())
	sim.run(100)
コード例 #2
0
ファイル: fibonacci.py プロジェクト: ross1909/migen
def main():
	nbits = 32
	
	# See:
	# http://www.csse.monash.edu.au/~damian/Idioms/Topics/12.1.DataFlow/html/text.html
	g = DataFlowGraph()
	
	adder = ActorNode(Add(BV(nbits)))
	bufadd = ActorNode(plumbing.Buffer) # TODO FIXME: deadlocks without this buffer
	init1 = ActorNode(Init(nbits))
	buf1 = ActorNode(plumbing.Buffer)
	init2 = ActorNode(Init(nbits))
	buf2 = ActorNode(plumbing.Buffer)
	
	g.add_connection(adder, bufadd)
	g.add_connection(bufadd, init1)
	g.add_connection(init1, buf1)
	g.add_connection(buf1, adder, sink_subr="a")
	g.add_connection(buf1, init2)
	g.add_connection(init2, buf2)
	g.add_connection(buf2, adder, sink_subr="b")
	
	g.add_connection(bufadd, ActorNode(Dumper(nbits)))
	
	c = CompositeActor(g)
	fragment = c.get_fragment()
	sim = Simulator(fragment, Runner())
	sim.run(100)
コード例 #3
0
def main():
	dut = Refresher(13, 2, tRP=3, tREFI=100, tRFC=5)
	logger = CommandLogger(dut.cmd)
	granter = Granter(dut.req, dut.ack)
	fragment = dut.get_fragment() + logger.get_fragment() + granter.get_fragment()
	sim = Simulator(fragment)
	sim.run(400)
コード例 #4
0
ファイル: framebuffer.py プロジェクト: shuckc/misoc
def main():
	hub = asmibus.Hub(16, 128)
	port = hub.get_port()
	hub.finalize()
	
	dut = Framebuffer(1, port, True)
	
	fragment = hub.get_fragment() + dut.get_fragment()
	sim = Simulator(fragment)
	
	sim.run(1)
	def csr_w(addr, d):
		sim.wr(dut.bank.description[addr].field.storage, d)
		
	hres = 4
	vres = 4
	
	csr_w(1, hres) # hres
	csr_w(2, hres+3) # hsync_start
	csr_w(3, hres+5) # hsync_stop
	csr_w(4, hres+10) # hscan
	csr_w(5, vres) # vres
	csr_w(6, vres+3) # vsync_start
	csr_w(7, vres+5) # vsync_stop
	csr_w(8, vres+10) # vscan
	csr_w(10, hres*vres*4) # length
	csr_w(0, 1) # enable
	
	sim.run(1000)
コード例 #5
0
ファイル: structuring.py プロジェクト: Jwomers/migen
def main():
	base_layout = [("value", 32)]
	packed_layout = structuring.pack_layout(base_layout, pack_factor)
	rawbits_layout = [("value", 32*pack_factor)]
	
	source = SimActor(source_gen(), ("source", Source, base_layout))
	sink = SimActor(sink_gen(), ("sink", Sink, base_layout))
	
	# A tortuous way of passing integer tokens.
	packer = structuring.Pack(base_layout, pack_factor)
	to_raw = structuring.Cast(packed_layout, rawbits_layout)
	from_raw = structuring.Cast(rawbits_layout, packed_layout)
	unpacker = structuring.Unpack(pack_factor, base_layout)
	
	g = DataFlowGraph()
	g.add_connection(source, packer)
	g.add_connection(packer, to_raw)
	g.add_connection(to_raw, from_raw)
	g.add_connection(from_raw, unpacker)
	g.add_connection(unpacker, sink)
	comp = CompositeActor(g)
	reporter = perftools.DFGReporter(g)
	
	fragment = comp.get_fragment() + reporter.get_fragment()
	sim = Simulator(fragment, Runner())
	sim.run(1000)
	
	g_layout = nx.spectral_layout(g)
	nx.draw(g, g_layout)
	nx.draw_networkx_edge_labels(g, g_layout, reporter.get_edge_labels())
	plt.show()
コード例 #6
0
ファイル: basic1.py プロジェクト: danfengzi/migen
def main():
	dut = Counter()
	# We do not specify a top-level nor runner object, and use the defaults.
	sim = Simulator(dut.get_fragment())
	# Since we do not use sim.interrupt, limit the simulation
	# to some number of cycles.
	sim.run(20)
コード例 #7
0
ファイル: fir.py プロジェクト: gyezhz/migen
def main():
	# Compute filter coefficients with SciPy.
	coef = signal.remez(80, [0, 0.1, 0.1, 0.5], [1, 0])
	fir = FIR(coef)
	
	# Simulate for different frequencies and concatenate
	# the results.
	in_signals = []
	out_signals = []
	for frequency in [0.05, 0.07, 0.1, 0.15, 0.2]:
		tb = TB(fir, frequency)
		fragment = autofragment.from_local()
		sim = Simulator(fragment, Runner())
		sim.run(100)
		in_signals += tb.inputs
		out_signals += tb.outputs
	
	# Plot data from the input and output waveforms.
	plt.plot(in_signals)
	plt.plot(out_signals)
	plt.show()
	
	# Print the Verilog source for the filter.
	print(verilog.convert(fir.get_fragment(),
		ios={fir.i, fir.o}))
コード例 #8
0
ファイル: dataflow_dma.py プロジェクト: gyezhz/migen
def test_writer():
    print("*** Testing writer")
    trgen = SimActor(trgen_gen(), ("address_data", Source, [("a", BV(30)), ("d", BV(32))]))
    writer = dma_wishbone.Writer()
    g = DataFlowGraph()
    g.add_connection(trgen, writer)
    comp = CompositeActor(g)

    peripheral = MyPeripheral()
    tap = wishbone.Tap(peripheral.bus)
    interconnect = wishbone.InterconnectPointToPoint(writer.bus, peripheral.bus)

    def end_simulation(s):
        s.interrupt = trgen.done and not s.rd(comp.busy)

    fragment = (
        comp.get_fragment()
        + peripheral.get_fragment()
        + tap.get_fragment()
        + interconnect.get_fragment()
        + Fragment(sim=[end_simulation])
    )

    sim = Simulator(fragment, Runner())
    sim.run()
コード例 #9
0
class SDRAMHostReadTest(sim.sdram_test_util.SDRAMUTFramework, unittest.TestCase):
#    def setUp(self):

    def _run(self, dummy_data, dummy_idle, max_burst_length, host_burst_length):
        self.tb = TestBench("mt48lc16m16a2", dummy_data, dummy_idle, max_burst_length, host_burst_length)
        # Verify that all necessary files are present
        files = gather_files(self.tb)
        for i in files:
            if not os.path.exists(i):
                raise FileNotFoundError("Please download and save the vendor "
                                        "SDRAM model in %s (not redistributable)"
                                        % i)

        runner = icarus.Runner(extra_files=files)
        vcd = "test_%s.vcd" % self.__class__.__name__
        self.sim = Simulator(self.tb, TopLevel(vcd), sim_runner=runner) 
        with self.sim:
            self.sim.run(10000)
    
    def test_sdram_host_read(self):
        self._run(300, 1000, 256, 16)

    def test_sdram_host_read_2(self):
        self._run(300, 10, 256, 256)

    def test_sdram_host_read_3(self):
        self._run(300, 1000, 16, 17)

    def test_sdram_host_read_4(self):
        self._run(300, 10, 32, 64)
コード例 #10
0
def main():
    dut = Counter()
    # Use the Icarus Verilog runner.
    # We do not specify a top-level object, and use the default.
    sim = Simulator(dut.get_fragment(), Runner())
    # Since we do not use sim.interrupt, limit the simulation
    # to some number of cycles.
    sim.run(20)
コード例 #11
0
ファイル: basic.py プロジェクト: danfengzi/migen
def run_sim(ng):
	g = DataFlowGraph()
	d = Dumper(layout)
	g.add_connection(ng, d)
	
	c = CompositeActor(g)
	sim = Simulator(c)
	sim.run(30)
	del sim
コード例 #12
0
ファイル: basic.py プロジェクト: Jwomers/migen
def run_sim(ng):
	g = DataFlowGraph()
	d = Dumper(layout)
	g.add_connection(ng, d)
	
	c = CompositeActor(g)
	fragment = c.get_fragment()
	sim = Simulator(fragment, Runner())
	sim.run(30)
	del sim
コード例 #13
0
def main():
	g = DataFlowGraph()
	g.add_connection(DataGen(), PE43602Driver(PE43602()))
	c = CompositeActor(g)
	
	def end_simulation(s):
		s.interrupt = s.cycle_counter > 5 and not s.rd(c.busy)
	f = c.get_fragment() + Fragment(sim=[end_simulation])
	sim = Simulator(f, TopLevel(vcd_name="pe43602.vcd"))
	sim.run()
コード例 #14
0
ファイル: misc.py プロジェクト: danfengzi/migen
def main():
	source = SimSource()
	loop = misc.IntSequence(32)
	sink = SimSink()
	g = DataFlowGraph()
	g.add_connection(source, loop)
	g.add_connection(loop, sink)
	comp = CompositeActor(g)
	sim = Simulator(comp)
	sim.run(500)
コード例 #15
0
ファイル: misc.py プロジェクト: fengxiaoiie/migen
def main():
	source = SimActor(source_gen(), ("source", Source, [("value", 32)]))
	loop = misc.IntSequence(32)
	sink = SimActor(sink_gen(), ("sink", Sink, [("value", 32)]))
	g = DataFlowGraph()
	g.add_connection(source, loop)
	g.add_connection(loop, sink)
	comp = CompositeActor(g)
	fragment = comp.get_fragment()
	sim = Simulator(fragment)
	sim.run(500)
コード例 #16
0
ファイル: dataflow.py プロジェクト: Jwomers/migen
def main():
	source = SimActor(source_gen(), ("source", Source, [("value", 32)]))
	sink = SimActor(sink_gen(), ("sink", Sink, [("value", 32)]))
	g = DataFlowGraph()
	g.add_connection(source, sink)
	comp = CompositeActor(g)
	def end_simulation(s):
		s.interrupt = source.token_exchanger.done
	fragment = comp.get_fragment() + Fragment(sim=[end_simulation])
	sim = Simulator(fragment, Runner())
	sim.run()
コード例 #17
0
ファイル: control.py プロジェクト: ross1909/migen
def main():
	source = ActorNode(SimActor(source_gen(), ("source", Source, [("value", BV(32))])))
	loop = ActorNode(control.For(32))
	sink = ActorNode(SimActor(sink_gen(), ("sink", Sink, [("value", BV(32))])))
	g = DataFlowGraph()
	g.add_connection(source, loop)
	g.add_connection(loop, sink)
	comp = CompositeActor(g)
	fragment = comp.get_fragment()
	sim = Simulator(fragment, Runner())
	sim.run(500)
コード例 #18
0
def main():
    source = ActorNode(
        SimActor(source_gen(), ("source", Source, [("value", BV(32))])))
    loop = ActorNode(control.For(32))
    sink = ActorNode(SimActor(sink_gen(), ("sink", Sink, [("value", BV(32))])))
    g = DataFlowGraph()
    g.add_connection(source, loop)
    g.add_connection(loop, sink)
    comp = CompositeActor(g)
    fragment = comp.get_fragment()
    sim = Simulator(fragment, Runner())
    sim.run(500)
コード例 #19
0
ファイル: __init__.py プロジェクト: shuckc/misoc
def _main():
	from migen.sim.generic import Simulator, TopLevel
	from migen.fhdl import verilog

	pads = Record([("cs_n", 1), ("clk", 1), ("dq", 4)])
	s = SpiFlash(pads)
	print(verilog.convert(s, ios={pads.clk, pads.cs_n, pads.dq, s.bus.adr,
		s.bus.dat_r, s.bus.cyc, s.bus.ack, s.bus.stb}))

	tb = SpiFlashTB()
	sim = Simulator(tb, TopLevel("spiflash.vcd"))
	sim.run()
コード例 #20
0
ファイル: dma.py プロジェクト: fengxiaoiie/migen
def wishbone_sim(efragment, master, end_simulation):
	peripheral = wishbone.Target(MyModelWB())
	tap = wishbone.Tap(peripheral.bus)
	interconnect = wishbone.InterconnectPointToPoint(master.bus, peripheral.bus)
	def _end_simulation(s):
		s.interrupt = end_simulation(s)
	fragment = efragment \
		+ peripheral.get_fragment() \
		+ tap.get_fragment() \
		+ interconnect.get_fragment() \
		+ Fragment(sim=[_end_simulation])
	sim = Simulator(fragment)
	sim.run()
コード例 #21
0
def wishbone_sim(efragment, master, end_simulation):
	peripheral = wishbone.Target(MyModelWB())
	tap = wishbone.Tap(peripheral.bus)
	interconnect = wishbone.InterconnectPointToPoint(master.bus, peripheral.bus)
	def _end_simulation(s):
		s.interrupt = end_simulation(s)
	fragment = efragment \
		+ peripheral.get_fragment() \
		+ tap.get_fragment() \
		+ interconnect.get_fragment() \
		+ Fragment(sim=[_end_simulation])
	sim = Simulator(fragment, Runner())
	sim.run()
コード例 #22
0
def asmi_sim(efragment, hub, end_simulation):
	def _end_simulation(s):
		s.interrupt = end_simulation(s)
	peripheral = asmibus.Target(hub, MyModelASMI())
	tap = asmibus.Tap(hub)
	def _end_simulation(s):
		s.interrupt = end_simulation(s)
	fragment = efragment \
		+ peripheral.get_fragment() \
		+ tap.get_fragment() \
		+ Fragment(sim=[_end_simulation])
	sim = Simulator(fragment, Runner())
	sim.run()
コード例 #23
0
ファイル: dma.py プロジェクト: fengxiaoiie/migen
def asmi_sim(efragment, hub, end_simulation):
	def _end_simulation(s):
		s.interrupt = end_simulation(s)
	peripheral = asmibus.Target(MyModelASMI(), hub)
	tap = asmibus.Tap(hub)
	def _end_simulation(s):
		s.interrupt = end_simulation(s)
	fragment = efragment \
		+ peripheral.get_fragment() \
		+ tap.get_fragment() \
		+ Fragment(sim=[_end_simulation])
	sim = Simulator(fragment)
	sim.run()
コード例 #24
0
ファイル: uio.py プロジェクト: larsclausen/migen
def run_sim(ng):
	g = DataFlowGraph()
	d = Dumper(layout)
	g.add_connection(ng, d)
	
	slave = wishbone.Target(SlaveModel())
	intercon = wishbone.InterconnectPointToPoint(ng.buses["wb"], slave.bus)
	
	c = CompositeActor(g)
	fragment = slave.get_fragment() + intercon.get_fragment() + c.get_fragment()
	
	sim = Simulator(fragment)
	sim.run(50)
	del sim
コード例 #25
0
class TestPassCPU(unittest.TestCase):

    def setUp(self):
        self.cpu = PassCPU()
        self.sim = Simulator(self.cpu, TopLevel())

    def tearDown(self):
        self.sim.close()

    def testBasic(self):
        self.sim.wr(self.cpu.a, 1)
        self.sim.run(1)
        self.assertEqual(self.sim.rd(self.cpu.x), 1)
        self.sim.wr(self.cpu.a, 0)
        self.sim.run(1)
        self.assertEqual(self.sim.rd(self.cpu.x), 0)
コード例 #26
0
def main():
	dut = ASMIcon(sdram_phy, sdram_geom, sdram_timing)
	initiator1 = Initiator(my_generator_r(), dut.hub.get_port())
	initiator2 = Initiator(my_generator_w(), dut.hub.get_port())
	dut.finalize()
	
	logger = DFILogger(dut.dfi)
	
	def end_simulation(s):
		s.interrupt = initiator1.done and initiator2.done
	
	fragment = dut.get_fragment() + initiator1.get_fragment() + initiator2.get_fragment() + \
		logger.get_fragment() + \
		Fragment(sim=[end_simulation])
	sim = Simulator(fragment, TopLevel("my.vcd"))
	sim.run(700)
コード例 #27
0
def test_asmi():
	print("*** ASMI test")
	
	# Create a hub with one port for our initiator.
	hub = asmibus.Hub(32, 32)
	port = hub.get_port()
	hub.finalize()
	# Create the initiator, target and tap (similar to the Wishbone case).
	master = asmibus.Initiator(my_generator(), port)
	slave = asmibus.Target(MyModelASMI(), hub)
	tap = asmibus.Tap(hub)
	# Run the simulation (same as the Wishbone case).
	def end_simulation(s):
		s.interrupt = master.done
	fragment = autofragment.from_local() + Fragment(sim=[end_simulation])
	sim = Simulator(fragment)
	sim.run()
コード例 #28
0
def main():
	hub = Hub(12, 128, 2)
	initiator = Initiator(hub.get_port(), my_generator())
	hub.finalize()
	
	dut = BankMachine(sdram_geom, sdram_timing, 2, 0, hub.get_slots())
	logger = CommandLogger(dut.cmd, True)
	completer = Completer(hub, dut.cmd)
	
	def end_simulation(s):
		s.interrupt = initiator.done
	
	fragment = hub.get_fragment() + initiator.get_fragment() + \
		dut.get_fragment() + logger.get_fragment() + completer.get_fragment() + \
		Fragment(sim=[end_simulation])
	sim = Simulator(fragment, TopLevel("my.vcd"))
	sim.run()
コード例 #29
0
ファイル: wb_initiator.py プロジェクト: gyezhz/migen
def main():
	# The "wishbone.Initiator" library component runs our generator
	# and manipulates the bus signals accordingly.
	master = wishbone.Initiator(my_generator())
	# Our slave.
	slave = MyPeripheral()
	# The "wishbone.Tap" library component examines the bus at the slave port
	# and displays the transactions on the console (<TRead...>/<TWrite...>).
	tap = wishbone.Tap(slave.bus)
	# Connect the master to the slave.
	intercon = wishbone.InterconnectPointToPoint(master.bus, slave.bus)
	# A small extra simulation function to terminate the process when
	# the initiator is done (i.e. our generator is exhausted).
	def end_simulation(s):
		s.interrupt = master.done
	fragment = autofragment.from_local() + Fragment(sim=[end_simulation])
	sim = Simulator(fragment, Runner())
	sim.run()
コード例 #30
0
def test_asmi():
    print("*** ASMI test")

    # Create a hub with one port for our initiator.
    hub = asmibus.Hub(32, 32)
    port = hub.get_port()
    hub.finalize()
    # Create the initiator, target and tap (similar to the Wishbone case).
    master = asmibus.Initiator(port, my_generator())
    slave = asmibus.Target(hub, MyModelASMI())
    tap = asmibus.Tap(hub)

    # Run the simulation (same as the Wishbone case).
    def end_simulation(s):
        s.interrupt = master.done

    fragment = autofragment.from_local() + Fragment(sim=[end_simulation])
    sim = Simulator(fragment, Runner())
    sim.run()
コード例 #31
0
ファイル: wb_initiator.py プロジェクト: gyezhz/migen
def main():
    # The "wishbone.Initiator" library component runs our generator
    # and manipulates the bus signals accordingly.
    master = wishbone.Initiator(my_generator())
    # Our slave.
    slave = MyPeripheral()
    # The "wishbone.Tap" library component examines the bus at the slave port
    # and displays the transactions on the console (<TRead...>/<TWrite...>).
    tap = wishbone.Tap(slave.bus)
    # Connect the master to the slave.
    intercon = wishbone.InterconnectPointToPoint(master.bus, slave.bus)

    # A small extra simulation function to terminate the process when
    # the initiator is done (i.e. our generator is exhausted).
    def end_simulation(s):
        s.interrupt = master.done

    fragment = autofragment.from_local() + Fragment(sim=[end_simulation])
    sim = Simulator(fragment, Runner())
    sim.run()
コード例 #32
0
def main():
	hub = Hub(12, 128, 8)
	initiators = [Initiator(hub.get_port(), my_generator(0, 2200*(i//6)+i*10))
		for i in range(8)]
	hub.finalize()
	
	slots = hub.get_slots()
	slicer = _AddressSlicer(sdram_geom, 2)
	logger = SlotsLogger(slicer, slots)
	selector = Selector(slicer, 0, slots)
	completer = Completer(hub, selector.queue)
	
	def end_simulation(s):
		s.interrupt = all([i.done for i in initiators])
	
	fragment = hub.get_fragment() + sum([i.get_fragment() for i in initiators], Fragment()) + \
		logger.get_fragment() + selector.get_fragment() + completer.get_fragment() + \
		Fragment(sim=[end_simulation])
	sim = Simulator(fragment, TopLevel("my.vcd"))
	sim.run()
コード例 #33
0
def main():
	controller = ASMIcon(sdram_phy, sdram_geom, sdram_timing)
	bridge = wishbone2asmi.WB2ASMI(l2_size//4, controller.hub.get_port())
	controller.finalize()
	initiator = wishbone.Initiator(my_generator())
	conn = wishbone.InterconnectPointToPoint(initiator.bus, bridge.wishbone)
	
	logger = DFILogger(controller.dfi)
	
	def end_simulation(s):
		s.interrupt = initiator.done
	
	fragment = controller.get_fragment() + \
		bridge.get_fragment() + \
		initiator.get_fragment() + \
		conn.get_fragment() + \
		logger.get_fragment() + \
		Fragment(sim=[end_simulation])
	sim = Simulator(fragment, TopLevel("my.vcd"))
	sim.run()
コード例 #34
0
ファイル: test_sdramsink.py プロジェクト: wiizzard/ov_ftdi
class SDRAMSinkTest(sim.sdram_test_util.SDRAMUTFramework, unittest.TestCase):
    def setUp(self):
        self.tb = TestBench("mt48lc16m16a2")
        # Verify that all necessary files are present
        files = gather_files(self.tb)
        for i in files:
            if not os.path.exists(i):
                raise FileNotFoundError(
                    "Please download and save the vendor " "SDRAM model in %s (not redistributable)" % i
                )

        runner = icarus.Runner(extra_files=files)
        vcd = "test_%s.vcd" % self.__class__.__name__
        self.sim = Simulator(self.tb, TopLevel(vcd), sim_runner=runner)

    def _run(self):
        with self.sim:
            self.sim.run(10000)

    def test_sdramsink(self):
        self._run()
コード例 #35
0
class SDRAMSinkTest(sim.sdram_test_util.SDRAMUTFramework, unittest.TestCase):
    def setUp(self):
        self.tb = TestBench("mt48lc16m16a2")
        # Verify that all necessary files are present
        files = gather_files(self.tb)
        for i in files:
            if not os.path.exists(i):
                raise FileNotFoundError("Please download and save the vendor "
                                        "SDRAM model in %s (not redistributable)"
                                        % i)

        runner = icarus.Runner(extra_files=files)
        vcd = "test_%s.vcd" % self.__class__.__name__
        self.sim = Simulator(self.tb, TopLevel(vcd), sim_runner=runner) 

    def _run(self):
        with self.sim:
            self.sim.run(10000)
    
    def test_sdramsink(self):
        self._run()
コード例 #36
0
def main():
	# Create a simple dataflow system
	receiver_layout = [
		("i0", width),
		("q0", width),
		("i1", width),
		("q1", width)
	]
	wg_i = CSRWG(0, depth, width, 2)
	wg_q = CSRWG(0, depth, width, 2)
	sink = SimActor(receiver(), ("sample", Sink, receiver_layout))
	g = DataFlowGraph()
	g.add_connection(wg_i, sink, sink_subr=["i0", "i1"])
	g.add_connection(wg_q, sink, sink_subr=["q0", "q1"])
	comp = CompositeActor(g)
	
	# CSR programmer and interconnect
	csr_i_prog = csr.Initiator(programmer(values_i, received_values_i))
	csr_i_intercon = csr.Interconnect(csr_i_prog.bus, [wg_i.bank.bus])
	csr_q_prog = csr.Initiator(programmer(values_q, received_values_q))
	csr_q_intercon = csr.Interconnect(csr_q_prog.bus, [wg_q.bank.bus])

	# Run the simulation until the CSR programmer finishes
	def end_simulation(s):
		s.interrupt = csr_i_prog.done and csr_q_prog.done
	frag = comp.get_fragment() \
		+ csr_i_prog.get_fragment() + csr_i_intercon.get_fragment() \
		+ csr_q_prog.get_fragment() + csr_q_intercon.get_fragment() \
		+ Fragment(sim=[end_simulation])
	sim = Simulator(frag)
	sim.run()
	
	# Check correctness of the first received values
	assert(received_values_i[:depth] == values_i)
	assert(received_values_q[:depth] == values_q)
	
	# Plot waveform
	plt.plot(received_values_i)
	plt.plot(received_values_q)
	plt.show()
コード例 #37
0
ファイル: dataflow_dma.py プロジェクト: gyezhz/migen
def test_reader():
    print("*** Testing reader")
    adrgen = SimActor(adrgen_gen(), ("address", Source, [("a", BV(30))]))
    reader = dma_wishbone.Reader()
    dumper = SimActor(dumper_gen(), ("data", Sink, [("d", BV(32))]))
    g = DataFlowGraph()
    g.add_connection(adrgen, reader)
    g.add_connection(reader, dumper)
    comp = CompositeActor(g)

    peripheral = MyPeripheral()
    interconnect = wishbone.InterconnectPointToPoint(reader.bus, peripheral.bus)

    def end_simulation(s):
        s.interrupt = adrgen.done and not s.rd(comp.busy)

    fragment = (
        comp.get_fragment() + peripheral.get_fragment() + interconnect.get_fragment() + Fragment(sim=[end_simulation])
    )

    sim = Simulator(fragment, Runner())
    sim.run()
コード例 #38
0
ファイル: test_consumer.py プロジェクト: zhangjinxing/ov_ftdi
class TestConsumer(unittest.TestCase):
    def setUp(self):
        self.tb = TestBench()
        self.sim = Simulator(self.tb)

    def _run(self):
        with self.sim:
            self.sim.run(200)

    def testConsumer2(self):
        tests = [
            {"start":0,   "count":  4},
            {"start":555, "count": 77}
        ]

        def srcgen():
            for t in tests:
                yield Token('source', t)
                yield

        def sinkgen():
            for test in tests:
                for n, ck in enumerate(range(
                    test["start"], test["start"] + test["count"])):
                    last = n == test["count"] - 1

                    t = Token("sink", idle_wait=True)
                    yield t
                    
                    self.assertEqual(t.value['d'], ck & 0xFF)
                    self.assertEqual(t.value['last'], last)
                    self.last = t.value

        self.tb.setSeq(srcgen(), sinkgen())

        self._run()

        self.assertEqual(self.last, {"d":119, "last":1})
コード例 #39
0
ファイル: dataflow_dma.py プロジェクト: gyezhz/migen
def test_writer():
	print("*** Testing writer")
	trgen = SimActor(trgen_gen(), ("address_data", Source, [("a", BV(30)), ("d", BV(32))]))
	writer = dma_wishbone.Writer()
	g = DataFlowGraph()
	g.add_connection(trgen, writer)
	comp = CompositeActor(g)
	
	peripheral = MyPeripheral()
	tap = wishbone.Tap(peripheral.bus)
	interconnect = wishbone.InterconnectPointToPoint(writer.bus, peripheral.bus)
	
	def end_simulation(s):
		s.interrupt = trgen.done and not s.rd(comp.busy)
	
	fragment = comp.get_fragment() \
		+ peripheral.get_fragment() \
		+ tap.get_fragment() \
		+ interconnect.get_fragment() \
		+ Fragment(sim=[end_simulation])
	
	sim = Simulator(fragment, Runner())
	sim.run()
コード例 #40
0
ファイル: dataflow_dma.py プロジェクト: gyezhz/migen
def test_reader():
	print("*** Testing reader")
	adrgen = SimActor(adrgen_gen(), ("address", Source, [("a", BV(30))]))
	reader = dma_wishbone.Reader()
	dumper = SimActor(dumper_gen(), ("data", Sink, [("d", BV(32))]))
	g = DataFlowGraph()
	g.add_connection(adrgen, reader)
	g.add_connection(reader, dumper)
	comp = CompositeActor(g)
	
	peripheral = MyPeripheral()
	interconnect = wishbone.InterconnectPointToPoint(reader.bus, peripheral.bus)
	
	def end_simulation(s):
		s.interrupt = adrgen.done and not s.rd(comp.busy)
	
	fragment = comp.get_fragment() \
		+ peripheral.get_fragment() \
		+ interconnect.get_fragment() \
		+ Fragment(sim=[end_simulation])
	
	sim = Simulator(fragment, Runner())
	sim.run()
コード例 #41
0
def main():
    # Compute filter coefficients with SciPy.
    coef = signal.remez(80, [0, 0.1, 0.1, 0.5], [1, 0])
    fir = FIR(coef)

    # Simulate for different frequencies and concatenate
    # the results.
    in_signals = []
    out_signals = []
    for frequency in [0.05, 0.07, 0.1, 0.15, 0.2]:
        tb = TB(fir, frequency)
        fragment = autofragment.from_local()
        sim = Simulator(fragment, Runner())
        sim.run(100)
        in_signals += tb.inputs
        out_signals += tb.outputs

    # Plot data from the input and output waveforms.
    plt.plot(in_signals)
    plt.plot(out_signals)
    plt.show()

    # Print the Verilog source for the filter.
    print(verilog.convert(fir.get_fragment(), ios={fir.i, fir.o}))
コード例 #42
0
ファイル: leds.py プロジェクト: zozo123/ov_ftdi
def main():
    tb = TB()
    sim = Simulator(tb)
    sim.run()
コード例 #43
0
def main():
    dut = Mem()
    sim = Simulator(dut.get_fragment(), Runner())
    # No need for a cycle limit here, we use sim.interrupt instead.
    sim.run()
コード例 #44
0
def main():
    dut = Counter()
    # Instantiating the generic top-level ourselves lets us
    # specify a VCD output file.
    sim = Simulator(dut.get_fragment(), Runner(), TopLevel("my.vcd"))
    sim.run(20)
コード例 #45
0
ファイル: echo.py プロジェクト: jix/ezusbfifo
            NET "{clk_ezusbfifo}" TNM_NET = "GRP_clk_ezusbfifo";

            TIMESPEC "TS_cdc_fwd" =
                FROM "GRP_clk_sys" TO "GRP_clk_ezusbfifo"
                [delay] ns DATAPATHONLY;
            TIMESPEC "TS_cdc_bwd" =
                FROM "GRP_clk_ezusbfifo" TO "GRP_clk_sys"
                [delay] ns DATAPATHONLY;

            OFFSET = IN 15 ns VALID 30 ns BEFORE "{clk_if}";
            OFFSET = OUT 15 ns AFTER "{clk_if}";
            """.replace('[delay]',
                        str(0.5 * 33.33 * fraction[1] / fraction[0])),
            clk_if=clk_if,
            clk_sys=clk_sys,
            clk_ezusbfifo=clk_ezusbfifo,
        )

        plat.build_cmdline(echo)
    elif command == 'sim':
        from migen.sim.generic import Simulator, TopLevel

        echo = Echo(SimUSBActor(loop=True))

        sim = Simulator(echo, TopLevel("echo.vcd"))

        with sim:
            sim.run()
    else:
        print('usage: python %s build|sim [options]' % sys.argv[0])
コード例 #46
0
ファイル: cfilt.py プロジェクト: zhangjinxing/ov_ftdi
        self.byte_list = [(1,0x40), (0,0xCA), (1,0x10), (0, 0xFE), (1, 0x41)]

    def do_simulation(self, s):
        if s.cycle_counter > 5 and s.cycle_counter %2 and self.byte_list:
            b = self.byte_list[0]
            print("WR %s" % repr(b))
            self.byte_list = self.byte_list[1:]

            s.wr(self.tr.sink.stb, 1) 
            s.wr(self.tr.sink.payload.d, b[1])
            s.wr(self.tr.sink.payload.rxcmd, b[0])
        else:
            s.wr(self.tr.sink.stb,0)
    

        if s.rd(self.tr.source.stb):
            print("%02x %d" % (s.rd(self.tr.source.payload.d), s.rd(self.tr.source.payload.rxcmd)))


        
if __name__ == "__main__":
    from migen.sim.generic import Simulator, TopLevel

    tl = TopLevel("sdram.vcd")

    test = TestFilt(tl.clock_domains[0])
    sim = Simulator(test, tl)
    sim.run(500)

コード例 #47
0
ファイル: whacker.py プロジェクト: ymz000/ov_ftdi
            for i in packet(10, 0x20, 4):
                yield i

            for i in packet(10, 0x30, 2):
                yield i

        class SimSource(SimActor):
            def __init__(self):
                self.source = Endpoint(ULPI_DATA_D)
                SimActor.__init__(self, gen())

        self.submodules.w = Whacker(1024)

        self.submodules.src = SimSource()
        self.comb += self.src.source.connect(self.w.sink)
        self.comb += self.src.busy.eq(0)

        self.submodules.dmp = Dumper(D_LAST)
        self.comb += self.w.source.connect(self.dmp.result)
        self.comb += self.dmp.busy.eq(0)


if __name__ == '__main__':
    from migen.sim.generic import Simulator, TopLevel
    from migen.sim.icarus import Runner
    tl = TopLevel("testwhacker.vcd")
    tl.clock_domains[0].name_override = 'sys_clk'
    test = TestWhacker()
    sim = Simulator(test, tl, Runner(keep_files=True))
    sim.run(2000)