Professional Documents
Culture Documents
Systemc 1 Tutorial
Systemc 1 Tutorial
Systemc 1 Tutorial
%HUQKDUG1LHPDQQ
)UDXQKRIHU,QVWLWXWHIRU
,QWHJUDWHG&LUFXLWV
IIS
Fraunhofer Institut
Integrierte Schaltungen
h'I(**4"
2EMHFWLYHV
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 2
$JHQGD
Unit Topic
1 SystemC Introduction
4 Simple Example
5 Resources
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 3
+'/%DVHG)ORZ
C/C++
4. Hand over specification document HDL
1. Conceptualize
2. Simulate in C++ 5. Understand
3. Write specification 6. (Re)Implement in HDL
document 7. (Re)Verify
8. Synthesize from HDL
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 4
&%DVHG)ORZ
C/C++
C/C++
C/C++
1. Conceptualize
2. Simulate in C++
3. Write specification
document
4. Hand over
• Executable specification
• Testbench
• Written specification
5. Understand
6. Refine in C++
7. Verify reusing testbenches
8. Synthesize from C++
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 5
&DQ&EHXVHGDVLV"
½ SystemC supports
½ Hardware style communication
½ Signals, protocols, etc.
½ Notion of time
½ Time sequenced operations.
½ Concurrency
½ Hardware and systems are inherently concurrent, i.e. they operate in
parallel.
½ Reactivity
½ Hardware is inherently reactive, it responds to stimuli and is in
constant interaction with its environment, which requires handling of
exceptions.
½ Hardware data types
½ Bit type, bit-vector type, multi-valued logic type, signed and unsigned
integer types and fixed-point types.
½ Integrated Simulation Kernel
Refine
½ Behavioral Level
Partition
½synthesizable
½clocked
Behavioral
Behavioral ½I/O cycle accurate
½algorithmic description
abstract Refine
abstract
RTOS
RTOS RTL
RTL ½ RT Level
Refine ½synthesizable
½clocked
target
target ½FSM
code Netlist
Netlist ½data path
code
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 7
'HYHORSLQJ6\VWHP&$Q2YHUYLHZ
your standard
C/C++ development
environment DSP
header files Interface
compiler
IP-Core
.......
libraries
linker ASIC
....
simulation kernel source files for system
and testbenches
make
t able n“
x ecu atio
„e ecific sim.x
sp
executable = simulator
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 8
0RGHO6WUXFWXUH6\VWHP/HYHO
Channel
Channel (implements
(implements I/F)
I/F) SystemC 2.x
Port
Port (accesses
(accesses aa channel’s
channel’s I/F)
I/F)
o Module
o Port
o Interface
Module o Channel
o Process
Interface
Interface
Algorithm
Process
Process (reads
(reads data
data from
from input
input ports
ports IIS
and writes data to output ports)
and writes data to output ports) Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 9
0RGHO6WUXFWXUH,PSOHPHQWDWLRQ/HYHO
Hardware
Hardware signal
signal
Special SystemC 1.0.x
Special ports
ports to
to access
access the
the hardware
hardware signal
signal
o Module
o Special Ports
o Hardware Signal
Module o Process
Algorithm
Process
Process (reads
(reads data
data from
from input
input ports
ports IIS
and writes data to output ports)
and writes data to output ports) Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 10
%DVLF6\VWHP6WUXFWXUH
main.cpp
in1 in2
a1 in1
Stimulus Response
DUT out re
Generator Monitor
a2 in2
clk
Algorithm
stimgen.cpp
stimgen.cpp algo.cpp
algo.cpp monitor.cpp
monitor.cpp
stimgen.h
stimgen.h algo.h
algo.h monitor.h
monitor.h
DUT
out
main.cpp
main.cpp
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 11
&RPSDULVRQ6\VWHP&[9+'/
VHDL SystemC
½ Hierarchy entity module
½ Connection port port
½ Communication signal signal
½ Functionality process process
½ Test Bench object orientation
½ System Level channel, interface, event
abstract data types
½ I/O simple file I/O C++ I/O capabilities
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 12
$JHQGD
Unit Topic
1 SystemC Introduction
4 Simple Example
5 Resources
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 13
$JHQGD
Unit Topic
2.2 Processes
2.3 Hierarchy
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 14
'DWD7\SHV2YHUYLHZ
½ C++ built in data types may be used but are not adequate to
model Hardware.
½ long, int, short, char, unsigned long, unsigned int,
unsigned short, unsigned char, float, double, long double,
and bool.
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 15
:KHQWRXVHZKLFK'DWD7\SHV
To get fast simulations, you have to choose the right data type
Hint: You may use a profiling tool, which tells you, how much
time you spent in which function call, to control simulation
speed.
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 16
:KHQWRXVHZKLFK'DWD7\SHV
To get fast simulations, you have to choose the right data type
Hint: You may use a profiling tool, which tells you, how much
time you spent in which function call, to control simulation
speed.
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 17
VFBLQWVFBXLQWVFBELJLQWVFBELJXLQW6\QWD[
Syntax:
Syntax:
sc_int<length>
sc_int<length> variable_name
variable_name;;
sc_uint<length>
sc_uint<length> variable_name
variable_name;;
sc_bigint<length>
sc_bigint<length> variable_name
variable_name;;
sc_biguint<length>
sc_biguint<length> variable_name
variable_name;;
length:
length:
½½ Specifies
Specifiesthe
thenumber
numberof ofelements
elementsininthe
thearray
array
½½ Must
Mustbebegreater
greaterthan
than00
½½ Must
Mustbebecompile
compiletime
timeconstant
constant
½½ Use
Use [] to bit select and range()to
[] to bit select and range() topart
partselect.
select.
½½ Rightmost
Rightmostis isLSB(0),
LSB(0),Leftmost
Leftmostis isMSB
MSB(n-1)
(n-1)
sc_int<5>
sc_int<5> a;a; //
// aa is
is aa 5-bit
5-bit signed
signed integer
integer
sc_uint<44>
sc_uint<44> b; b; //
// bb is
is aa 44-bit
44-bit unsigned
unsigned integer
integer
sc_bigint<5>
sc_bigint<5> c; c;
cc == 13;
13; // c gets 01101,
// c gets 01101, c[4]
c[4] == 0,
0, c[3]
c[3] == 1,
1, …,
…, a[0]
a[0] == 11
bool
bool d;
d;
dd == c[4];
c[4]; //
// dd gets
gets 00
dd == c[3];
c[3]; //
// dd gets
gets 11
sc_bigint<3>
sc_bigint<3> e; e;
ee == c.range(3,
c.range(3, 1);
1); //
// ee gets
gets 110
110 -- interpreted
interpreted asas -2
-2 IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 18
$JHQGD
Unit Topic
2.2 Processes
2.3 Hierarchy
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 19
0RGXOH
½ A module is a container. It is the
basic building block of SystemC main.cpp
½ Similar to VHDL “entity” a1 in1
Stimulus Response
DUT out re
Generator Monitor
½ Module interface in the header file a2 in2
EXAMPLE: Code
Codeininheader
headerfile:
file:
EXAMPLE: my_module.h
my_module.h
SC_MODULE(my_module)
SC_MODULE(my_module){{
////body
bodyofofmodule
module
};};
Note
Notethe
thesemicolon
semicolonat
atthe
the
end
endofofthe
themodule
moduledefinition
definition
MODULE
Other
Other
Method
Method
Process
Process
Other
Other methods
methods cancan
read/write
read/write ports
ports and
and signals
signals
Process
Process can
can read/write
read/write
ports
ports and
and signals
signals IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 22
3RUWV2YHUYLHZ
½ Ports are the external interface of a module SC_MODULE
{
½ Pass information to and from a module ã Ports
o Signals
½ There are three different kinds of ports o Variables
o Constructor
½ input o Processes
o Modules
½ output };
½ inout
½ Ports are always bound to signals
½ exception: port-to-port binding (explained later)
½ Ports are members of the module
½ Each port has a data type
½ passed as template parameter
main.cpp
a1 in1
Stimulus Response
DUT out re
Generator Monitor
a2 in2
IIS
Fraunhofer Institut
h'I(**4"
clk
Integrierte Schaltungen 23
3RUWV'HFODUDWLRQ
SC_MODULE
{
½ Ports have to be declared inside a module ã Ports
o Signals
½ The direction of the port is specified by the port type o Variables
o Constructor
½ input: sc_in<> o Processes
o Modules
½ output: sc_out<> };
½ inout: sc_inout<>
½ The data type is passed as template parameter
Declaration
Declarationas
asdata
datamembers
membersof
ofthe
themodule:
module:
SC_MODULE(my_mod)
SC_MODULE(my_mod) { {
sc_in<t_data>
sc_in<t_data> port_name;
port_name;
sc_out<t_data>
sc_out<t_data> port_name;
port_name;
sc_inout<t_data>
sc_inout<t_data> port_name;
port_name;
};
};
t_data:
t_data:
½½ data
datatype
typeof
ofthe
theport
port
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 24
6LJQDOV2YHUYLHZ
½ Signals are used for communication SC_MODULE
{
½ Exchange of data in a concurrent execution semantics o Ports
ã Signals
½ between modules o Variables
o Constructor
½ between processes o Processes
o Modules
½ There is only one kind of signal };
clk
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 25
6LJQDOV'HFODUDWLRQ
SC_MODULE
½ Signals are declared inside a module or at top level {
o Ports
½ There is only one type of signal ã Signals
o Variables
½ sc_signal<> o Constructor
o Processes
½ The data type is passed as template parameter o Modules
};
Declaration
Declarationas
asdata
datamembers
membersof
ofthe
themodule:
module:
SC_MODULE(my_mod)
SC_MODULE(my_mod) { {
sc_signal<t_data>
sc_signal<t_data> signal_name;
signal_name;
};
};
t_data:
t_data:
½½ data
datatype
typeof
ofthe
thesignal
signal
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 26
3RUWVDQG6LJQDOV([DPSOH
SC_MODULE
½ Declaring ports and signals within a module {
ã Ports
½ ports and signals are data members of the module ã Signals
o Variables
½ good style to declare o Constructor
o Processes
½ ports at the beginning of the module o Modules
};
½ signals after port declaration
SC_MODULE(module_name)
SC_MODULE(module_name) {{
//
// ports
ports
sc_in<int>
sc_in<int> a; Note:
a; Note:aaspace
spaceisis
sc_out<bool>
sc_out<bool> b; required
b; requiredby
bythe
theC++
C++
sc_inout<sc_bit>
sc_inout<sc_bit> c;
c; compiler
compiler
//
// signals
signals
sc_signal<int>
sc_signal<int> d;
d;
sc_signal<char>
sc_signal<char> e;
e;
sc_signal<sc_int<10>
sc_signal<sc_int<10> >> f;
f;
//
// rest
rest
}; IIS
}; Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 27
3RUWVDQG6LJQDOV5HDGDQG:ULWH
½ To read a value from a port or signal SC_MODULE
{
½ use assignment ã Ports
½ use the .read() method (recommended) ã Signals
o Variables
o Constructor
o Processes
½ To write a value to a port or signal o Modules
};
½ use assignment
½ use the .write() method (recommended)
Example:
Example:
SC_MODULE(count)
SC_MODULE(count) {{
//
// ports
ports && signals
signals not
not shown
shown
int
int count_val;
count_val; //// internal
internal data
data stroage
stroage
sc_int<8>
sc_int<8> mem[512]
mem[512] //
// array
array of
of sc_int
sc_int
//
// Body
Body of
of module
module not
not shown
shown
};
};
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 29
0RGXOH&RQVWUXFWRU
SC_MODULE
{
o Ports
½ Each module has a constructor o Signals
o Variables
½ Called at the instantiation of the module ã Constructor
o Processes
½ initialize internal data structure (e.g. check port-signal o Modules
binding) };
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 30
0RGXOH&RQVWUXFWRU([DPSOH
Code
Codein
inheader
headerfile:
file: SC_MODULE
Example:
Example: {
module_name.h
module_name.h o Ports
o Signals
SC_MODULE
SC_MODULE (my_module)
(my_module) {{ o Variables
//
// Ports,
Ports, internal
internal signals,
signals, processes,
processes, other
other methods
methods ã Constructor
//
// Constructor
Constructor o Processes
o Modules
SC_CTOR(my_module)
SC_CTOR(my_module) {{ };
//
// process
process registration
registration && declarations
declarations ofof sensitivity
sensitivity lists
lists
//
// module
module instantiations
instantiations && port
port connection
connection declarations
declarations
}}
};
};
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 31
$JHQGD
Unit Topic
2.2 Processes
2.3 Hierarchy
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 32
3URFHVV3URSHUWLHV
SC_MODULE
{
o Ports
½ Functionality of a SystemC model is described in processes. o Signals
o Variables
o Constructor
½ Processes are member functions of a module. They are registered ã Processes
o Modules
to the SystemC simulation kernel. };
½ Processes are called by the simulation kernel, whenever a signal in
their sensitivity list is changing.
½ Some processes execute when called and return control to the calling
function (behave like a function).
½ Some processes are called once, and then can suspend themselves
and resume execution later (behave like threads).
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 33
3URFHVV3URSHUWLHV
SC_MODULE
{
o Ports
o Signals
½ Processes use signals to communicate with each other. o Variables
½ Don’t use global variables - may cause order dependencies in o Constructor
ã Processes
code (very bad). o Modules
};
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 34
6\VWHP&3URFHVVHV
SC_MODULE
½ SC_METHOD (sc_async_fprocess) {
o Ports
½ process executes everything and wakes up at next event o Signals
o Variables
½ good for modeling combinational logic o Constructor
ã Processes
½ synchronous logic is sensitive to clock edge o Modules
};
½ SC_THREAD (sc_async_tprocess)
½ execution is suspended on wait() until next event
½ SC_CTHREAD (sc_sync_tprocess)
½ execution is suspended on wait() until next active clock edge
½ within one process can be only registers sensitive to one clock
edge
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 35
$V\QF)XQFWLRQ3URFHVV&KDUDFWHULVWLFV
Processes
ã SC_METHOD
½ Asynchronous Function Process SC_METHOD: o SC_THREAD
o SC_CTHREAD
½ Is sensitive to a set of signals
½ This set is called sensitivity list
½ May be sensitive to any change on a signal
½ May be sensitive to the positive or negative edge of a boolean
signal
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 36
$V\QFKURQRXV)XQFWLRQ3URFHVV8VDJH
Processes
ã SC_METHOD
o SC_THREAD
½ Asynchronous Function Process SC_METHOD: o SC_CTHREAD
½ Model combinational logic
½ multiplexing, bit extraction, bit manipulation, arith. operations...
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 37
'HILQLQJWKH6HQVLWLYLW\/LVWRID3URFHVV
Processes
½ To define the sensitivity list for any process type use ã SC_METHOD
ã SC_THREAD
½ sensitive with the () operator o SC_CTHREAD
½ takes a single port or signal as an argument
½ e.g. sensitive(sig1); sensitive(sig2); sensitive(sig3);
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 38
6&B0(7+2'
Processes
SC_MODULE( my_module ) { ã SC_METHOD
sc_in_clk clk; o SC_THREAD
sc_in<bool> reset_n; o SC_CTHREAD
sc_in<int> in1;
sc_in<int> in2; void my_module::proc1()
{
sc_out<int> out1; int inc = 5;
sc_out<int> out2; inc++;
sc_signal<int> sig1; sig2 = in1.read() + sig1 + inc;
sc_signal<int> sig2; }
int _internal;
void proc1();
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 39
$V\QF7KUHDG3URFHVV&KDUDFWHULVWLFV
Processes
o SC_METHOD
½ Asynchronous Thread Process SC_THREAD: ã SC_THREAD
o SC_CTHREAD
½ Is sensitive to a set of signals
½ This set is called sensitivity list
½ May be sensitive to any change on a signal
½ May be sensitive to the positive or negative edge of a boolean signal
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 40
$V\QFKURQRXV7KUHDG3URFHVV8VDJH
Processes
o SC_METHOD
ã SC_THREAD
o SC_CTHREAD
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 41
7LPLQJ&RQWURO6WDWHPHQWV
Processes
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 42
7KUHDG3URFHVVHVZDLW)XQFWLRQ
Processes
½ wait() may be used in both SC_THREAD and SC_CTHREAD processes
but NOT in an SC_METHOD process (block). o SC_METHOD
ã SC_THREAD
ã SC_CTHREAD
½ wait() suspends execution of the process until the process is
invoked again.
Examples:
Examples:
wait()
wait() ;; //
// waits
waits 11 cycle
cycle in
in synchronous
synchronous process
process
wait(4);
wait(4); //// waits
waits 44 cycles
cycles in
in synchronous
synchronous process
process IIS
wait(4) ; //ERROR!! in Asynchronous process Fraunhofer Institut
wait(4) ; //ERROR!! in Asynchronous process
h'I(**4"
Integrierte Schaltungen 43
6&B7+5($'
Processes
SC_MODULE( my_module ) { void my_module::proc2() o SC_METHOD
sc_in_clk clk; { ã SC_THREAD
sc_in<bool> reset_n; // start-up functionality goes here o SC_CTHREAD
int inc = 1;
sc_in<int> in1;
sc_in<int> in2; while(1) {
out1.write(in2.read() + sig2 + inc);
sc_out<int> out1; ++inc;
sc_out<int> out2; wait();
}
sc_signal<int> sig1; }
sc_signal<int> sig2;
int _internal;
void proc2();
SC_CTOR( my_module ) {
SC_THREAD( proc2 );
State
Stateofofinternal
internalvariables
variablesisispreserved
preserved=>
=>
sensitive << in2 << sig2;
} the
thevalue
valueofofinc
incisisincremented
incrementedby byone
one
}; each
eachtime
timethe
theprocess
processisisreactivated.
reactivated.
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 44
6\QF7KUHDG3URFHVVHV&KDUDFWHULVWLFV
Processes
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 45
6\QF7KUHDG3URFHVVHV&KDUDFWHULVWLFV
Processes
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 46
6\QFKURQRXV7KUHDG3URFHVV,27LPLQJ
Processes
in1 o SC_METHOD
while (true) { o SC_THREAD
in1 out = in1 + in2; ã SC_CTHREAD
out
wait( );
in2 } out
in2
clock clock
in1 1 35 in1 1 35
in2 13 18 in2 13 18
out 14 out 14 53
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 47
6\QFKURQRXV7KUHDG3URFHVV8VDJH
Processes
o SC_METHOD
½ Synchronous Thread Process SC_CTHREAD: o SC_THREAD
ã SC_CTHREAD
½ Useful for high level synthesis.
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 48
6&B&7+5($'
Processes
int _internal;
void proc3();
SC_CTOR( my_module ) {
SC_CTHREAD( proc3, clk.pos() ); State
Stateofofinternal
internalvariables
variablesisispreserved
preserved=>
=>
} the
thevalue
valueofofinc
inc isisincremented
incrementedby byat
ateach
each
}; positive
positiveclock
clockedge.
edge.
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 49
$JHQGD
Unit Topic
2.2 Processes
2.3 Hierarchy
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 50
0RGHOLQJ+LHUDUFK\2YHUYLHZ
SC_MODULE
{
o Ports
½ Systems are modeled hierarchically o Signals
½ SystemC has to provide a mechanism for hierarchy o Variables
o Constructor
½ Solution o Processes
ã Modules
½ Modules may contain instances of other modules };
top
top
sub_a sub_b
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 51
0RGHOLQJ+LHUDUFK\'HILQH,QWHUQDO6LJQDOV
SC_MODULE(top)
SC_MODULE(top) SC_MODULE
{{ ½
½ Define
Define member
member variables
variables {
sc_in<int> for
for all
all the
the internal
internal signals
signals o Ports
sc_in<int> in;
in;
sc_out<int> that
that are needed to connect
are needed to connect o Signals
sc_out<int> out;
out;
the
the child
child module’s
module’s ports
ports to
to o Variables
each
each other.
other. o Constructor
sc_signal<int>
sc_signal<int> sig;
sig; o Processes
½
½ Note:
Note: aa port
port of
of the
the parent
parent ã Modules
sub_a*
sub_a* inst1;
inst1; module
module is directly bound to
is directly bound to };
sub_b*
sub_b* inst2;
inst2; aa port of the child module
port of the child module
....
.... (no
(no signal
signal needed).
needed).
};
};
top
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 52
0RGHOLQJ+LHUDUFK\'HILQH3RLQWHUV
SC_MODULE(top)
SC_MODULE(top) SC_MODULE
{{ ½
½ Define
Define member
member variables
variables {
sc_in<int> that
that are
are pointers
pointers to
to the
the o Ports
sc_in<int> in;
in;
sc_out<int> child
child module’s class for
module’s class for all
all o Signals
sc_out<int> out;
out;
instances
instances o Variables
o Constructor
sc_signal<int>
sc_signal<int> sig;
sig; o Processes
ã Modules
sub_a*
sub_a* inst1;
inst1; };
sub_b*
sub_b* inst2;
inst2;
....
....
};
};
top
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 53
0RGHOLQJ+LHUDUFK\&UHDWH,QVWDQFHV
SC_MODULE
½
½ Create
Create the
the child
child module
module {
SC_CTOR instances
instances within the
within the parent
parent o Ports
SC_CTOR {{
inst1 module’s
module’s constructor using
constructor using o Signals
inst1 == new
new sub_a("inst_1");
sub_a("inst_1");
the C++ keyword new.
the C++ keyword new. o Variables
inst2
inst2 == new
new sub_b("inst_2");
sub_b("inst_2"); o Constructor
½
½ An
An arbitrary
arbitrary name
name isis given
given o Processes
(*inst1).a_out(sig);
(*inst1).a_out(sig); to
to the
the module
module instances.
instances. ItIt ã Modules
(*inst1).a_in(in);
(*inst1).a_in(in); is
is good
good practice
practice to
to use
use the
the };
name of the instance
name of the instance
(*inst2)(sig,
(*inst2)(sig, b_out);
b_out); variable.
variable.
}}
top
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 54
0RGHOLQJ+LHUDUFK\&RQQHFW3RUWVDQG6LJQDOV
SC_MODULE
½
½ Connect
Connect ports
ports of
of child
child {
SC_CTOR modules
modules to one another with
to one another with o Ports
SC_CTOR {{
inst1 internal signals.
internal signals. o Signals
inst1 == new
new sub_a("inst_1");
sub_a("inst_1");
o Variables
inst2
inst2 == new
new sub_b("inst_2");
sub_b("inst_2"); ½
½ Connect
Connect ports
ports of
of the
the parent
parent o Constructor
module
module to
to ports
ports of
of the
the child
child o Processes
(*inst1).a_out(sig);
(*inst1).a_out(sig); module
module using
using direct
direct port-to-
port-to- ã Modules
(*inst1).a_in(in);
(*inst1).a_in(in); port connection. A signal
port connection. A signal };
MUST
MUST NOT
NOT be
be used.
used.
(*inst2)(sig,
(*inst2)(sig, b_out);
b_out);
}}
½
½ Mapping
Mapping by
by name
name is
is
recommended.
recommended.
½
½ Mapping
Mapping by
by position
position may
may also
also
be
be used.
used.
top
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 55
$JHQGD
Unit Topic
4 Simple Example
5 Resources
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 56
6\VWHP&'HVLJQ)ORZ
Software UTF Hardware
UTF ½ System/ Architectural Level
½not synthesizable
Refine ½event driven
½abstract communication
TF
TF ½abstract data types
Refine
½ Behavioral Level
Partition
½synthesizable
½clocked
Behavioral
Behavioral ½I/O cycle accurate
½algorithmic description
abstract Refine
abstract
RTOS
RTOS RTL
RTL ½ RT Level
Refine ½synthesizable
½clocked
target
target ½FSM
code Netlist
Netlist ½data path
code
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 57
$YDLODEOH)XQFWLRQDOLW\DQG7RROV
½ System/Architectural Level
½ channels, interfaces, events, master-slave comm. library (all beta)
½ Behavioral
½ synthesis to netlist
½ RTL
½ synthesis to netlist
½ Software
½ abstract RTOS (not yet available)
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 58
5HILQHPHQWIRU6\QWKHVLV
½ Refine Structure
Functional Description
½ use signals for I/F
½ partition into synthesizable blocks
½ restrict to synthesizable language subset
½ Refine Control
½ specify throughput/latency Structure Control Data
½ specify I/O protocol
½ Refine Data
½ restrict to physically meaningful data
types (no abstract data)
½ specify bit width Implementable Description
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 59
%HKDYLRUDO0RGHOLQJ6\VWHP
CPU
Clk
algorithmic driven
Bus IF
Clk
algorithmic driven I/O Board Disk
Bus IF
Clk Clk
driven algorithmic driven algorithmic
Memory Bus IF Bus IF
Clk
Bus driven
Arbiter Bus IF
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 60
%HKDYLRUDO0RGHOLQJ0RGXOH
½Interface cycle accurate
½ ports and signals
½ synthesizable data types
½ introduction of a clock
SC_MODULE(fir) {
sc_in_clk clk; ½Rest of module
sc_in<bool> reset; ½ algorithmic
sc_in<T_DATA> in; ½ clocked (SC_CTHREAD)
sc_in<bool> in_data_valid;
½ restriction to synthesizable SystemC
sc_out<T_DATA> out;
sc_out<bool> out_data_valid; subset
...
SC_CTOR(fir) {
SC_CTHREAD(fir_process, clk.pos());
½Behavioral Code may utilize
... ½ functions to reduce code complexity
} ½ loops
};
½ conditional statements
½ no abstract data types for
ports/signals
½ only synthesizable subset of
SystemC
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 61
57/HYHO0RGHOLQJ6\VWHP
CPU
CLK
driven
Bus
Arbiter
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 62
57/HYHO0RGHOLQJ0RGXOH
½Interface cycle accurate
½ ports and signals
SC_MODULE(fir) {
sc_in_clk clk; ½ synthesizable data types
sc_in<bool> reset; ½ introduction of a clock
sc_in<T_DATA> in;
sc_in<bool> in_data_valid;
sc_out<T_DATA> out; ½Rest of module
sc_out<bool> out_data_valid; ½ cycle accurate
... ½ sequential and combinational logic
sc_signal<T_STATE> state_curr, state_nxt;
... (SC_METHOD)
SC_CTOR(fir) { ½ restriction to synthesizable SystemC
SC_METHOD(fir); subset
sensitive << state_curr << in;
SC_METHOD(fsm);
sensitive << state_curr << data_valid; ½RTL Code may utilize
SC_METHOD(reg); ½ functions to reduce code complexity
sensitive_pos << clk;
sensitive << reset; ½ loops
... ½ conditional statements
} ½ no abstract data types for
};
ports/signals
½ only synthesizable subset of
SystemC IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 63
$JHQGD
Unit Topic
4 Simple Example
5 Resources
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 64
6LPSOH([DPSOH2YHUYLHZ
in1 in2
main.cpp
a1 in1
Stimulus Response
Adder out re
Generator Monitor
a2 in2
clk
+
stimgen.cpp
stimgen.cpp adder.cpp
adder.cpp monitor.cpp
monitor.cpp
stimgen.h
stimgen.h adder.h
adder.h monitor.h
monitor.h
out
main.cpp
main.cpp
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 65
6LPSOH([DPSOH6LPXODWLRQ0RGHO
//
// header
header file
file adder.h
adder.h
typedef
typedef int
int T_ADD;
T_ADD; main.cpp
SC_MODULE(adder)
SC_MODULE(adder) {{ a1 in1
//
// Input
Input ports
ports Stimulus Response
sc_port<sc_fifo_in_if<T_ADD>
sc_port<sc_fifo_in_if<T_ADD> >> in1; Adder out re
in1; Generator Monitor
sc_port<sc_fifo_in_if<T_ADD>
sc_port<sc_fifo_in_if<T_ADD> >> in2;
in2;
a2 in2
//
// Output
Output ports
ports
sc_port<sc_fifo_out_if<T_ADD>
sc_port<sc_fifo_out_if<T_ADD> >> in2;
in2; clk
//
// Constructor
Constructor
SC_CTOR(adder){
SC_CTOR(adder){
SC_THREAD(main);
SC_THREAD(main);
}}
stimgen.cpp
stimgen.cpp adder.cpp
adder.cpp monitor.cpp
monitor.cpp
//
// Functionality
Functionality of
of the
the process
process
void
void main();
main(); stimgen.h
stimgen.h adder.h
adder.h monitor.h
monitor.h
};
};
main.cpp
main.cpp
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 66
6LPSOH([DPSOH6LPXODWLRQ0RGHO
main.cpp
a1 in1
Stimulus Response
//
// Implementation
Implementation file
file adder.cpp
adder.cpp Adder out re
Generator Monitor
#include
#include “systemc.h”
“systemc.h” a2 in2
#include
#include “adder.h”
“adder.h”
void
void adder::main()
adder::main() clk
{{
while
while (true)
(true) {{
out->write(in1->read()
out->write(in1->read() ++ in2->read());
in2->read());
//
// assign
assign aa run-time
run-time to
to process
process
wait(10,
wait(10, SC_NS);
SC_NS);
}} stimgen.cpp
stimgen.cpp adder.cpp
adder.cpp monitor.cpp
monitor.cpp
}}
stimgen.h
stimgen.h adder.h
adder.h monitor.h
monitor.h
main.cpp
main.cpp
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 67
6LPSOH([DPSOH%HKDYLRUDO/HYHO
// Constructor stimgen.cpp
stimgen.cpp adder.cpp
adder.cpp monitor.cpp
monitor.cpp
SC_CTOR(adder){
SC_CTHREAD(main, clk.pos());
stimgen.h
stimgen.h adder.h
adder.h monitor.h
monitor.h
}
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 68
6LPSOH([DPSOH%HKDYLRUDO/HYHO
main.cpp
// Implementation file adder.cc
#include “systemc.h” a1 in1
#include “adder.h” Stimulus Response
Adder out re
Generator Monitor
void adder::main()
{ a2 in2
// initialization
T_ADD __in1 = 0; clk
T_ADD __in2 = 0;
T_ADD __out = 0;
out.write(__out);
wait();
stimgen.cpp
stimgen.cpp adder.cpp
adder.cpp monitor.cpp
monitor.cpp
// infinite loop
while(1) {
__in1 = in1.read(); stimgen.h
stimgen.h adder.h
adder.h monitor.h
monitor.h
__in2 = in2.read();
__out = __in1 + __in2;
out.write(__out);
wait();
} main.cpp
main.cpp
}
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 69
6LPSOH([DPSOH57/HYHO
// internal signal
sc_signal<T_ADD> sum;
// Constructor
stimgen.cpp
stimgen.cpp adder.cpp
adder.cpp monitor.cpp
monitor.cpp
SC_CTOR(adder){
SC_METHOD(add);
sensitive << in1 << in2; stimgen.h
stimgen.h adder.h
adder.h monitor.h
monitor.h
SC_METHOD(reg);
sensitive_pos << clk;
}
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 70
6LPSOH([DPSOH57/HYHO
// Implementation file adder.cc
#include “systemc.h”
#include “adder.h”
void adder::add()
main.cpp
{
T_ADD __in1 = in1.read(); a1 in1
T_ADD __in2 = in2.read(); Stimulus Response
Adder out re
Generator Monitor
sum.write( __in1 + __in2 ); a2 in2
}
stimgen.cpp
stimgen.cpp adder.cpp
adder.cpp monitor.cpp
monitor.cpp
stimgen.h
stimgen.h adder.h
adder.h monitor.h
monitor.h
main.cpp
main.cpp
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 71
6LPSOH([DPSOH6FUHHQVKRW
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 72
$JHQGD
Unit Topic
4 Simple Example
5 Resources
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 73
6\VWHP&:HE6LWH
www.systemc.org
½download
½news
½forum (mailing list)
½FAQs
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 74
7UDLQLQJLQ(XURSH
½ http://www.iis.fhg.de/kursbuch/kurse/systemc.html
IIS
Fraunhofer Institut
h'I(**4"
Integrierte Schaltungen 75