From 0fcd9f486508363072d1050ddfb7ef5637fb12e7 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Wed, 12 May 2021 14:45:58 +0200 Subject: [PATCH] add module example --- modules.py | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 modules.py diff --git a/modules.py b/modules.py new file mode 100644 index 0000000..de62405 --- /dev/null +++ b/modules.py @@ -0,0 +1,83 @@ +# +# Copyright (c) 2019 -2021 MINRES Technolgies GmbH +# +# SPDX-License-Identifier: Apache-2.0 +# + +import os.path +import logging +import cppyy +from cppyy import gbl as cpp +import pysysc +from pysysc.structural import Connection, Module, Signal, Simulation + +############################################################################### +# setup and load +############################################################################### +logging.basicConfig(level=logging.DEBUG) +build_type='Debug' +############################################################################### +myDir = os.path.dirname( os.path.realpath(__file__)) +pysysc.read_config_from_conan(os.path.join(myDir, 'conanfile.txt'), build_type) +pysysc.load_systemc() +############################################################################### +logging.debug("Loading SC-Components lib") +pysysc.add_include_path(os.path.join(myDir, 'scc/incl')) +pysysc.add_library('scc.h', os.path.join(myDir, 'build/%s/lib/libscc.so'%build_type)) +############################################################################### +logging.debug("Loading Components lib") +pysysc.add_include_path(os.path.join(myDir, 'components')) +pysysc.add_library('components.h', os.path.join(myDir, 'build/%s/lib/libcomponents.so'%build_type)) + +############################################################################### +# define toplevel class +############################################################################### +num_of_mem = 4 + +class TopModule(cpp.scc.PyScModule): + + def __init__(self, name): + super().__init__(self, name) + ############################################################################### + # instantiate + ############################################################################### + self.clk_gen = Module(cpp.ClkGen).create("clk_gen") + self.rst_gen = Module(cpp.ResetGen).create("rst_gen") + self.initiator = Module(cpp.Initiator).create("initiator") + self.memories = [Module(cpp.Memory).create("mem%d"%idx) for idx in range(0,num_of_mem)] + self.router = Module(cpp.Router[num_of_mem]).create("router") + ############################################################################### + # connect them + ############################################################################### + self.clk = Signal("clk").src(self.clk_gen.clk_o).sink(self.initiator.clk_i).sink(self.router.clk_i) + [self.clk.sink(m.clk_i) for m in self.memories] + self.rst = Signal("rst").src(self.rst_gen.reset_o).sink(self.initiator.reset_i).sink(self.router.reset_i) + [self.rst.sink(m.reset_i) for m in self.memories] + Connection().src(self.initiator.socket).sink(self.router.target_socket) + [Connection().src(self.router.initiator_socket.at(idx)).sink(m.socket) for idx,m in enumerate(self.memories)] + + def EndOfElaboration(self): + print("Elaboration finished") + + def StartOfSimulation(self): + print("Simulation started") + + def EndOfSimulation(self): + print("Simulation finished") + +############################################################################### +# configure +############################################################################### +Simulation.setup(logging.root.level) +############################################################################### +# instantiate +############################################################################### +#from modules import TopModule +dut = Module(TopModule).create("dut") +############################################################################### +# run if it is standalone +############################################################################### +if __name__ == "__main__": + Simulation.configure(enable_vcd=False) + Simulation.run() + logging.debug("Done")