|
|
 |
SystemC from scratch. Part 3
Our first example
The best way to learn a new tool or language is to look at some examples already available. The SystemC installation includes a number of examples. Let's take a look at one of them. Here is the example directory.

The FIR filter
We will start with the FIR example. But before we do let's find out a little bit more about FIR filter design. Here is a good place to start: http://www.dspguru.com/info/faqs/firfaq.htmFIR (Finite Impulse Response) filters are one of two primary types of digital filters used in Digital Signal Processing (DSP) applications (the other type being IIR). Compared to IIR filters, FIR filters offer the following advantages: - They can easily be designed to be "linear phase" (and usually are). Put simply, linear-phase filters delay the input signal, but don't distort its phase.
- They are simple to implement. On most DSP microprocessors, the FIR calculation can be done by looping a single instruction.
- They are suited to multi-rate applications. By multi-rate, we mean either "decimation" (reducing the sampling rate), "interpolation" (increasing the sampling rate), or both. Whether decimating or interpolating, the use of FIR filters allows some of the calculations to be omitted, thus providing an important computational efficiency. In contrast, if IIR filters are used, each output must be individually calculated, even if it that output will discarded (so the feedback will be incorporated into the filter).
- They have desireable numeric properties. In practice, all DSP filters must be implemented using "finite-precision" arithmetic, that is, a limited number of bits. The use of finite-precision arithmetic in IIR filters can cause significant problems due to the use of feedback, but FIR filters have no feedback, so they can usually be implemented using fewer bits, and the designer has fewer practical problems to solve related to non-ideal arithmetic.
- They can be implemented using fractional arithmetic. Unlike IIR filters, it is always possible to implement a FIR filter using coefficients with magnitude of less than 1.0. (The overall gain of the FIR filter can be adjusted at its output, if desired.) This is an important considertaion when using fixed-point DSP's, because it makes the implementation much simpler.
SystemC FIR exampleThe SystemC example implements the following program structure:

