Skip to content

Latest commit

 

History

History
148 lines (108 loc) · 3.91 KB

systemc_notes.md

File metadata and controls

148 lines (108 loc) · 3.91 KB

Developing a SystemC Application

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:

1. Set Up the Development Environment

Install SystemC Library

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

2. Write SystemC Modules

Create SystemC modules by defining classes that inherit from sc_module. Implement the functionality in the SC_CTOR constructor and other member functions.

Example: Simple SystemC Module

// 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();
    }
};

3. Write the Top-Level Module and Testbench

Create a top-level module to instantiate and connect your SystemC modules. Write a testbench to drive the simulation.

Example: Top-Level Module and Testbench

// 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;
}

4. Compile and Run the Application

Use a build system like CMake to compile and run your SystemC application.

Example: CMakeLists.txt

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)

Build and Run

You can either pass the SYSTEMC_HOME parameter using the -D option or set the SYSTEMC_HOME environment variable:

Using CMake Parameter

mkdir build
cd build
cmake -DSYSTEMC_HOME=/path/to/install/systemc ..
make
./SystemCExample

Using Environment Variable

export SYSTEMC_HOME=/path/to/install/systemc
mkdir build
cd build
cmake ..
make
./SystemCExample

Summary

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.