adds initial files for mt test
Some checks failed
SCC Test/pipeline/head There was a failure building this commit
Some checks failed
SCC Test/pipeline/head There was a failure building this commit
This commit is contained in:
5
tests/quantum_keeper_mt/CMakeLists.txt
Normal file
5
tests/quantum_keeper_mt/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
add_executable (quantum_keeper_mt
|
||||
sc_main.cpp
|
||||
)
|
||||
target_link_libraries (quantum_keeper_mt LINK_PUBLIC scc-sysc)
|
||||
add_test(NAME quantum_keeper_mt COMMAND quantum_keeper_mt)
|
||||
46
tests/quantum_keeper_mt/sc_main.cpp
Normal file
46
tests/quantum_keeper_mt/sc_main.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "top_module.h"
|
||||
#include "util/logging.h"
|
||||
#include <csetjmp>
|
||||
#include <csignal>
|
||||
#include <cstdlib>
|
||||
#include <scc/configurer.h>
|
||||
#include <scc/report.h>
|
||||
#include <scc/trace.h>
|
||||
#include <scc/tracer.h>
|
||||
#include <sysc/utils/sc_report.h>
|
||||
#include <sysc/utils/sc_report_handler.h>
|
||||
#include <tlm_utils/tlm_quantumkeeper.h>
|
||||
#include <util/ities.h>
|
||||
|
||||
using namespace scc;
|
||||
using namespace sc_core;
|
||||
|
||||
jmp_buf abrt;
|
||||
void ABRThandler(int sig) { longjmp(abrt, 1); }
|
||||
|
||||
int sc_main(int argc, char* argv[]) {
|
||||
signal(SIGABRT, ABRThandler);
|
||||
auto my_name = util::split(argv[0], '/').back();
|
||||
auto level = "3"; // getenv("SCC_TEST_VERBOSE");
|
||||
auto log_lvl = level ? static_cast<scc::log>(std::min(strtoul(level, nullptr, 10) + 4, 7UL)) : log::FATAL;
|
||||
scc::init_logging(LogConfig().logLevel(log_lvl).logAsync(false).msgTypeFieldWidth(35));
|
||||
LOGGER(DEFAULT)::reporting_level().store(logging::TRACEALL);
|
||||
scc::configurer cfg("");
|
||||
// create tracer if environment variable SCC_TEST_TRACE is defined
|
||||
std::unique_ptr<scc::tracer> tracer;
|
||||
if(auto* test_trace = getenv("SCC_TEST_TRACE")) {
|
||||
tracer = std::make_unique<scc::tracer>(my_name, scc::tracer::ENABLE, scc::tracer::ENABLE);
|
||||
tracer->set_default_trace_enable(true);
|
||||
}
|
||||
int result = -1;
|
||||
tlm_utils::tlm_quantumkeeper::set_global_quantum(3_us);
|
||||
if(setjmp(abrt) == 0) {
|
||||
// instantiate design(s)
|
||||
top_module top_mod("top_module_inst");
|
||||
// Start the simulation
|
||||
sc_core::sc_start(20_us);
|
||||
} else {
|
||||
SCCERR() << "Some error occured";
|
||||
}
|
||||
return sc_core::sc_report_handler::get_count(sc_core::SC_ERROR) + sc_core::sc_report_handler::get_count(sc_core::SC_WARNING);
|
||||
}
|
||||
88
tests/quantum_keeper_mt/top_module.h
Normal file
88
tests/quantum_keeper_mt/top_module.h
Normal file
@@ -0,0 +1,88 @@
|
||||
#ifndef _TOP_MODULE_H_
|
||||
#define _TOP_MODULE_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <scc/async_queue.h>
|
||||
#include <scc/async_thread.h>
|
||||
#include <scc/report.h>
|
||||
#include <sysc/kernel/sc_initializer_function.h>
|
||||
#include <sysc/kernel/sc_simcontext.h>
|
||||
#include <thread>
|
||||
#include <tlm/scc/quantum_keeper.h>
|
||||
#include <tlm>
|
||||
#include <tlm_core/tlm_2/tlm_generic_payload/tlm_gp.h>
|
||||
#include <tlm_utils/simple_initiator_socket.h>
|
||||
#include <tlm_utils/simple_target_socket.h>
|
||||
#include <util/logging.h>
|
||||
|
||||
struct initiator : ::sc_core ::sc_module {
|
||||
tlm_utils::simple_initiator_socket<initiator, scc::LT> isckt{"isckt"};
|
||||
|
||||
initiator(sc_core::sc_module_name nm)
|
||||
: sc_core::sc_module(nm) {
|
||||
SC_THREAD(run);
|
||||
}
|
||||
|
||||
~initiator() {}
|
||||
|
||||
private:
|
||||
void run() {
|
||||
wait(sc_core::SC_ZERO_TIME); // guard elaboration phase
|
||||
quantum_keeper.reset();
|
||||
core_executor.start([this]() { return thread_exec(); });
|
||||
wait(core_executor.thread_finish_event());
|
||||
sc_core::sc_stop();
|
||||
}
|
||||
|
||||
sc_core::sc_time thread_exec() {
|
||||
SCCDEBUG(SCMOD) << "starting thread_exec";
|
||||
for(auto i = 0u; i < 16; ++i) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
if(i && (i % 3) == 0) {
|
||||
tlm::tlm_generic_payload gp;
|
||||
sc_core::sc_time t;
|
||||
SCCDEBUG(SCMOD) << "initiating b_transport at local time " << quantum_keeper.get_local_absolute_time();
|
||||
quantum_keeper.execute_on_sysc([this, &gp, &t]() {
|
||||
SCCDEBUG(SCMOD) << "executing b_transport";
|
||||
auto t0 = sc_core::sc_time_stamp();
|
||||
this->isckt->b_transport(gp, t);
|
||||
return t0 - sc_core::sc_time_stamp();
|
||||
});
|
||||
if(t.value()) {
|
||||
SCCDEBUG(SCMOD) << "incrementing local time by b_transport delay of " << t;
|
||||
quantum_keeper.inc(t);
|
||||
}
|
||||
} else {
|
||||
quantum_keeper.check_and_sync(1_us);
|
||||
}
|
||||
SCCDEBUG(SCMOD) << "local time now " << quantum_keeper.get_local_absolute_time();
|
||||
}
|
||||
SCCDEBUG(SCMOD) << "finished thread_exec at local time " << quantum_keeper.get_local_absolute_time();
|
||||
return quantum_keeper.get_local_absolute_time();
|
||||
}
|
||||
tlm::scc::quantumkeeper_mt quantum_keeper;
|
||||
scc::async_thread core_executor;
|
||||
};
|
||||
|
||||
// top_module
|
||||
struct top_module : ::sc_core ::sc_module {
|
||||
initiator core{"core"};
|
||||
|
||||
tlm_utils::simple_target_socket<top_module, scc::LT> tsckt{"tsckt"};
|
||||
|
||||
top_module(sc_core::sc_module_name nm)
|
||||
: sc_core::sc_module(nm) {
|
||||
core.isckt(tsckt);
|
||||
tsckt.register_b_transport(this, &top_module::b_transport);
|
||||
}
|
||||
|
||||
~top_module() {}
|
||||
|
||||
void b_transport(tlm::tlm_generic_payload& gp, sc_core::sc_time& t) {
|
||||
SCCDEBUG(SCMOD) << "Received b_transport call at local time " << t;
|
||||
t += 5_us;
|
||||
gp.set_response_status(tlm::TLM_OK_RESPONSE);
|
||||
}
|
||||
};
|
||||
#endif // _TOP_MODULE_H_
|
||||
Reference in New Issue
Block a user