Running a SystemC simulation
We will start by running a complete SystemC simulation to verify that everything is working. First we goto to the FIR simulation directory: -> cd /home/svenand/root/projects/SystemC/libraries/systemc-2.2.0/objdir/examples/sysc/fir We will start by removing all object files: -> rm *.o
Now we can use the makefile that comes with the installation to compile and run the FIR simulation: -> make check Here is the result:
==> make check make fir fir_rtl make[1]: Entering directory `/home/svenand/root/projects/SystemC/libraries/systemc-2.2.0/objdir/examples/sysc/fir' g++ -DPACKAGE_NAME="" -DPACKAGE_TARNAME="" -DPACKAGE_VERSION="" -DPACKAGE_STRING="" -DPACKAGE_BUGREPORT="" -I. -I../../../../examples/sysc/fir -I/home/svenand/root/projects/SystemC/libraries/systemc-2.2.0/include -Wall -DSC_INCLUDE_FX -O3 -c -o stimulus.o `test -f 'stimulus.cpp' || echo '../../../../examples/sysc/fir/'`stimulus.cpp g++ -DPACKAGE_NAME="" -DPACKAGE_TARNAME="" -DPACKAGE_VERSION="" -DPACKAGE_STRING="" -DPACKAGE_BUGREPORT="" -I. -I../../../../examples/sysc/fir -I/home/svenand/root/projects/SystemC/libraries/systemc-2.2.0/include -Wall -DSC_INCLUDE_FX -O3 -c -o display.o `test -f 'display.cpp' || echo '../../../../examples/sysc/fir/'`display.cpp g++ -DPACKAGE_NAME="" -DPACKAGE_TARNAME="" -DPACKAGE_VERSION="" -DPACKAGE_STRING="" -DPACKAGE_BUGREPORT="" -I. -I../../../../examples/sysc/fir -I/home/svenand/root/projects/SystemC/libraries/systemc-2.2.0/include -Wall -DSC_INCLUDE_FX -O3 -c -o fir.o `test -f 'fir.cpp' || echo '../../../../examples/sysc/fir/'`fir.cpp g++ -DPACKAGE_NAME="" -DPACKAGE_TARNAME="" -DPACKAGE_VERSION="" -DPACKAGE_STRING="" -DPACKAGE_BUGREPORT="" -I. -I../../../../examples/sysc/fir -I/home/svenand/root/projects/SystemC/libraries/systemc-2.2.0/include -Wall -DSC_INCLUDE_FX -O3 -c -o main.o `test -f 'main.cpp' || echo '../../../../examples/sysc/fir/'`main.cpp g++ -Wall -DSC_INCLUDE_FX -O3 -o fir stimulus.o display.o fir.o main.o -L/home/svenand/root/projects/SystemC/libraries/systemc-2.2.0/lib-linux -lsystemc -lm g++ -DPACKAGE_NAME="" -DPACKAGE_TARNAME="" -DPACKAGE_VERSION="" -DPACKAGE_STRING="" -DPACKAGE_BUGREPORT="" -I. -I../../../../examples/sysc/fir -I/home/svenand/root/projects/SystemC/libraries/systemc-2.2.0/include -Wall -DSC_INCLUDE_FX -O3 -c -o fir_fsm.o `test -f 'fir_fsm.cpp' || echo '../../../../examples/sysc/fir/'`fir_fsm.cpp g++ -DPACKAGE_NAME="" -DPACKAGE_TARNAME="" -DPACKAGE_VERSION="" -DPACKAGE_STRING="" -DPACKAGE_BUGREPORT="" -I. -I../../../../examples/sysc/fir -I/home/svenand/root/projects/SystemC/libraries/systemc-2.2.0/include -Wall -DSC_INCLUDE_FX -O3 -c -o fir_data.o `test -f 'fir_data.cpp' || echo '../../../../examples/sysc/fir/'`fir_data.cpp g++ -DPACKAGE_NAME="" -DPACKAGE_TARNAME="" -DPACKAGE_VERSION="" -DPACKAGE_STRING="" -DPACKAGE_BUGREPORT="" -I. -I../../../../examples/sysc/fir -I/home/svenand/root/projects/SystemC/libraries/systemc-2.2.0/include -Wall -DSC_INCLUDE_FX -O3 -c -o main_rtl.o `test -f 'main_rtl.cpp' || echo '../../../../examples/sysc/fir/'`main_rtl.cpp g++ -Wall -DSC_INCLUDE_FX -O3 -o fir_rtl stimulus.o display.o fir_fsm.o fir_data.o main_rtl.o -L/home/svenand/root/projects/SystemC/libraries/systemc-2.2.0/lib-linux -lsystemc -lm make[1]: Leaving directory `/home/svenand/root/projects/SystemC/libraries/systemc-2.2.0/objdir/examples/sysc/fir' make check-TESTS make[1]: Entering directory `/home/svenand/root/projects/SystemC/libraries/systemc-2.2.0/objdir/examples/sysc/fir'
SystemC 2.2.0 --- Jun 8 2008 12:54:47 Copyright (c) 1996-2006 by all Contributors ALL RIGHTS RESERVED Stimuli : 0 at time 9000 Display : 0 at time 10000 Stimuli : 1 at time 19000 Display : -6 at time 20000 Stimuli : 2 at time 29000 Display : -16 at time 30000 Stimuli : 3 at time 39000 Display : -13 at time 40000 Stimuli : 4 at time 49000 Display : 6 at time 50000 Stimuli : 5 at time 59000 Display : 7 at time 60000 Stimuli : 6 at time 69000 Display : -33 at time 70000 Stimuli : 7 at time 79000 Display : -50 at time 80000 Stimuli : 8 at time 89000 Display : 87 at time 90000 Stimuli : 9 at time 99000 Display : 446 at time 100000 Stimuli : 10 at time 109000 Display : 959 at time 110000 Stimuli : 11 at time 119000 Display : 1495 at time 120000 Stimuli : 12 at time 129000 Display : 1990 at time 130000 Stimuli : 13 at time 139000 Display : 2467 at time 140000 Stimuli : 14 at time 149000 Display : 2960 at time 150000 Stimuli : 15 at time 159000 Display : 3466 at time 160000 Stimuli : 16 at time 169000 Display : 3968 at time 170000 Stimuli : 17 at time 179000 Display : 4470 at time 180000 Stimuli : 18 at time 189000 Display : 4972 at time 190000 Stimuli : 19 at time 199000 Display : 5474 at time 200000 Stimuli : 20 at time 209000 Display : 5976 at time 210000 Stimuli : 21 at time 219000 Display : 6478 at time 220000 Stimuli : 22 at time 229000 Display : 6980 at time 230000 Stimuli : 23 at time 239000 Display : 7482 at time 240000 Simulation of 24 items finished at time 240000 SystemC: simulation stopped by user. PASS: fir
Congratulations! We have run our first SystemC simulation.
Posted at 11:21 am by svenand
 |  |  | robin_ny July 16, 2009 06:38 AM PDT
Hello. First thank you for your efforts. I am learning SystemC and I ran into a trouble trying to installing SCV (SystemC verification) library in Ubuntu 8.04. I followed the INSTALL guides. The SystemC is already installed in the /usr/local/systemc-2.2 directory. I was attemting to install SVC in the /usr/local/svc folder. The ../configure with the prefix and other stuff worked fine. But when I tried "make" it, it gave me two errors. I have used g++ version 4.2.4 for SystemC. I am not sure if this is related to gcc or it is a script issue with sh -h. I run ubuntu is in Sun's virtualbox as well as on a stand alone desktop. (not that it makes any difference). Any help would be appreciated. |  |
  |  |  | svenand June 24, 2008 07:25 AM PDT
I have not planned any SystemC to RTL synthesis. My idea about using SystemC is to build a virtual platform where I can simulate my design using TLM methods. Any inputs on how to do SystemC to RTL synthesis are welcomed.
Sven |  |
  |  |  | robin June 22, 2008 10:30 PM PDT
Just was wondering what is your planned approach to RTL synthesis from SystemC.
I am on similar track to learn SystemC, but have a limited budget and so I have been trying to find open-source tools.
So far the only one I have found is sv2v, a translator from SystemC to Verilog. Unfortunately, this tool does not appear to handle all of SystemC's (V2.2.0) syntax and semantics.
I have looked in SystemCrafter, but only allows for a 2 (?!) day trial period, then it's 3K USD.
Anyway, I would be interested in your thoughts on this.
|  |
|