/pics/scams_wave_1200_80.png

How to set up a free build environment - step by step

/pics/puzzle.pngThis is a consistent description of a working setup, re-checked on 21th of February 2021.
I assume you are able to read - so there are no screenshots of buttoos...
It may not work for newer versions, depending on backward compatibility of the used tools. The setup is based on Windows - due to the vast options of Linux distributions available, which are often not really compatible to each other, I won't provide any solutions for that. I also don't own a Mac, so I can't help here either. You still may use this document as general guideline for the setup, but you may have to expect some differences. If you deviate from it, you are on your own as well - sorry.
Please use it as a starting point, you can not expect a fully smooth turn-key solution for free. You must have a basic understanding of C/C++ development environments, so you should be able to fix smaller issues arising when using any future build tool versions. Otherwise, you may consider starting with some basic C++ tutorials first, to get used to C++ development in general.
But the effort pays off, as it will give you a modelling environment to create virtual prototypes also on commercial basis, which can even outperform models generated by commercial tools like Matlab®/Simulink® and can easily link to a lot of other system level tools out there.
If you want that someone else "thinks for you to provide a proper working setup" - which is a legitimate request, if you are in modelling and not C++ development - you need to pay this people and their tools they offer. In this case check again my notes on commercial SystemC/SystemC-AMS tools at the end of the page here. If you are an academic institution, you should get in contact with these people to discuss special deals - similar to other commercial tools out there.
Please note: links below are leading to external sites.

Prerequisites

  • An actual Windows 10 PC with decent AMD or Intel processor (64 bit preferred)

  • You should have at least 3GB free on your hard drive for the installation

Install the compile environment

  • Go to https://www.msys2.org/ and download an actual distribution (im my case it is: "msys2-x86_64-20210105.exe"). You can find more information on the environment here, but not important for now: https://www.msys2.org/wiki/MSYS2-introduction/.

  • Execute the installer file you meanwhile should have on your PC. I didn't like to install all in the root of my hard drive, so I selected "C:\tools\msys64" as folder for the installation.

  • A Msys2 command line will open (otherwise it can be started as "C:\tools\msys64\msys2.exe"). In the command line, enter "pacman -Syu" to get the latest updates. The update will finally close the command line.

  • Create a link to "C:\tools\msys64\msys2.exe" on the desktop and click on it to open again a shell.

  • In the shell, we will install now the build environment with "pacman -S --needed base-devel mingw-w64-x86_64-toolchain".

  • Now you have all you need to compile the SystemC/SystemC-AMS libraries. Just create another link to "C:\tools\msys64\mingw64.exe " on your desktop.

  • To unpack the example downloads later on and to have a basic editor, you may also install this "pacman -S vim zip unzip".

  • Additionally, you could already install the waveform viewer with this "pacman -S mingw-w64-i686-gtkwave".

  • Furthermore, if you want to use Python for postprocessing as I show in the example section, you should install "pacman -S mingw-w64-x86_64-python-numpy" and "pacman -S mingw-w64-x86_64-python-matplotlib".

  • But this steps you can also do later, before trying any example. Just open a Msys2 command line again and install these packages when needed.

  • Now you can close the Msys2 command line (close the window or enter "exit").

Download and compile the SystemC and SystemC-AMS libraries

  • Go to https://www.accellera.org/downloads/standards/systemc and download:
    • SystemC 2.3.3 (Includes TLM) -> Core SystemC Language and Examples (tar.gz)
    • SystemC AMS 2.3 -> SystemC AMS Proof-of-Concept (external)
  • Copy the two downloaded .tar.gz files into "C:\tools\msys64\opt".

  • Open a Mingw64 command line. I installed both libraries to one location "/opt/scams", so I need to set up less paths later on. You could separate using different --prefix options in the configure run, but this is not really needed, I'd say.

  • Now you can compile the setup in the command line window. Please note, the -j12 argument on the make takes 12 CPUs for compilation. Take the number of CPUs you have on your PC, e.g. with 4 CPUs use -j4.

         cd /opt
         tar xvfz systemc-2.3.3.tar.gz
         tar xvfz systemc-ams-2.3.tar.gz

         cd systemc-2.3.3
         ./configure --prefix=/opt/scams
         make -j12
         (there are some "out of bounds" warnings, for now I ignored them)
         make install

         cd ../systemc-ams-2.3
         ./configure --prefix=/opt/scams --with-systemc=/opt/scams --with-arch-suffix=-mingw64
         make -j12
         (ignore the static library warnings, it will work fine)
         make install

  • In principle, you can delete the .tar.gz files and the two directories systemc-ams-2.3 and systemc-2.3.3 after the next step - you just need the just created scams directory.

