Farid Okla
Einführung in System C
Farid Okla
Einführung in System C1Einführung in SystemC Andreas Mitschele-Thiel 22-Apr-03
TECHNISCHE UNIVERSITÄTILMENAU
Inte
grat
ed H
ard-
nd S
oftw
are
Syst
ems
http
://w
Einführung in
SystemC
Farid Okla22. April 2003
aw
w-ih
s.th
eoin
f.tu-
ilmen
au.d
e
2Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Gliederung
• Allgemeine Einführung und Entwicklungsgeschichte• Herkömmlicher Entwurfsprozess vs. SystemC Entwurfsprozess• SystemC-Sprachkonzept
– SystemC-Datentypen– Module und Ports– Module und Signale– Prozesse– Clocks– Signale, Variablen, Prozesse, Constructor
• „Lauflicht“ – ein Beispiel– Testbench und Hauptroutine– Compilieren und Simulieren
• Zusammenfassung und Quellen
3Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Was ist SystemC
Daraus resultieren zwei notwendige Eigenschaften:
SystemC ist eine von mehreren Firmen unter Leitung der Open SystemC Initiative OSCI entwickelte C++ Klassenbibliothek.SystemC wurde unter dem Aspekt der Vereinheitlichung einer Entwurfssprache für Hardware- und Software- Design entworfen.
SystemC besitzt die aus der Softwareentwicklung bekannten Eigenschaften der objektorientierten Programmiersprache C++.
SystemC besitzt Konstrukte zur Beschreibung komplexer Hardware-Systeme, vergleichbar mit den herkömmlichen Hardware-Beschreibungssprachen (Hardware-Description-Language) wie VHDL oder Verilog-HDL.
4Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Entwicklungsgeschichte
• vor SystemC: Vielzahl an C/C++ basierten Entwurfssprachen, aberkein einheitlicher Standard
• Einführung September 1999• Entwicklung und Standardisierung durch die OSCI
– Open SystemC™ Initiative– Konsortium größerer EDA (Electronic Design Automation )-Firmen und IP-Providern
• „Open Source License“– kann ohne Kosten runtergeladen, installiert und benutzt werden
frei verfügbares Entwurfs- und Simulationspaket
5Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Gliederung
• Allgemeine Einführung und Entwicklungsgeschichte• Herkömmlicher Entwurfsprozess vs. SystemC Entwurfsprozess• SystemC-Sprachkonzept
– SystemC-Datentypen– Module und Ports– Module und Signale– Prozesse– Signale und Clocks– Signale, Variablen, Prozesse, Constructor
• „Lauflicht“ – ein Beispiel– Testbench und Hauptroutine– Compilieren und Simulieren
• Zusammenfassung und Quellen
6Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
HDL-basierter Design-Flow
• Funktionale Spezifikationin C++ (ausführbar)
• Entscheidung welcherin Hard- bzw. Softwareimplementiert wird
• Übersetzung derSpezifikation in HDL !!!
• Heterogene Simulations bzw.Testumgebungerschwert HW / SW CoDesign
System Spezifikation C++
Hardware-Software Partitionierung
Softwareentwurf C, C++
SoftwaresyntheseKompilation
Hardwareentwurf VHDL, Verilog
HardwaresynthesePlace and Route
SoftwareHardware
7Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
SystemC Design-Flow
•Ausführbare Spezifikation in SystemC als Grundlage für HW und SW-Entwurf
•Hardware- und Software-Modelle gemeinsam in einerhomogenen Umgebung
• Hardwareentwurf wird durch schrittweise Verfeinerung der Spezifikation erreicht. (keineSprachbarriere wie zu HDL‘s)
• Hardware-Synthese direktvom SystemC-Modell
System Spezifikation SystemC
Hardware-Software Partitionierung
Softwareentwurf C++
SoftwaresyntheseKompilation
Hardwareentwurf SystemC
HardwaresynthesePlace and Route
SoftwareHardware
8Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Gliederung
• Allgemeine Einführung und Entwicklungsgeschichte• Herkömmlicher Entwurfsprozess vs. SystemC Entwurfsprozess• SystemC-Sprachkonzept
– SystemC-Datentypen – Module und Ports– Module und Signale– Prozesse– Clocks– Signale, Variablen, Prozesse, Konstruktor
• „Lauflicht“ – ein Beispiel– Testbench und Hauptroutine– Compilieren und Simulieren
• Zusammenfassung und Quellen
9Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Übersicht SystemC-Sprachkonzept
Modul
Ports Signale Variablen Prozesse
SC_METHOD
SC_THREAD
SC_CTHREAD
sc_in
sc_out
sc_inout
10Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
SystemC-Datentypen
sc_bit zweiwertiges Bit (0 und 1)sc_logic vierwertiges Bit (0, 1, Z, X)sc_int<n> Integertyp mit fester Bitlänge n (n≤64)sc_uint<n> Integertyp mit fester Bitlänge n (n≤64)sc_bv<n> Bitvektoren der Länge n (zweiwertig)sc_lv<n> Bitvektoren der Länge n (vierwertig)
• zusätzlich– alle C++ Standardtypen– Fixkomma-Datentypen (DSP-Anwendungen)– benutzerdefinierte Typen
11Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Module und Ports (1)
• Module– grundlegende Bausteine in SystemC– Deklaration:
SC_MODULE(lauflicht) {…
– alternativ: struct lauflicht : sc_module {…
• Ports– zur Kommunikation zwischen Modulen– drei verschiedene Typen:
Eingang sc_in<datentyp>
Ausgang sc_out<datentyp>
Eingang/Ausgang sc_inout<datentyp>
12Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Module und Ports (2)
// ram.h#include "systemc.h"SC_MODULE(ram){
sc_in<int> addr;sc_in<int> datain;sc_in<bool> rwb;sc_out<int> dout;int memdata[64];int i;void ramread();void ramwrite();
SC_CTOR(ram){ // ConstructorSC_METHOD(ramread);sensitive << addr << rwb;
SC_METHOD(ramwrite);sensitive<<addr<< datain<<rwb;for(i=0 ; i++; i<64){
memdata[i]=0;}
}};
13Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Module und Ports (3)
LoadFIFO
Full
EmptyReadData
SC_MODULE(fifo){sc_in<bool> load;sc_in<bool> read;sc_inout<int> data;sc_out<bool> full;sc_out<bool> empty;
..........};
14Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Port read/write-Operationen
SC_MODULE(module_name){
// ports
sc_in<int> a;
sc_out<int> b;
int c;
void entry(){
b=10;// Write 10 to the port
if(a < 5){ // Read the port
c = a; // Read the port again
}
}
// rest of module
SC_MODULE(module_name){
// ports
sc_in<int> a;
sc_out<int> b;
int c;
void entry(){
b.write(10);// Write 10 to the port
if(a.read() < 5){ // Read the port
c = a.read();// Read the port again
}
}
// rest of module
15Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Module und Signale (1)
Positional Connection:
aq
b m1cc1 out
din s1 doutq
Sample
Coeff
Mults
Filter
// filter.h
#include "systemc.h"
#include "mult.h"
#include "coeff.h"
#include "sample.h"
SC_MODULE(filter){
sample *s1;
coeff *c1;
mult *m1;
sc_signal<sc_uint<32> > q, s,c;
SC_CTOR(filter){
s1 = new sample("s1");
(*s1)(q,s);
c1 = new coeff("c1");
(*c1)(c);
m1 = new mult ("m1");
(*m1)(s,c,q);
}
}
16Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Module und Signale (2)
Named Connection:
aq
b m1cc1 out
din s1 doutq
Sample
Coeff
Mults
Filter
// filter.h#include "systemc.h"#include "mult.h"#include "coeff.h"#include "sample.h"SC_MODULE(filter){sample *s1;coeff *c1;mult *m1;
sc_signal<sc_uint<32> > q, s,c;
SC_CTOR(filter){s1 = new sample("s1");s1->din(q);s1->dout(s);c1 = new coeff("c1");c1->out(c);m1 = new mult ("m1");m1->a(s);m1->b(c);m1->q(q); }
}
17Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Prozesse
• Prozesse dienen zur Beschreibung des (reaktiven) Verhaltens von Modulen, werden (quasi)-parallel ausgeführt
• Prozesse enthalten eine Menge von Anweisungen, die die Funktionalität des Prozesses imlementieren.
• 3 Typen von Prozessen:– Method– Thread– Clocked Thread
18Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Prozess Type : Method (SC_METHOD)
// dff.h#include "system.h"SC_MODULE(dff) {
sc_in<bool> din;sc_in<bool> clock;
sc_out<bool> dout;
void doit();
SC_CTOR(dff) {SC_METHOD(doit);sensitive_pos << clock;
}};
// dff.cc#include "dff.h"void dff::doit() {
dout = din;}
19Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Prozess Type : Thread (SC_THREAD)// Header File
SC_MODULE(my_module){
// ports
sc_in<int> a;
sc_in<bool> b;
sc_out<int> x;
sc_out<int> y;
// Internal signals
sc_signal<bool> c;
sc_signal<int> d;
// Thread process
void my_thread_proc();
// ConstructorSC_CTOR(my_module) {// register thread processSC_THREAD(my_thread_proc);
sensitive << a << c << d;sensitive_pos << b; }
};// Implementation File// Process Bodyvoid my_module :: my_thread_proc()
while (true) {x = a + d;
wait();y = a /d;
wait(); } }
20Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Prozess Type : Clocked Thread (SC_CTHREAD)// Header FileSC_MODULE(my_module){// ports
sc_in_clk clock;sc_in<int> a;sc_in<bool> b;sc_out<int> x;sc_out<int> y;// Internal signalssc_signal<bool> c;sc_signal<int> d;// CThread process
void my_cthread_proc();
// ConstructorSC_CTOR(my_module) {// register thread processSC_CTHREAD(my_cthread_proc,clock.pos()); }
}; // Implementation File// Process Bodyvoid my_module :: my_cthread_proc(){
while (true) {x = a + d;wait();y = a /d;wait(); }
}
21Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Wait, Watching
Wait: Watching
// ConstructorSC_CTOR(adder) {SC_CTHREAD(entry, CLK.pos());watching(reset.delayed()==true);}……………………..void adder::adder_proc() {/*reset actions*/while(true) {out=in1+in2;wait();out=in1+in2+2;wait();}}
// ConstructorSC_CTOR(adder) {SC_CTHREAD(entry, CLK.pos());}……………………..void adder::adder_proc() {while(true) {out=in1+in2;wait();if(reset==1){/*reset actions*/};out=in1+in2+2;wait();if(reset==1){/*reset actions*/};}}
22Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Prozesstypen
SC_CTHREADSC_THREADSC_METHOD
Zeit/ taktgetriggertmehrere Zustände
(waits)
event getriggert (beliebige
Triggerbedingung)mehrere Zustände
(waits)
event getriggert (beliebigeTriggerbedingung)
vollständige Bearbeitungdes Prozesses (keinewait() Anweisungen)
Event1
Event2
Event3
Event5
Event4
Takt1
Takt2Takt4
Takt3
23Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Clocks• Clocks sind besondere Objekte in SystemC.• Clocks generieren zeitabhängige Signale, die zur
synchronisierten Events in der Simulation benutzt werden.• Clock-Objekt hat folgende Syntax:
sc_clock clock1("clock1", 20, 0.5, 2, true);Diese Definition erzeugt ein Takt-Objekt namens „clock1“, mit einer Periode von „20“ Zeiteinheiten und ein Tastverhältnis von „50%“, deren erste Flanke nach „2“ Zeiteinheiten auf einen Wert „true“ führt.
20Clock Waveform
0 2 12 22 32
clock Offset Clock Waveform
24Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Variablen, Signale, Prozesse (1)
Variablenwerden innerhalb von Modulen definiertdienen als Speicher, Registerz.B. sc_uint<8> my_data;
SignaleSignalleitungenverbinden Prozesse und Modulez.B.: sc_signal<int> my_signal;
Prozessebeschreiben Funktionalität des Modulsz.B. void my_process();
25Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Variablen, Signale, Prozesse (2)#include "systemc.h"
SC_MODULE(lauflicht) {
sc_in<bool> clk; sc_in<bool> reset;sc_in<bool> en; sc_in<bool> dir; sc_out<sc_uint<8> > d_out;
sc_uint<8> data; void my_process();
…};
26Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Gliederung
• Allgemeine Einführung und Entwicklungsgeschichte• Herkömmlicher Entwurfsprozess vs. SystemC Entwurfsprozess• SystemC-Sprachkonzept
– SystemC-Datentypen – Module und Ports– Module und Signale– Prozesse– Clocks– Signale, Variablen, Prozesse, Constructor
• „Lauflicht“ – ein Beispiel– Testbench und Hauptroutine– Compilieren und Simulieren
• Zusammenfassung und Quellen
27Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Testbench (1)
Stimulus Device Under Test
Results Checking
Hauptmodul
– Erzeugung von Testsignalen an Eingangsports– Erfassen von Ausgabewerten an Ausgabeports
28Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Testbench (2)
// count_stim.h#include "systemc.h"SC_MODULE(count_stim) {
sc_in<bool> load;sc_in<int> din; // input portsc_in<bool> clock; // input portsc_out<int> dout;void stimgen();
SC_CTOR(count_stim) {SC_THREAD(stimgen);sensitive_pos (clock);}
};
29Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Testbench (3)
// count_stim.cc#include "count_stim.h"void count_stim::stimgen() {while (true) {
load = true; // load 0din = 0;wait(); // count up, value = 1load = false;wait(); // count up, value = 2wait(); //count up, value = 3wait(); // count up, value = 4wait(); // count up, value = 5wait(); // count up, value = 6wait(); // count up, value = 7}
}
30Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
lauflicht.h#include "systemc.h"SC_MODULE(lauflicht) {sc_in<bool> clk; sc_in<bool> reset;sc_in<bool> en; sc_in<bool> dir; sc_out<sc_uint<8> > d_out;
sc_uint<8> data; void my_process();SC_CTOR(lauflicht) {SC_METHOD(my_process);sensitive_pos << clk;sensitive_neg << reset;
data = 0;d_out = 255;
}};
31Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
lauflicht.cpp#include "lauflicht.h"void lauflicht::my_process(){ if (reset.read()==0) { // asynchroner Resetdata=0;d_out=0;
}else {if (en==1) {
if (dir==1) { // von rechts nach linksdata = data << 1; if (data==0) {
data=1; }
} else { // von links nach rechtsdata = data >> 1;if (data==0) {
data=128;}
}}d_out=~data; } } // negiert auf Ausgang, da LEDs lowaktiv
32Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Hauptroutine – sc_main()
• Deklaration notwendiger Verbindungssignale
• Erzeugen aller benötigten Top-Level-Module
• Portmapping für Module durchführen
• Simulation starten – sc_start(n)– n … Anzahl Zyklen– n=-1 Simulation läuft kontinuierlich
33Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
main.cpp
#include "lauflicht.h"int sc_main(int argc, char* argv[ ]) {
// Verbindungssignalesc_signal<sc_uint<8> > DATA; sc_clock CLOCK("clock",10);sc_signal<bool> RESET,EN,DIR;// Portmapping für Lauflichtlauflicht lauflicht1("lauflicht");lauflicht1.clk(CLOCK);lauflicht1.d_out(DATA);lauflicht1.reset(RESET);lauflicht1.en(EN);lauflicht1.dir(DIR); // Simulation starten - 1000 Zyklensc_start(1000);
return(0);}
34Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Erstellen von Tracefiles (1)
• SystemC unterstützt Erzeugung von Waveform-Tracefiles• Formate: VCD, ASCII WIF, ISDB
• vor Simulationsc_trace_file * my_trace_file;
my_trace_file = sc_create_vcd_trace_file(“my_trace”);
sc_trace(my_trace_file,my_module.d_out,“my_module_d_out");
• nach Simulationsc_close_vcd_trace_file(my_trace_file);
35Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Erstellen von Tracefiles (2)
// Erzeugen eines VCD-Tracefile
sc_trace_file *my_trace_file;
my_trace_file = sc_create_vcd_trace_file("lauflicht_trace");
// Signalverfolgungen
sc_trace(my_trace_file,lauflicht1.clk,"lauflicht_clk");
sc_trace(my_trace_file,lauflicht1.reset,"lauflicht_reset");
sc_trace(my_trace_file,lauflicht1.d_out,"lauflicht_d_out");
// Simulation starten
sc_start(1000);
// VCD-Tracefile schliessen
sc_close_vcd_trace_file(my_trace_file);
36Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Compilieren und Simulieren
• make –f Makefile.gcc aufrufen– bei Problemen Pfad- und Quellcodeangaben überprüfen
• ./lauflicht.x ausführenspice% lauflicht.x
SystemC 2.0.1 --- Apr 4 2002 17:28:28Copyright (c) 1996-2002 by all Contributors
ALL RIGHTS RESERVED* resetting lauflicht ** start lauflicht *WARNING: Default time step is used for VCD tracing.lauflicht value :254lauflicht value :253lauflicht value :251lauflicht value :247lauflicht value :239lauflicht value :223lauflicht value :191
37Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
VCD-Waveformbetrachter - Windows
Winwave – frei verfügbar, basierend auf GTKWave
Signale anzeigen: <Search> <Signal Search Tree>
38Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Zusammenfassung
• Bedeutung von SystemC nimmt zu
• steigende Unterstützung in der Industrie
• Verbesserungen bei Synthese
• Übergang von RTL- zu System-Modellierung
• ideale Anwendung: System-on-Chip
39Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Quellen
• www.systemc.org• „SystemC Version 2.0 User‘s Guide“• „Functional Specification For SystemC 2.0“• Synopsys CoCentric SystemC Compiler „RTL User and Modeling
Guide“• Synopsys CoCentric SystemC Compiler „Behavioral User and
Modeling Guide“• Guido Arnout „OSCI Update“• Thorsten Grötker „Modelling Software with SystemC 3.0“• Jon Connell, Bruce Johnson „Early Hardware/Software Integration
Using SystemC 2.0“• http://www.geocities.com/SiliconValley/Campus/3216/GTKWave/gtkwave-win32.htm
40Einführung in SystemC FG IHS Prof. Andreas Mitschele-Thiel 22-Apr-03
Vielen Dank
Top Related