Developing a SystemC application involves several steps, including setting up the development environment, writing SystemC modules, and compiling and running the application. Here is a canonical way to develop a SystemC application:
First, you need to install the SystemC library. You can download it from the Accellera website and follow the installation instructions.
# Download SystemC
wget http://www.accellera.org/images/downloads/standards/systemc/systemc-2.3.3.tar.gz
tar -xzf systemc-2.3.3.tar.gz
cd systemc-2.3.3
# Configure and install
mkdir build
cd build
../configure --prefix=/path/to/install/systemc
make
make install
Create SystemC modules by defining classes that inherit from sc_module
. Implement the functionality in the SC_CTOR
constructor and other member functions.
// simple_module.h
#include <systemc.h>
SC_MODULE(SimpleModule) {
sc_in<bool> clock;
sc_out<int> out_signal;
void process() {
while (true) {
wait(); // Wait for a clock edge
out_signal.write(out_signal.read() + 1);
}
}
SC_CTOR(SimpleModule) {
SC_THREAD(process);
sensitive << clock.pos();
}
};
Create a top-level module to instantiate and connect your SystemC modules. Write a testbench to drive the simulation.
// main.cpp
#include <systemc.h>
#include "simple_module.h"
int sc_main(int argc, char* argv[]) {
sc_signal<bool> clock;
sc_signal<int> out_signal;
SimpleModule simple_module("SimpleModule");
simple_module.clock(clock);
simple_module.out_signal(out_signal);
// Generate clock signal
sc_clock clk("clk", 10, SC_NS);
clock(clk);
// Trace file to record simulation results
sc_trace_file *tf = sc_create_vcd_trace_file("trace");
sc_trace(tf, clock, "clock");
sc_trace(tf, out_signal, "out_signal");
// Start simulation
sc_start(100, SC_NS);
// Close trace file
sc_close_vcd_trace_file(tf);
return 0;
}
Use a build system like CMake to compile and run your SystemC application.
cmake_minimum_required(VERSION 3.10)
project(SystemCExample)
# Check if SYSTEMC_HOME is set as a CMake parameter or environment variable
if(NOT DEFINED SYSTEMC_HOME)
if(DEFINED ENV{SYSTEMC_HOME})
set(SYSTEMC_HOME $ENV{SYSTEMC_HOME})
else()
message(FATAL_ERROR "SYSTEMC_HOME is not set. Please specify the SystemC installation path using -DSYSTEMC_HOME=/path/to/systemc or set the SYSTEMC_HOME environment variable.")
endif()
endif()
# Include SystemC headers and libraries
include_directories(${SYSTEMC_HOME}/include)
link_directories(${SYSTEMC_HOME}/lib-linux64)
# Add executable
add_executable(SystemCExample main.cpp simple_module.h)
# Link SystemC library
target_link_libraries(SystemCExample systemc)
You can either pass the SYSTEMC_HOME
parameter using the -D
option or set the SYSTEMC_HOME
environment variable:
mkdir build
cd build
cmake -DSYSTEMC_HOME=/path/to/install/systemc ..
make
./SystemCExample
export SYSTEMC_HOME=/path/to/install/systemc
mkdir build
cd build
cmake ..
make
./SystemCExample
The canonical way to develop a SystemC application involves setting up the development environment, writing SystemC modules, creating a top-level module and testbench, and using a build system like CMake to compile and run the application. The provided examples demonstrate how to write a simple SystemC module, a top-level module, and a testbench, as well as how to set up a CMake project to build and run the application.