--- /dev/null
+#!/usr/bin/env python3
+
+import argparse
+import importlib
+
+from litex.gen import *
+from litex.boards.platforms import sim
+from litex.gen.genlib.io import CRG
+
+from litex.soc.integration.soc_core import *
+from litex.soc.integration.builder import *
+from litex.soc.cores import uart
+
+
+class BaseSoC(SoCCore):
+ def __init__(self, **kwargs):
+ platform = sim.Platform()
+ SoCCore.__init__(self, platform,
+ clk_freq=int((1/(platform.default_clk_period))*1000000000),
+ integrated_rom_size=0x8000,
+ integrated_main_ram_size=16*1024,
+ with_uart=False,
+ **kwargs)
+ self.submodules.crg = CRG(platform.request(platform.default_clk_name))
+
+ self.submodules.uart_phy = uart.RS232PHYModel(platform.request("serial"))
+ self.submodules.uart = uart.UART(self.uart_phy)
+
+
+def main():
+ parser = argparse.ArgumentParser(description="Generic LiteX SoC Simulation")
+ builder_args(parser)
+ soc_core_args(parser)
+ args = parser.parse_args()
+
+ soc = BaseSoC(**soc_core_argdict(args))
+ builder = Builder(soc, **builder_argdict(args))
+ builder.build()
+
+
+if __name__ == "__main__":
+ main()
from litex.build.generic_platform import *
+sim_directory = os.path.abspath(os.path.dirname(__file__))
+
+
def _build_tb(platform, vns, serial, template):
def io_name(resource, subsignal=None):
res = platform.lookup_request(resource)
tools.write_to_file("dut_tb.cpp", content)
-def _build_sim(platform, vns, build_name, include_paths, sim_path, serial, verbose):
+def _build_sim(platform, vns, build_name, include_paths, serial, verbose):
include = ""
for path in include_paths:
include += "-I"+path+" "
build_script_file = "build_" + build_name + ".sh"
tools.write_to_file(build_script_file, build_script_contents, force_unix=True)
- _build_tb(platform, vns, serial, os.path.join("..", sim_path, "dut_tb.cpp"))
+ _build_tb(platform, vns, serial, os.path.join(sim_directory, "dut_tb.cpp"))
if verbose:
r = subprocess.call(["bash", build_script_file])
else:
class SimVerilatorToolchain:
- # XXX fir sim_path
def build(self, platform, fragment, build_dir="build", build_name="top",
- sim_path="../migen/migen/build/sim/", serial="console",
- run=True, verbose=False):
+ serial="console", run=True, verbose=False):
tools.mkdir_noerror(build_dir)
os.chdir(build_dir)
if path not in include_paths:
include_paths.append(path)
include_paths += platform.verilog_include_paths
- _build_sim(platform, v_output.ns, build_name, include_paths, sim_path, serial, verbose)
+ _build_sim(platform, v_output.ns, build_name, include_paths, serial, verbose)
if run:
_run_sim(build_name)
self.sink, self.source = self.tx.sink, self.rx.source
+class RS232PHYModel(Module):
+ def __init__(self, pads):
+ self.sink = Sink([("data", 8)])
+ self.source = Source([("data", 8)])
+
+ self.comb += [
+ pads.source_stb.eq(self.sink.stb),
+ pads.source_data.eq(self.sink.data),
+ self.sink.ack.eq(pads.source_ack),
+
+ self.source.stb.eq(pads.sink_stb),
+ self.source.data.eq(pads.sink_data),
+ pads.sink_ack.eq(self.source.ack)
+ ]
+
+
def _get_uart_fifo(depth, sink_cd="sys", source_cd="sys"):
if sink_cd != source_cd:
fifo = AsyncFIFO([("data", 8)], depth)