develop #2

Merged
eyck merged 4 commits from develop into master 2021-11-28 14:48:37 +01:00
23 changed files with 186 additions and 215 deletions

View File

@ -51,7 +51,9 @@
</win32>
<defs>
<def name="BUILD_SHARED_LIBS" type="BOOL" val="ON"/>
<def name="CMAKE_BUILD_TYPE" type="STRING" val="${config_name}"/>
</defs>
<undefs/>
</storageModule>
</cconfiguration>
<cconfiguration id="cdt.managedbuild.toolchain.gnu.base.1318364290.125067248">

View File

@ -1,10 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_ADDITIONAL_GRAMMAR_VALIDATION">3.6</pydev_property>
</pydev_project>

View File

@ -3,12 +3,9 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${C
project(pysysc-sc)
set(ENABLE_SCV TRUE CACHE BOOL "Enable use of SCV")
set(ENABLE_SHARED TRUE CACHE BOOL "Build shared libraries")
include(GNUInstallDirs)
include(Conan)
include(BuildType)
include(clang-format)
@ -35,14 +32,60 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(warnings "/W4 /WX /EHsc")
endif()
setup_conan()
include(ConanInline)
conan_check()
set(CONAN_BOOST_OPTIONS
boost:fPIC=True
boost:shared=True
boost:header_only=False
boost:without_context=True
boost:without_contract=True
boost:without_coroutine=True
boost:without_fiber=True
boost:without_graph=True
boost:without_graph_parallel=True
boost:without_iostreams=True
boost:without_json=True
boost:without_locale=True
boost:without_log=True
boost:without_math=True
boost:without_mpi=True
boost:without_nowide=True
boost:without_python=True
boost:without_random=True
boost:without_regex=True
boost:without_serialization=True
boost:without_stacktrace=True
boost:without_test=True
boost:without_timer=True
boost:without_type_erasure=True
boost:without_wave=True
)
set(CONAN_PACKAGES boost/1.75.0)
set(CONAN_SETTINGS ${CONAN_BOOST_OPTIONS})
if(NOT DEFINED ENV{SYSTEMC_HOME})
set(CONAN_PACKAGES ${CONAN_PACKAGES}
systemc/2.3.3
systemc-cci/1.0.0
)
set(CONAN_SETTINGS ${CONAN_SETTINGS}
#systemc:phase_cb=False
systemc-cci:shared=False
)
endif()
conan_configure(REQUIRES ${CONAN_PACKAGES}
GENERATORS cmake_find_package
OPTIONS ${CONAN_SETTINGS}
)
conan_install()
conan_setup(TARGETS)
# This line finds the boost lib and headers.
set(Boost_NO_BOOST_CMAKE ON) # Don't do a find_package in config mode before searching for a regular boost install.
find_package(Boost COMPONENTS program_options system thread REQUIRED)
# set-up SystemC and SCV
find_package(OSCISystemC)
include(SystemCPackage)
if(SystemC_FOUND)
include_directories(${SystemC_INCLUDE_DIRS})
link_directories(${SystemC_LIBRARY_DIRS})
@ -58,7 +101,7 @@ if(CCI_FOUND)
endif()
add_subdirectory(scc)
add_subdirectory(components)
add_subdirectory(vp_components)
add_subdirectory(top)
# CTest is a testing tool that can be used to test your project.

View File

@ -8,8 +8,6 @@ A simple C++/SystemC/CMake project to test pysysc
```
pip install conan
conan remote add minres https://api.bintray.com/conan/minres/conan-repo
cd PySysC-SC
mkdir build
cd build
@ -18,15 +16,4 @@ cmake -DBUILD_SHARED_LIBS=ON ..
cmake --build .
```
## Notes
If you encounter issues when linking wrt. c++11 symbols you might have run into GCC ABI incompatibility introduced from GCC 5.0 onwards. You can fix this by adding '-s compiler.libcxx=libstdc++11' to the conan call or changing compiler.libcxx to
```
compiler.libcxx=libstdc++11
```
in $HOME/.conan/profiles/default or run
```
conan profile update settings.compiler.libcxx=libstdc++11 default
```

View File

@ -1,115 +0,0 @@
/*
* logging.cpp
*
* Created on: 24.12.2018
* Author: eyck
*/
#include <systemc>
#include <deque>
#include <array>
#include <sstream>
#include <iomanip>
#include "logging_.h"
using namespace sc_core;
enum log_level {NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE};
namespace {
static std::deque<std::string> msg_buf;
inline log_level verbosity2log(int verb) {
if (verb >= sc_core::SC_FULL) return TRACE;
if (verb >= sc_core::SC_HIGH) return DEBUG;
return INFO;
}
std::string time2string(const sc_core::sc_time &t) {
const std::array<const char *, 6> time_units{"fs", "ps", "ns", "us", "ms", "s "};
const std::array<uint64_t, 6> multiplier{1ULL,
1000ULL,
1000ULL * 1000,
1000ULL * 1000 * 1000,
1000ULL * 1000 * 1000 * 1000,
1000ULL * 1000 * 1000 * 1000 * 1000};
std::ostringstream oss;
const sc_core::sc_time_tuple tt{t};
const auto val = tt.value();
if (!val) {
oss << "0 s";
} else {
const unsigned scale = tt.unit();
const auto fs_val = val * multiplier[scale];
for (int j = multiplier.size() - 1; j >= scale; --j) {
if (fs_val > multiplier[j]) {
const auto i = val / multiplier[j - scale];
const auto f = val % multiplier[j - scale];
oss << i << '.' << std::setw(3 * (j - scale)) << std::setfill('0') << std::left << f << ' '
<< time_units[j];
break;
}
}
}
return oss.str();
}
const std::string compose_message(const sc_report &rep) {
std::stringstream os;
os << "[" << std::setw(20) << time2string(sc_core::sc_time_stamp()) << "] ";
if (rep.get_id() >= 0)
os << "("
<< "IWEF"[rep.get_severity()] << rep.get_id() << ") ";
os << rep.get_msg_type();
if (*rep.get_msg()) os << ": " << rep.get_msg();
if (rep.get_severity() > SC_INFO) {
std::array<char, 16> line_number_str;
os << " [FILE:" << rep.get_file_name() << ":" << rep.get_line_number() << "]";
sc_simcontext *simc = sc_get_curr_simcontext();
if (simc && sc_is_running()) {
const char *proc_name = rep.get_process_name();
if (proc_name) os << "[PROCESS:" << proc_name << "]";
}
}
return os.str();
}
void report_handler(const sc_report &rep, const sc_actions &actions) {
std::array<const log_level, 4> map = {{INFO, WARNING, ERROR, FATAL}};
if (actions & SC_DISPLAY) {
auto level = rep.get_severity() > sc_core::SC_INFO ? map[rep.get_severity()] : verbosity2log(rep.get_verbosity());
msg_buf.push_back(compose_message(rep));
}
if (actions & SC_STOP) sc_stop();
if (actions & SC_ABORT) abort();
if (actions & SC_THROW) throw rep;
}
}
bool has_output(){
return !msg_buf.empty();
}
std::string get_output(){
std::string ret = msg_buf.front();
msg_buf.pop_front();
return ret;
}
void init_logging(unsigned level) {
const std::array<int, 8> verbosity = {SC_NONE, // Logging::NONE
SC_LOW, // Logging::FATAL
SC_LOW, // Logging::ERROR
SC_LOW, // Logging::WARNING
SC_MEDIUM, // Logging::INFO
SC_HIGH, // logging::DEBUG
SC_FULL, // logging::TRACE
SC_DEBUG}; // logging::TRACE+1
sc_report_handler::set_verbosity_level(verbosity[level]);
sc_report_handler::set_handler(report_handler);
}

View File

@ -1,42 +0,0 @@
/*
* logging.h
*
* Created on: 24.12.2018
* Author: eyck
*/
#ifndef LOGGING_H_
#define LOGGING_H_
#include <string>
#include <sstream>
#include <systemc.h>
bool has_output();
std::string get_output();
void init_logging(unsigned level);
class Log {
public:
Log(const char* file, int line):messageLevel(sc_core::SC_INFO), file(file), line(line){};
Log(const Log&) = delete;
Log& operator =(const Log&) = delete;
virtual ~Log(){
::sc_core::sc_report_handler::report(messageLevel, "", os.str().c_str(), file, line );
}
std::ostringstream& Get(sc_core::sc_severity level = sc_core::SC_INFO){
messageLevel = level;
return os;
}
protected:
std::ostringstream os;
sc_core::sc_severity messageLevel;
const char* file;
int line;
};
#define LOG(level) Log(__FILE__, __LINE__).Get(level)
#define LOG_INFO Log(__FILE__, __LINE__).Get(sc_core::SC_INFO)
#define LOG_WARN Log(__FILE__, __LINE__).Get(sc_core::SC_WARNING)
#define LOG_ERR Log(__FILE__, __LINE__).Get(sc_core::SC_ERROR)
#endif /* LOGGING_H_ */

View File

@ -1,12 +0,0 @@
[requires]
SystemC/2.3.3@minres/stable
SystemC-CCI/1.0.0@minres/stable
[generators]
cmake
[options]
SystemC:stdcxx=11
SystemC:shared=True
SystemC-CCI:stdcxx=11
SystemC-CCI:shared=True

100
modules.py Normal file
View File

@ -0,0 +1,100 @@
#
# 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, 'build/%s/conanfile.txt'%build_type), 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))
pysysc.add_include_path(os.path.join(myDir, 'scc/src/common'))
pysysc.add_library('scc_util.h', os.path.join(myDir, 'build/%s/scc/src/common/libscc-util.so'%build_type))
pysysc.add_include_path(os.path.join(myDir, 'scc/third_party'))
pysysc.add_include_path(os.path.join(myDir, 'scc/third_party/scv-tr/src'))
pysysc.add_library('scv-tr.h', os.path.join(myDir, 'build/%s/scc/third_party/scv-tr/src/libscv-tr.so'%build_type))
pysysc.add_include_path(os.path.join(myDir, 'scc/src/sysc'))
pysysc.add_library('scc_sysc.h', os.path.join(myDir, 'build/%s/scc/src/sysc/libscc-sysc.so'%build_type))
pysysc.add_include_path(os.path.join(myDir, 'scc/src/components'))
cppyy.include('scc_components.h')
###############################################################################
logging.debug("Loading Components lib")
pysysc.add_include_path(os.path.join(myDir, 'vp_components'))
pysysc.add_library('components.h', os.path.join(myDir, 'build/%s/vp_components/libvp_components.so'%build_type))
###############################################################################
# define toplevel class
###############################################################################
num_of_mem = 4
from pysysc.sysc import ScModule
class TopModule(ScModule):
def __init__(self, name):
ScModule.__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)]
self.ScThread("RunThread")
def EndOfElaboration(self):
print("Elaboration finished")
def StartOfSimulation(self):
print("Simulation started")
def EndOfSimulation(self):
print("Simulation finished")
def RunThread(self):
print("Starting RunThread")
while(cpp.sc_core.sc_time_stamp()<cpp.sc_core.sc_time(500, cpp.sc_core.SC_NS)):
#self.pyScWait(self.clk.signal.value_changed_event())
self.ScWait(cpp.sc_core.sc_time(100, cpp.sc_core.SC_NS))
print("Hello from Thread %s, @ %s"%(self.name(), cpp.sc_core.sc_time_stamp().to_string()))
###############################################################################
# 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")

