1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC...

18
1 Freeha Azmat Saba Zia Dec 02, 2008 Learning SystemC

Transcript of 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC...

Page 1: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

1

Freeha Azmat

Saba Zia

Dec 02, 2008

Learning SystemC

Page 2: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

AgendaInstallationIntroductionFrom Verilog to SystemCCounter as an ExampleComplete SystemC Modeling

2

Page 3: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

Installation on Linux Download System2.2 from www.systemc.org Run following commands in terminal

cd systemC-2.2 mkdir objdir cd objdir setenv CXX g++ ./configure Gmake debug Gmake instaal Gmake check

Download dinotrace from www.veripool.com/dinotrace tar xvf dinotrace*.tg*z cd dinotrace* ./configure make # Test ./dinotrace traces/ascii.tra make install

3

Page 4: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

Introduction :System C :

Is a C++ Library for system Level ModelingSupports various abstraction Layers

System C is used for :Fast and efficient designsSystem verification

Page 5: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

SystemC VS C++

•Sequential Language

•Not suitable for complex and detailed systems

•Data Types are not suitable for Hardware Implementation

•Parallel Processing is possible

•Incorporate delays, Clocks or Time

•Data Types dedicated to Hardware modeling e.g bit, vector types as well as fixed point types.

System CC ++

Page 6: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

SystemC implementation• Modules• Processes• Ports and Interfaces• Channels

Page 7: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

Modules :Is a C++ ClassEncapsulates hardware /software

descriptionAny Modules has to be derived from the

existing class sc_module.SystemC modules are analogous to verilog

modules or VHDL entity / architecture pair.

Modules communicate to other modules via ports.

Page 8: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

Ports and Interfaces :

Ports are defined as objects inside a modulePublically available to the outside world

through the use of public Keyword.Predefined Ports:

sc_in<>,sc_out<>,sc_inout<>,sc_fifo_in<>,sc_fifo_out<>

Example :sc_in<bool>clk;User Defined Ports are defined with the help of

sc_port class Example:Sc_port <sc_signal_in_if<bool>, 1>

clk;

Page 9: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

Processes :Two kinds of Processes :SC_METHOD: cannot be suspended during its execution

Once the execution of SC_METHOD as been performed it halts and waits for new activities on its sensitivity listSimilar to Verilog always block

SC_THREAD :Can be suspended during execution and resumed at a

later stageSC_THREAD only executes once during simulation and

then suspendsSimilar to Verilog initial Block

Page 10: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

Channels :

SystemC ‘s communication Medium.Modules communicate via ports and channelsThey are similar to Verilog wire and VHDL

signal System C provides a exhaustive range of pre-

defined channels for generic uses such as sc_signal.

This Feature of language differentiate it from VHDL and Verilog

Page 11: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

From Verilog to SystemC

11

module name();// module functionalityendmodule

input A,B;output F;reg [3:0] G;

always @(posedge clk)begin//process sensitive //to rising edge of clock //inputend

SC_MODULE(name){//module functionality}

sc_in<bool> A,B;sc_out<bool> F;sc_uint<4> G;

SC_CTOR(name){//process to executeSC_METHOD(myfunc);//sensitive to clocksensitive<<clk.pos();}

Page 12: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

From Verilog to SystemC

12

add inst(.F(F),.A(A),.B(B));

always @ ()beginend

add inst;SC_CTOR(name):inst(“INST”){inst.A(A);inst.B(B);inst.F(F);}

SC_METHOD(myfunc);

Initialbeginend

SC_THREAD (myfunc);

Page 13: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

Counter

13

#include <systemc.h>

SC_MODULE(counter){

sc_in_clk clk; sc_in<bool>reset;sc_out<sc_uint<4> > counter_out; sc_uint<4> count;

SC_CTOR(counter){SC_METHOD(myfunc);sensitive<<clk.pos();sensitive<<reset;}

void myfunc(){count=0;if(reset.read()==1)counter_out.write(count);elsecount =count + 1;counter_out.write(count);cout<<counter_out.read()<<endl;}};

int sc_main(int argc,char *argv[]){counter c("hello");c.myfunc();sc_start();return(0);}

module counter(clk,reset,counter_out);

input clk;input reset;output [3:0]counter_out;reg [3:0]counter_out;

always @(posedge clk or negedge reset)begin

if(!reset)counter_out<=0;elsecounter_out<=counter_out + 1;

end

endmodule

Page 14: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

Complete SystemC Model

14REF:Introduction to SystemC by Deian Tabakov Rice University Houston, TX

Page 15: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

Stimulus Generator

15

/************************stimulus.h *********************/#include "systemc.h"SC_MODULE(stim) {sc_out<bool> A, B;sc_in<bool> Clk;

void StimGen() {A.write(false);B.write(false);wait(); // wait for the next clock tickA.write(false);B.write(true);wait(); // wait for the next clock tick...sc_stop(); // notify kernel to stop simulation}

SC_CTOR(stim) {SC_THREAD(StimGen);sensitive << Clk.pos();}}; REF:Introduction to SystemC by Deian Tabakov Rice University Houston, TX

Page 16: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

Monitor

16

/************************monitor.h *********************/

#include "systemc.h"SC_MODULE(mon) {sc_in<bool> A, B, F;sc_in_clk Clk;void Monitor() {while(1) {wait();cout << sc_time_stamp() << "\t " << A.read()<< " " << B.read() << " " << F.read() << endl;}}SC_CTOR(mon) {SC_THREAD(Monitor);sensitive << Clk.pos();cout << "Time\t A B F" << endl;}};

REF:Introduction to SystemC by Deian Tabakov Rice University Houston, TX

Page 17: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

Complete XOR Model

17

#include "stim.h"#include "exor.h"#include "mon.h“

int sc_main(int argc, char* argv[]) {sc_signal<bool> ASig, BSig, FSig;sc_clock TestClk("TestClock", 10, SC_NS, 0.5);

stim Stim1("Stimulus"); mon Monitor1("Monitor");Stim1.A(ASig); Monitor1.A(ASig);Stim1.B(BSig); Monitor1.B(BSig);Stim1.Clk(TestClk); Monitor1.F(FSig);Monitor1.Clk(TestClk);

exor DUV("exor");DUV.A(ASig);DUV.B(BSig);DUV.F(FSig);sc_start(); // run foreverreturn 0;}

REF:Introduction to SystemC by Deian Tabakov Rice University Houston, TX

Page 18: 1 Freeha Azmat Saba Zia Dec 02, 2008. Agenda Installation Introduction From Verilog to SystemC Counter as an Example Complete SystemC Modeling 2.

Simulation in Terminal

18REF:Introduction to SystemC by Deian Tabakov Rice University Houston, TX