simplesoc_ecp5: add simulation
This commit is contained in:
parent
83ffe66f70
commit
75e9310097
@ -2,7 +2,7 @@ import argparse
|
|||||||
import struct
|
import struct
|
||||||
|
|
||||||
from nmigen import *
|
from nmigen import *
|
||||||
from nmigen.back import rtlil
|
from nmigen.back import rtlil, pysim
|
||||||
|
|
||||||
from heavycomps import uart, wishbone
|
from heavycomps import uart, wishbone
|
||||||
from minerva.core import Minerva
|
from minerva.core import Minerva
|
||||||
@ -27,8 +27,9 @@ class SimpleWishboneSerial(Elaboratable):
|
|||||||
|
|
||||||
|
|
||||||
class Top(Elaboratable):
|
class Top(Elaboratable):
|
||||||
def __init__(self, firmware):
|
def __init__(self, firmware, create_clock):
|
||||||
self.clk100 = Signal()
|
if create_clock:
|
||||||
|
self.clk100 = Signal()
|
||||||
self.led = Signal()
|
self.led = Signal()
|
||||||
self.serial_tx = Signal()
|
self.serial_tx = Signal()
|
||||||
self.firmware = firmware
|
self.firmware = firmware
|
||||||
@ -36,9 +37,10 @@ class Top(Elaboratable):
|
|||||||
def elaborate(self, platform):
|
def elaborate(self, platform):
|
||||||
m = Module()
|
m = Module()
|
||||||
|
|
||||||
cd_sync = ClockDomain(reset_less=True)
|
if hasattr(self, "clk100"):
|
||||||
m.domains += cd_sync
|
cd_sync = ClockDomain(reset_less=True)
|
||||||
m.d.comb += cd_sync.clk.eq(self.clk100)
|
m.domains += cd_sync
|
||||||
|
m.d.comb += cd_sync.clk.eq(self.clk100)
|
||||||
|
|
||||||
counter = Signal(27)
|
counter = Signal(27)
|
||||||
m.d.sync += counter.eq(counter + 1)
|
m.d.sync += counter.eq(counter + 1)
|
||||||
@ -64,23 +66,31 @@ def read_firmware(file):
|
|||||||
word = f.read(4)
|
word = f.read(4)
|
||||||
if len(word) < 4:
|
if len(word) < 4:
|
||||||
break
|
break
|
||||||
firmware.append(struct.unpack(">I", word)[0])
|
firmware.append(struct.unpack("<I", word)[0])
|
||||||
return firmware
|
return firmware
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--simulate", action="store_true")
|
||||||
parser.add_argument("firmware_bin")
|
parser.add_argument("firmware_bin")
|
||||||
parser.add_argument("output_file")
|
parser.add_argument("output_file")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
firmware = read_firmware(args.firmware_bin)
|
firmware = read_firmware(args.firmware_bin)
|
||||||
|
top = Top(firmware, create_clock=not args.simulate)
|
||||||
|
|
||||||
top = Top(firmware)
|
if args.simulate:
|
||||||
output = rtlil.convert(Fragment.get(top, None),
|
with pysim.Simulator(top,
|
||||||
ports=(top.clk100, top.led, top.serial_tx))
|
vcd_file=open(args.output_file + ".vcd", "w"),
|
||||||
with open(args.output_file, "w") as f:
|
gtkw_file=open(args.output_file + ".gtkw", "w")) as sim:
|
||||||
f.write(output)
|
sim.add_clock(1e-6)
|
||||||
|
sim.run_until(100e-6, run_passive=True)
|
||||||
|
else:
|
||||||
|
output = rtlil.convert(Fragment.get(top, None),
|
||||||
|
ports=(top.clk100, top.led, top.serial_tx))
|
||||||
|
with open(args.output_file, "w") as f:
|
||||||
|
f.write(output)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user