View File

@ -9,22 +9,22 @@ build_type='Debug'
logging.basicConfig(level=logging.DEBUG)
###############################################################################
myDir = os.path.dirname( os.path.realpath(__file__))
res=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))
pysysc.add_include_path(os.path.join(myDir, 'scc/src/sysc'))
pysysc.add_include_path(os.path.join(myDir, 'scc/src/common'))
pysysc.add_include_path(os.path.join(myDir, 'scc/third_party'))
pysysc.add_library('scc_sysc.h', os.path.join(myDir, 'build/%s/scc/src/sysc/libscc-sysc.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))
pysysc.add_include_path(os.path.join(myDir, 'vp_components'))
pysysc.add_library('components.h', os.path.join(myDir, 'build/%s/vp_components/libvp_components.so'%build_type))
###############################################################################
# configure
###############################################################################
cpp.scc.init_logging(cpp.scc.log.INFO, 24, False);
cpp.sc_core.sc_report_handler.set_actions(cpp.sc_core.SC_ID_MORE_THAN_ONE_SIGNAL_DRIVER_, cpp.sc_core.SC_DO_NOTHING);
cpp.scc.init_cci("GlobalBroker")
###############################################################################
# instantiate
###############################################################################

View File

@ -12,16 +12,17 @@ logging.basicConfig(level=logging.INFO)
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))
pysysc.add_include_path(os.path.join(myDir, 'scc/src/sysc'))
pysysc.add_include_path(os.path.join(myDir, 'scc/src/common'))
pysysc.add_include_path(os.path.join(myDir, 'scc/third_party'))
pysysc.add_library('scc_sysc.h', os.path.join(myDir, 'build/%s/scc/src/sysc/libscc-sysc.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))
pysysc.add_include_path(os.path.join(myDir, 'vp_components'))
pysysc.add_library('components.h', os.path.join(myDir, 'build/%s/vp_components/libvp_components.so'%build_type))
###############################################################################
# configure
###############################################################################

2
scc

@ -1 +1 @@
Subproject commit 385eed07957bed93669ae6c453d706414e95aebc
Subproject commit 1b28dadcb3510550fea0d7c383511e502bae2582

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.3)
set(APP_NAME top)
add_executable(${APP_NAME} sc_main.cpp)
target_link_libraries (${APP_NAME} LINK_PUBLIC components)
target_link_libraries (${APP_NAME} LINK_PUBLIC vp_components)

View File

@ -1,14 +1,13 @@
set(LIB_SOURCES
initiator.cpp
logging.cpp
target.cpp
clkgen.cpp
resetgen.cpp
)
# Define two variables in order not to repeat ourselves.
set(LIBRARY_NAME components)
set(LIBRARY_NAME vp_components)
# Define the library
add_library(${LIBRARY_NAME} SHARED ${LIB_SOURCES})
target_link_libraries (${LIBRARY_NAME} LINK_PUBLIC scc)
target_include_directories (components PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories (${LIBRARY_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

View File

@ -5,8 +5,8 @@
* Author: eyck
*/
#ifndef COMPONENTS_CLKGEN_H_
#define COMPONENTS_CLKGEN_H_
#ifndef VP_COMPONENTS_CLKGEN_H_
#define VP_COMPONENTS_CLKGEN_H_
#include <systemc>
@ -20,4 +20,4 @@ protected:
void end_of_elaboration() override;
};
#endif /* COMPONENTS_CLKGEN_H_ */
#endif /* VP_COMPONENTS_CLKGEN_H_ */

View File

@ -55,7 +55,7 @@ void Initiator::thread_process() {
wait( dmi_data.get_write_latency() );
}
SCCINFO() << "DMI = { " << (cmd ? 'W' : 'R') << ", " << hex << i
SCCDEBUG() << "DMI = { " << (cmd ? 'W' : 'R') << ", " << hex << i
<< " } , data = " << hex << data << " at time " << sc_time_stamp();
}
else
@ -101,7 +101,7 @@ void Initiator::thread_process() {
dmi_ptr_valid = socket->get_direct_mem_ptr( *trans, dmi_data );
}
SCCINFO() << "trans = { " << (cmd ? 'W' : 'R') << ", " << hex << i
SCCDEBUG() << "trans = { " << (cmd ? 'W' : 'R') << ", " << hex << i
<< " } , data = " << hex << data << " at time " << sc_time_stamp();
}
}
@ -119,7 +119,7 @@ void Initiator::thread_process() {
for (unsigned int i = 0; i < n_bytes; i += 4)
{
SCCINFO() << "mem[" << (A + i) << "] = "
SCCTRACE() << "mem[" << (A + i) << "] = "
<< *(reinterpret_cast<unsigned int*>( &data[i] ));
}
@ -131,7 +131,7 @@ void Initiator::thread_process() {
for (unsigned int i = 0; i < n_bytes; i += 4)
{
SCCINFO() << "mem[" << (A + i) << "] = "
SCCTRACE() << "mem[" << (A + i) << "] = "
<< *(reinterpret_cast<unsigned int*>( &data[i] ));
}
}

View File

@ -5,8 +5,8 @@
* Author: eyck
*/
#ifndef COMPONENTS_RESETGEN_H_
#define COMPONENTS_RESETGEN_H_
#ifndef VP_COMPONENTS_RESETGEN_H_
#define VP_COMPONENTS_RESETGEN_H_
#include <systemc>
@ -23,4 +23,4 @@ protected:
void thread();
};
#endif /* COMPONENTS_RESETGEN_H_ */
#endif /* VP_COMPONENTS_RESETGEN_H_ */