Esempio n. 1
0
    import sys
    from nmigen_boards.tinyfpga_bx import TinyFPGABXPlatform

    clk_freq = 16e6
    spi_freq = 2e6
    clk_per_bit = int(clk_freq // spi_freq)

    if len(sys.argv) < 2 or sys.argv[1] == "sim":
        m = Module()

        m.submodules.loopback = loopback = SpiMaster(clk_per_bit, 8)

        m.d.comb += loopback.miso.eq(loopback.mosi)

        sim = sim.Simulator(m)
        sim.add_clock(1.0 / clk_freq)

        sim.add_sync_process(_test_loopback(loopback))

        with sim.write_vcd("spi.vcd", "spi.gtkw", traces=loopback.ports()):
            sim.run()
            # while sim.advance():
            #     input("ENTER to continue...")
    elif sys.argv[1] == "build":
        class Board(TinyFPGABXPlatform):
            p = "p1"

        class SpiTest(Elaboratable):
            def __init__(self):
                pass
Esempio n. 2
0
 def run(fragment, process):
     sim = nmigen.sim.Simulator(fragment)
     sim.add_sync_process(process)
     sim.add_clock(1 / 10e6)
     with sim.write_vcd(vcd_path(request.node)):
         sim.run()