Documente Academic
Documente Profesional
Documente Cultură
Design
Lecture: SystemC
SystemC
What is it?
SystemC
A C++ library
#include <systemc.h>
Library is a set of C++ classes and
macros for event-driven simulation
Transaction Level Modeling (TLM) (aka Behavioural)
BACK TO VHDL....
SystemC
Lets model a D flip flop (register)
SystemC
Lets model a D flip flop (register)
void p1() {
dout.write(din.read());
}
SC_CTOR(dff) {
SC_METHOD(p1);
sensitive << clk.pos();
}
};
SystemC
Lets model a D flip flop (register)
#include "systemc.h"
SC_MODULE(dff) {
sc_in<bool > clk;
sc_in<bool > din;
sc_out<bool > dout;
void p1() {
dout.write(din.read());
}
SC_CTOR(dff) {
SC_METHOD(p1);
Ports sensitive << clk.pos();
}
};
SystemC
Lets model a D flip flop (register)
#include "systemc.h"
SC_MODULE(dff) {
sc_in<bool > clk;
sc_in<bool > din;
sc_out<bool > dout;
void p1() {
dout.write(din.read());
}
SC_CTOR(dff) {
SC_METHOD(p1);
dont_initialize();
sensitive << clk.pos();
}
};
SystemC
Lets model a D flip flop (register) w/ enable
#include <systemc.h> Flipflop.h
#include "flipflop.h"
Flipflop.cpp
SC_MODULE(flipflop) {
sc_in<bool > clk; sc_int<3> data;
sc_in<bool> enable;
sc_in<sc_uint<3> > din; void flipflop :: ff_method() {
cout << "Enable = " << enable.read() <<", output = ";
sc_out<sc_uint<3> > dout;
if(enable.read() == 1){
void ff_method(); data = din.read();
dout.write(din.read());
SC_CTOR(flipflop) { }
SC_METHOD(ff_method); cout << data.to_string(SC_BIN) << endl;
dont_initialize(); }
sensitive << clk.pos();
}
};
SystemC
Lets model a D flip flop (register)
return 0;
}
SystemC
#include <systemc.h>
#include "flipflop.h"
Signals
return 0;
}
SystemC
int sc_main(int argc, char* argv[]){
...
sc_clock clk("clk",10,SC_NS,0.5); //Create a clock signal
en.write(0); //initialize
data_in.write(0);
sc_start(9, SC_NS);
...
sc_close_vcd_trace_file(tf);
return 0;
}
SystemC
int sc_main(int argc, char* argv[]){
...
sc_clock clk("clk",10,SC_NS,0.5); //Create a clock signal
en.write(0); //initialize
data_in.write(0);
sc_start(9, SC_NS);
...
sc_close_vcd_trace_file(tf);
return 0;
}
SystemC
Makefile used to compile C/C++ projects and are
extremely useful when it is necessary to include several
source, header or library files to create your executable
CC=/usr/bin/g++
ARCH := $(shell arch)
SYSTEMC_HOME=/usr/local/SystemC-2.3.0
.... Makefile
PROGRAM = flipflop.x
SRCS = flipflop.cpp sc_main.cpp
OBJS = flipflop.o sc_main.o
....
SystemC
Lets model a D flip flop (register) w/ enable
#include <systemc.h> Flipflop.h
#include "flipflop.h"
Flipflop.cpp
SC_MODULE(flipflop) {
sc_in<bool > clk; sc_int<3> data;
sc_in<bool> enable;
sc_in<sc_uint<3> > din; void flipflop :: ff_method() {
cout << "Enable = " << enable.read() <<", output = ";
sc_out<sc_uint<3> > dout;
if(enable.read() == 1){
void ff_method(); data = din.read();
dout.write(din.read());
SC_CTOR(flipflop) { }
SC_METHOD(ff_method); cout << data.to_string(SC_BIN) << endl;
dont_initialize(); }
sensitive << clk.pos();
}
};
SystemC I/O Port Types
VHDL Port SystemC Port SystemC Notes
in sc_in
out sc_out Behaves like a VHDL buffer port
inout sc_inout
buffer sc_inout
SystemC Data Types
VHDL Type SystemC Type SystemC Notes
bit sc_bit Use native C++ bool type instead
bit_vector sc_bv Faster in simulation than sc_lv
Only support 4 types, 'X','Z','0'
std_ulogic sc_logic
and '1'
Only support 4 types, 'X','Z','0'
std_ulogic_vector sc_lv
and '1'
Resolution function for 'X','Z','0'
std_logic sc_logic_resolved
and '1'
Resolution function for 'X','Z','0'
std_logic_vector sc_signal_rv
and '1'
boolean bool recommended instead of sc_bit
int size is platform dependent, use
integer int
sizeof(int)
N bits signed/unsigned integer
integer sc_int<N>/sc_uint<N>
vector (N <=64)
arbitrary length signed/unsigned
integer sc_bigint<M>/sc_biguint<M>
integer vector
Native C/C++ 32bits floating point
float float
number
SystemC Data Types
VHDL Type SystemC Type SystemC Notes
bit sc_bit Use native C++ bool type instead
bit_vector sc_bv Faster in simulation than sc_lv
Only support 4 types, 'X','Z','0'
std_ulogic sc_logic
and '1'
Only support 4 types, 'X','Z','0'
std_ulogic_vector sc_lv
and '1'
Resolution function for 'X','Z','0'
std_logic sc_logic_resolved
and '1'
Resolution function for 'X','Z','0'
std_logic_vector sc_signal_rv
and '1'
boolean bool recommended instead of sc_bit
int size is platform dependent, use
integer int
sizeof(int)
N bits signed/unsigned integer
integer sc_int<N>/sc_uint<N>
vector (N <=64)
arbitrary length signed/unsigned
integer sc_bigint<M>/sc_biguint<M>
integer vector
Native C/C++ 32bits floating point
float float
number
sc_logic and sc_lv are unresolved types, only support the 4 signal types
Rule of Thumb Use C++ native types as much as possible. If you dont need
x and z then use: std_logic = <bool>, std_logic_vector = sc_int and sc_uint
SystemC I/O Port Types
VHDL Port SystemC Port SystemC Notes
in sc_in
out sc_out Behaves like a VHDL buffer port
inout sc_inout
buffer sc_inout
- PC counter example
-VHDL vs SystemC
VHDL and SystemC
PC COUNTER EXAMPLE
dont_initialize()
Flipflop.h
#include <systemc.h> #include "flipflop.h" Flipflop.cpp
SC_MODULE(flipflop) { sc_int<3> data;
sc_in<bool > clk;
sc_in<bool> enable; void flipflop :: ff_method() {
sc_in<sc_uint<3> > din; cout << "Enable = " << enable.read() <<", output = ";
sc_out<sc_uint<3> > dout; if(enable.read() == 1){
data = din.read();
void ff_method(); dout.write(din.read());
}
SC_CTOR(flipflop) { cout << data.to_string(SC_BIN) << endl;
SC_METHOD(ff_method); }
dont_initialize();
sensitive << clk.pos();
}
};
sc_start()
int sc_main(int argc, char* argv[]){
...
sc_clock clk("clk",10,SC_NS,0.5); //Create a clock signal
en.write(0); //initialize
data_in.write(0);
sc_start(9, SC_NS);
...
sc_clock clk("clk",10,SC_NS,0.5); //Create a clock signal
without dont_initialize()
Clock Generation
sc_clock clock_name(clockLabel, period,
duty_ratio, offset, initial_value);
SC_MODULE(test) {
SC_CTOR(test_ctor){
....
}
}
Initializing Ports
ENTITY Test IS
port (count : out std_logic_vector(7 downto 0):=X"AA";
zero : out std_logic:='1');
END Test;
SC_MODULE(test) {
SC_CTOR(test_ctor){
....
}
}
Initializing Ports
ENTITY Test IS
port (count : out std_logic_vector(7 downto 0):=X"AA";
zero : out std_logic:='1');
END Test;
SC_MODULE(test) {
sc_inout<sc_lv<8> > count;
sc_out<sc_logic > zero;
SC_CTOR(count) {
...
count.initialize(0xAA);
zero.initialize('1');
...
}
};
Bit Select & Concatenation
-Rotation, shifting, swaps etc
VHDL
port (din : in std_logic_vector(7 downto 0);
dout1 : out std_logic_vector(7 downto 0);
dout2 : out std_logic_vector(7 downto 0));
Architecture
dout1 <= din(0) & din(7 downto 1); -- ROR
dout2 <= din(3 downto 0) & din(7 downto 4); -- Swap Nibble
SystemC
din(7,1) => Range or multiple term concatenation
din[0] => Bit select concatenation
Bit Select & Concatenation
-Rotation, shifting, swaps etc
VHDL
port (din : in std_logic_vector(7 downto 0);
dout1 : out std_logic_vector(7 downto 0);
dout2 : out std_logic_vector(7 downto 0));
Architecture
dout1 <= din(0) & din(7 downto 1); -- ROR
dout2 <= din(3 downto 0) & din(7 downto 4); -- Swap Nibble
SystemC
din(7,1) => Range or multiple term concatenation
din[0] => Bit select concatenation
?
Bit Select & Concatenation
-Rotation, shifting, swaps etc
VHDL
port (din : in std_logic_vector(7 downto 0);
dout1 : out std_logic_vector(7 downto 0);
dout2 : out std_logic_vector(7 downto 0));
Architecture
dout1 <= din(0) & din(7 downto 1); -- ROR
dout2 <= din(3 downto 0) & din(7 downto 4); -- Swap Nibble
SystemC
sc_in<sc_uint<8> > din;
sc_out<sc_uint<8> > dout1;
sc_out<sc_uint<8> > dout2;
SC_MODULE(dff) {
sc_in<bool > clk;
sc_in<bool > din;
sc_out<bool > dout;
void p1() {
dout.write(din.read());
}
SC_CTOR(dff) {
SC_METHOD(p1);
sensitive << clk.pos();
}
};
Processes
SC_METHOD SC_THREAD
#include "systemc.h" #include "systemc.h"
SC_MODULE(dff) { SC_MODULE(dff) {
sc_in<bool > clk; sc_in<bool > clk;
sc_in<bool > din; sc_in<bool > din;
sc_out<bool > dout; sc_out<bool > dout;
SC_METHOD SC_THREAD
#include "systemc.h" #include "systemc.h"
SC_MODULE(dff) { SC_MODULE(dff) {
sc_in<bool > clk; sc_in<bool > clk;
sc_in<bool > din; sc_in<bool > din;
sc_out<bool > dout; sc_out<bool > dout;
SC_MODULE(shiftreg) {
sc_in<bool > clk;
sc_in<bool > reset;
sc_in<bool > din;
sc_out<bool > dout;
SC_CTOR(shiftreg) : dff1("dff1"),
dff2("dff2"), dff3("dff3"), dff4("dff4")
{
dff1.clk(clk);
dff1.reset(reset);
dff1.din(din);
dff1.dout(q1_s);
dff2.clk(clk);
dff2.reset(reset);
dff2.din(q1_s);
dff2.dout(q2_s);
....
}
};
Multiplier Accelerator
HDL Versus SystemC
SystemC
Simulates at the behavioural level
In comparison to ANSI C, designer may
support:
Multiple concurrent processes
Hierarchical designs, modules, and their
communications at the transaction level
Event-driven simulation
HDL Versus SystemC
What cant SystemC do for our SoC
designs?
And what does HDL/RTL provide for our
designs in comparison?