The Sparta Modeling Framework
Loading...
Searching...
No Matches
SystemC Models

The Sparta Scheduler can work in a SystemC environment using the sparta::SysCSpartaSchedulerAdapter.

Building

To enable SystemC in Sparta, the cmake option COMPILE_WITH_SYSTEMC must be ON. To run SystemC tests and the TLM examples, make sure Sparta's CMake build environment can find the SystemC package during configuration. A message in the configuration output will be written if the package was found and COMPILE_WITH_SYSTEMC with set to ON:

% cd sparta/build; cmake .. -DCMAKE_BUILD_TYPE=Release -DCOMPILE_WITH_SYSTEMC=ON
...
-- SystemC enabled: 2.3.3.20181013
...
Macros for handling exponential backoff.

If not, then cmake could not find the SystemC package. This can happen if there exists an install of SystemC elsewhere on the system (like a user's home directory). Sparta can still use that install, but it must be built with the same C++ standard as Sparta (C++17 for example). First, build SystemC:

cd /path/to/systemc-2.3.3; mkdir build; cd build
cmake .. -DCMAKE_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=Release
make install

Then, configure/build Sparta again:

  1. Set your SYSTEMC_HOME environment variable to the SystemC build: export SYSTEMC_HOME=/path/to/systemc-2.3.3
  2. Re-configure Sparta: cmake .. -DCMAKE_BUILD_TYPE=Release -DCOMPILE_WITH_SYSTEMC=ON

The enablement message should print at this point.

To build/run the SystemC example (example/SystemC), the TLM example directory must be found. Since the TLM examples are not part of an install, the Sparta SystemC example CMakeLists.txt file will use the environment variable SYSTEMC_HOME to locate it.

SystemC/Sparta Adapter

The sparta::SysCSpartaSchedulerAdapter is just that, an adapter that syncs the SystemC clock with the Sparta Scheduler. With this class, the modeler is not responsible for advancing time on the Sparta scheduler. SystemC will be doing that via SC_THREADs.

However, Sparta assumes "control" of the scheduling in that the adapter by starting the SystemC scheduler (sc_core::sc_start) via the sparta::SysCSpartaSchedulerAdapter::run method.

The expected development using this adapter is:

  1. Implement sc_main as normal
  2. Instantiate Sparta components including a sparta::Scheduler, sparta::ResourceTreeNode, etc
  3. Instantiate the sparta::SysCSpartaSchedulerAdapter passing to its constructor the sparta::Scheduler created
  4. Call run() on the adapter

See an example of this in sparta/test/SystemC_test.cpp.

There are 3 other examples of how Sparta can be used in a SystemC environment in the examples/SystemC directory:

1_phase
2_phase
4_phase

Each directory is an example of using the TLM initiator/target at_*_phase example swapping out the TLM target with a Sparta memory object and a Sparta/TLM socket adapter. These examples can only be built if the TLM examples are present in the SystemC directory. Make sure SYSTEMC_HOME is set before running cmake on Sparta. See above...

Caveats on using the SystemC adapters:

  1. Only one adapter is allowed in simulation
  2. Only one sparta::Scheduler is allowed in simulation
  3. Time advancement bounces between SystemC and Sparta. Zero-timed communication between a SysC component and a Sparta component may not work if the Sparta component requires advancement from the Sparta Scheduler. This is currently untested.
  4. Communication between a Sparta component (Sparta Port) and a SystemC Port (or TLM callback) requires a Sparta/SystemC gasket to be written by the modeler