ip core design - lecture 7 - introduction to...
TRANSCRIPT
IP Core Design
Lecture 7Introduction to SystemC
Juinn-Dar Huang, Ph.D.Assistant Professor
September 2004
Courtecy: Cadence Design, Inc.
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
1copyright © 2004
Outlines
– SystemC applications– SystemC language– SystemC data types– SystemC processes– Simulation control
SystemC Applications
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
3copyright © 2004
Nature of SystemC
• SystemC is actually a C++ class library– enable H/W models at different levels of abstraction– support various development processes– focus on system-level design, modeling and verification
• Goal– provide a unified environment for architects, verification
engineers and implementation engineers
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
4copyright © 2004
Different Levels of Abstraction (1/3)Concept
Abstraction
Algorithm Selection/Performance Analysis
Architecture Selection/Finite Wordlength
Effects Analysis
Architecture MappingHW/SW Mapping
HW/RTL SW/C
SystemCSPW,
COSSAP
Matlab
HDL
C/C++
Not Easy
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
5copyright © 2004
Different Levels of Abstraction (2/3)
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
6copyright © 2004
Different Levels of Abstraction (3/3)
To be available in v3.x
Available in v2.x
Available in v1.x
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
7copyright © 2004
Heterogeneous Environment
Functional System Specification(HW, SW, environment) in C/C++
DigitalHW Block
DesignSW Block Design
AMSHW Block
Design
System Architecture
Het
erog
eneo
usM
ultil
evel
Ver
ifica
tion
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
8copyright © 2004
What is SystemC?•Open source C++ class library and event-driven simulator
SystemC 1.0
RTL level of abstraction
Separates function from communication with concepts of ports, signals, data types
SystemC 3.0
Focus on software and scheduler modeling
SystemC 2.0
System Level modeling on top of 1.0
Addition of communication and synchronization in the form of channels, interfaces, and events
Oct 2001
SystemCVerificationStandard (SCV)
Transaction-based verification
Randomization
Constraint solver
Oct 2002Mar 2000
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
9copyright © 2004
SystemC 2.0 Language Architecture (1/2)
C++ Language Standard
Core LanguageModulesPortsProcessesEventsInterfacesChannelsEvent-driven Simulation Kernel
Data-Types
4-valued logic types (01zx)4-valued logic vectorsBits and bit-vectorsArbitrary-precision integersFixed-point numbersC++ user-defined types
Elementary ChannelsSignal, Timer, Mutex, Semaphore, FIFO, etc.
Standard Channels for Various Models of Computation (MOCs)Kahn Process NetworksStatic Dataflow, etc.
Methodology Specific Channels
Master/Slave Library, etc.
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
10copyright © 2004
SystemC 2.0 Language Architecture (2/2)
1.0
2.0
3.0
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
11copyright © 2004
SystemC’s Target
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
12copyright © 2004
SystemC Cannot Cover All
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
13copyright © 2004
SystemC’s Target Applications
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
14copyright © 2004
SystemC Does Not Try …
• SystemC is NOT– replacement of HDL and associated simulation tools
• especially gate-level modeling
– replacement of domain-specific tools• such as Matlab, COSSAP, SPW, …
– next generation HDL• SystemVerilog, Verilog-200X
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
15copyright © 2004
SystemC Simulation Environment
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
16copyright © 2004
SystemC Resources (1/2)– WWW resources
• The Open SystemC Initiative (OSCI)http://www.systemc.org/
– Books• System Design with SystemC
Kluwer Academic Publisher ISBN 1-402070721• SystemC: Methodologies and Applications
Kluwer Academic Publisher ISBN 1-402074794• A SystemC Primer
Star Galaxy Publishing ISBN 0-965039188
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
17copyright © 2004
SystemC Resources (2/2)
• Documentations• SystemC Version 2.0 User’s Guide (update for 2.0.1)
UserGuide20.pdf• Functional Specification for SystemC 2.0 (update for SystemC 2.0.1)
FuncSpec20.pdf
• Examples• examples/systemc/ directory
simple_fifo, simple_perf, simple_bus, rsa, risc_cpu, pkt_switch, pipe, forkjoin, fir, fft…
SystemC Language
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
19copyright © 2004
Modules and HierarchyPort
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
20copyright © 2004
Processes
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
21copyright © 2004
Ports and Channels
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
22copyright © 2004
Example – Adder with Register (1/3)
+a
b
clk
Adder Register
temp c
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
23copyright © 2004
Example – Adder with Register (2/3)
#include “systemc.h”
SC_MODULE(adder_reg) {// input portsc_in<sc_int<8> > a; sc_in<sc_int<8> > b; // output port sc_out<sc_int<9> > c; // clocksc_in<bool> clk;
// Internal signalsc_signal<sc_int<9> > temp;
// Adder processvoid prc_add();
// Register update processvoid prc_reg();
// ConstructorSC_CTOR(adder_reg) {SC_METHOD(prc_add);sensitive << a << b;SC_METHOD(prc_reg);sensitive_pos << clk;
}};
adder_reg.h
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
24copyright © 2004
Example – Adder with Register (3/3)
#include “adder_reg.h”
// Adder processvoid adder_reg::prc_add() {temp = a + b;
}
// Register update processvoid adder_reg::prc_reg() {c = temp;
}
adder_reg.cpp
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
25copyright © 2004
Hierarchical Coding (1/3)
// adder.h#include “systemc.h”
SC_MODULE(adder) {// input portsc_in<sc_int<8> > a; sc_in<sc_int<8> > b; // output port sc_out<sc_int<9> > c;
// Adder processvoid prc_add();
// ConstructorSC_CTOR(adder) {SC_METHOD(prc_add);sensitive << a << b;
}};
// adder.cpp#include “adder.h”// Adder processvoid adder::prc_add() {c = a + b;
}
Return to SC_METHOD
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
26copyright © 2004
Hierarchical Coding (2/3)
// reg.h#include “systemc.h”
SC_MODULE(reg) {// input portsc_in<sc_int<9> > in; // output port sc_out<sc_int<9> > out; // clocksc_in<bool> clk;
// Register update processvoid prc_reg();
// ConstructorSC_CTOR(reg) {SC_METHOD(prc_reg);sensitive_pos << clk;
}};
// reg.cpp#include “reg.h”// Register update processvoid reg::prc_reg() {out = in;
}
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
27copyright © 2004
Hierarchical Coding (3/3)
#include “systemc.h”#include “adder.h”#include “reg.h”
SC_MODULE(adder_reg) {sc_in<sc_int<8> > a; sc_in<sc_int<8> > b; sc_out<sc_int<9> > c; sc_in<bool> clk;
// Instantiated objectsadder add1;reg reg1;
// Internal signalsc_signal<sc_int<9> > temp;// sc_signal is a SystemC// built-in channel
// ConstructorSC_CTOR(adder_reg): add1(“add1”), reg1(“reg1”){
// port bindingadd1(a, b, temp); // pos
reg1.in(temp); // namereg1.out(c); // namereg1.clk(clk); // name
}};
adder_reg.h
SystemC Data Types
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
29copyright © 2004
SystemC Data Types
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
30copyright © 2004
Bit Types
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
31copyright © 2004
Integer Types
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
32copyright © 2004
sc_int<n>
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
33copyright © 2004
sc_int<n> and sc_uint<n>
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
34copyright © 2004
Arbitrary Sized Integer Types
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
35copyright © 2004
Arbitrary Sized Vector Types (1/2)
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
36copyright © 2004
Arbitrary Sized Vector Types (2/2)
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
37copyright © 2004
sc_bv<n> and sc_lv<n>
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
38copyright © 2004
Impact on Simulation Performance
Faster
Native (built-in) C++ data typeNative (built-in) C++ data type
Fixed precision integer data typeFixed precision integer data type
Arbitrary precision integer data typeArbitrary precision integer data typesc_big(u)int<n>sc_big(u)int<n>
sc_bv<n>sc_bv<n>Slower
sc_lv<n>sc_lv<n>
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
39copyright © 2004
SystemC Data Types
Type Description Remarkssc_bit 2 value single bitsc_logic 4 value single bitsc_int<n> n bit signed integersc_uint<n> n bit unsigned integersc_bigint<n> arbitrary sized signed integersc_biguint<n> arbitrary sized unsigned integersc__bv<n> arbitrary sized 2 value vectorsc_lv<n> arbitrary sized 4 value vectorsc_fixed<> templated signed fixed pointsc_ufixed<> templated unsigned fixed pointsc_fix untemplated signed fixed pointsc_ufix untemplated unsigned fixed point
O < n <= 512
0 < n <= 64
More com
plex
Faster
Processes
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
41copyright © 2004
SystemC Processes
• Processes describe the functionality and allow concurrency
• Processes are not hierarchical– it’s illegal to call another process within a process
• Two kinds of processes– Method process: SC_METHOD– Thread process: SC_THREAD
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
42copyright © 2004
SC_METHOD
• Execute from the head to the end at every activation of sensitized signals
• Return the control to the simulation kernel once the execution is completed
• Cannot call wait() in a SC_METHOD process
Example
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
43copyright © 2004
SC_THREAD
• Similar to SC_METHOD– registration way, sensitivity list specification, …
• It usually call wait()• When the execution encounters a wait()
statement, the process is suspended• It resumes from the suspend only if the process
detects activations of sensitized signals• SC_THREAD simulates much slower than
SC_METHOD
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
44copyright © 2004
SC_THREAD ExampleSC_MODULE(tb) {// ...bool clk; // 50% duty cyclebool biased_clk;// H-H-L, 67% duty cuclevoid prc_clk_gen();// ...SC_CTOR(tb) {// ...SC_THREAD(prc_clk_gen);sensitive_pos << clk;
// ...}// ...
};
void tb::prc_clk_gen() {while(true){ // infinite loopbiased_clk = true;wait();biased_clk = true;wait();biasd_clk = false; wait();
}}
Simulation Control
Introduction to SystemC
Juinn-Dar H
uang jdhuang@m
ail.nctu.edu.tw
46copyright © 2004
Simulation Topmonitor u_mon(“u_mon”);u_mon(in1, in2, in3, out1);
sc_trace_file * tf =sc_create_vcd_trace_file(“a”);sc_trace(tf, out1, “out1”);
sc_start(100, SC_NS);// sc_start(-1); forever// sc_stop(); terminate
sc_close_vcd_trace_file(tf);
return 0;}
#include “systemc.h”#include “duv.h”#include “driver.h”#include “monitor.h”
int sc_main(int argc,char *argv[]) {
sc_signal<bool> in1, in2, in3,out1;
duv u_duv(“u_duv”);u_duv(in1, in2, in3, out1);
driver u_driver(“u_driver”);u_driver(in1, in2, in3);