Check the setup - try a simple example

  •  Open a Mingw64 command line, if not already open. In your home directory, create a folder scatest ("cd ~; mkdir scatest; cd scatest").

  • Use vim or any other editor to type in this example file "sc_main.cpp":
//----------------------------------------------------------------------
//   Copyright 2020 Carinthia University of Applied Sciences
//   All Rights Reserved Worldwide
//
//   Licensed under the Apache License, Version 2.0 (the
//   "License"); you may not use this file except in
//   compliance with the License.  You may obtain a copy of
//   the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in
//   writing, software distributed under the License is
//   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
//   CONDITIONS OF ANY KIND, either express or implied.  See
//   the License for the specific language governing
//   permissions and limitations under the License.
//----------------------------------------------------------------------

#include <systemc.h>
#include <systemc-ams.h>

SC_MODULE(rc_example)
{
  // ELN primitive instances
  sca_eln::sca_vsource i_vin;
  sca_eln::sca_r i_sca_r1;
  sca_eln::sca_c i_sca_c1;

  // ELN nodes
sca_eln::sca_node vin;

  sca_eln::sca_node vout;
  sca_eln::sca_node_ref gnd;

// RC lowpass with sine input
  SC_CTOR(rc_example)

  : i_vin("i_vin", 2.0, 2.0,1.0,1e6,0,sc_core::SC_ZERO_TIME,1.0), // 2V DC, 1V/1MHz sin and 1V AC
    i_sca_r1("i_sca_r1", 1e3),         // R of lowpass
    i_sca_c1("i_sca_c1", 160e-12),      // C of lowpass
    vin("vin"), vout("vout"), gnd("gnd")
  {
    // input source, ELN time step definition
    i_vin.p(vin);
    i_vin.n(gnd);
    i_vin.set_timestep(1, sc_core::SC_NS);

    // RC lowpass
    i_sca_r1.p(vin);
    i_sca_r1.n(vout);
    i_sca_c1.p(vout);
    i_sca_c1.n(gnd);
  }

};

// ========================================================

int sc_main(int argc, char* argv[]){

  sc_set_time_resolution(1.0, SC_NS);
 
  rc_example dut("dut");

  // transient domain simulation
  sca_util::sca_trace_file* trtf = sca_util::sca_create_tabular_trace_file( "tr.tab" );
  sca_util::sca_trace( trtf, dut.vin, "vin" );
  sca_util::sca_trace( trtf, dut.vout, "vout" );
  sc_start(2, SC_US);
  trtf->disable();

  SC_REPORT_INFO("sc_main", "transient domain simulation done");

  // frequency-domain simulation
  sca_util::sca_trace_file* actf = sca_util::sca_create_tabular_trace_file( "ac.tab" );
  sca_util::sca_trace( actf, dut.vin, "vin" );
  sca_util::sca_trace( actf, dut.vout, "vout" );
  sca_ac_start(1e3,100e6,100);

  SC_REPORT_INFO("sc_main", "frequency domain simulation done");

  return 0;
}
  • Compile the model in the command line using "g++ sc_main.cpp -osc_main.exe -I/opt/scams/include -L/opt/scams/lib-mingw64 -lsystemc-ams -lsystemc -lm"

  • This will generate sc_main.exe you can run. It will generate two files, "tr.tab" and "ac.tab" we will have a look later. But when you have got these files, your environment seems to be ok.
 

Install the Eclipse CDT environment

This is no introduction to Eclipse. If you have no idea what I am talking about, you should look for some basic tutorials on Eclipse CDT and try some "hello world" examples first.
  • Go to https://www.eclipse.org/cdt/downloads.php and download the installation package (in my case it was "eclipse-cpp-2020-12-R-win32-x86_64.zip").

  • Unpack to: "C:\tools\eclipse".

  • In this directory, create a batch file start_systemc.bat:
@echo off
rem Set these environment variables in the C/C++ Build options
set MINGW_HOME=C:\tools\msys64\mingw64
set MSYS_HOME=C:\tools\msys64
set PATH=%MSYS_HOME%\usr\bin;%MINGW_HOME%\bin;%PATH%
.\eclipse
  • Now you can create a link of this batch file on your desktop and start the environment with it.

  • After setting up the workspace, you can try the example above again.

  • To build SystemC-AMS projects within Eclipse/CDT, you use the project explorer like this:

    • New -> C++ Project -> Empty Project, MinGW GCC, select a project name
    • Project->Properties->C/C++ General -> Path and Symbols
          set [all configurations]
          C++ Includes add: C:\tools\msys64\opt\scams\include
          C++ Libraries add: systemc-ams
          C++ Libraries add: systemc
          C++ Libraries add: m
          C++ Library paths add: C:\tools\msys64\opt\scams\lib-mingw64
    • Create and save sc_main.cpp (see source above)
    • Compile and run the example using the Eclipse build flow