C15 SystemC Support

Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

Native SystemC Support in Active-HDL Design Entry and Simulation Course 15

15.1. Outline
1. 2.

Overview Design Entry


Creating a transactor with the Transactor Wizard Creating a testbench with the Language Assistant Creating a wrapper with the New SystemC Source Code Wizard

3.

Compilation
Compiling SystemC into a dynamic-link library (*.dll) Adding SystemC modules to the design library

4.

Simulation
SystemC modules in various debugging tools Debugging C Code

All materials updated on: November 20, 2006

15. 1.1 Native SystemC Support


Active-HDL supports SystemC natively SystemC modules are stored in the design library (just like other HDL units) No hand-crafted PLI/VHPI interfaces are needed between SystemC and HDL portions of the Design SystemC modules are displayed by Active-HDL debugging tools Design entry tools for SystemC are available

All materials updated on: November 20, 2006

15. 1.2 SystemC Samples in Active-HDL


Three SystemC designs are included in Active-HDL: serial_receiver Simple VHDL and Verilog models of a serial receiver with a SystemC testbench (used in this training) sc_hex_ram Design demonstrating controlling simple memory module access from SystemC data_acquisition A more advanced sample utilizing the SystemC Verification Library (SCV) Open the serial_receiver design to start the training

All materials updated on: November 20, 2006

15. 1.3 Overview of serial_receiver


The simulation top-level includes three units: rcv A model of a simple serial receiver testwrapper SystemC testbench clk_gen Clock generator used both by HDL (rcv) and SystemC (testwrapper)

All materials updated on: November 20, 2006

15. 1.4 Testbench Overview


The SystemC-based testbench consists of two modules: test Calls functions such as initialize(), send_message() or terminate() transactor Translates function calls to RT-level activity

All materials updated on: November 20, 2006

15. 1.5 SystemC Files Used in the Design


The following files are used by the SystemC part of the design:
*.cpp C++/SystemC files *.h Header files *.dlm C/C++ Configuration file that automates building the SystemC library (*.dll)

Right-click empty area in the Design Browser, select Create New Folder, rename folder to Backup and move the files marked in red to that folder. You will re-create them in this training.

All materials updated on: November 20, 2006

15. 2.1 About Transactors


Why and when do you need a transactor? C/C++ testbenches can be written at an abstraction level higher than RTL High-level testbenches are used for high-level models When a high-level model is translated into RTL, the transactor translates function calls in the testbench into RTlevel stimulus The same testbench can be used throughout the whole design cycle

All materials updated on: November 20, 2006

15. 2.2 Transactor Wizard Overview


The transactor is typically designed in the following manner: the transactor class inherits from two classes: the interface class and the task class the interface class interfaces to the RT-level unit the task class interfaces to the high-level testbench

The Transactor Wizard generates source code skeleton with the class structure shown in the picture above.

All materials updated on: November 20, 2006

15. 2.3 Starting the Wizard


1. Make sure that the HDL part of the design is compiled (left).

2. Start the wizard with the Generate SystemC Transactors command from the Tools menu (right).
All materials updated on: November 20, 2006

15. 2.4 Selecting the Top-Level Unit


The first tab of the wizard allows to select the UUT. You need to select the rcv unit. UUT ports are read from the design library. Conversion of HDL port types to SystemC types is done by the wizard.

All materials updated on: November 20, 2006

15. 2.5 Defining Transactor Methods


The Methods tab allows to define functions that can be used in the testbench to stimulate the UUT. Use New Method button to define three functions:
initialize() send_message (char *msg) terminate()

All three functions should be pure virtual and public and return void.

All materials updated on: November 20, 2006

15. 2.6 Setting Class Names


The Classes tab defines the names of classes that will be used in the transactor. Override the default values suggested by the wizard with the following:
transactor_task_if transactor_port_if transactor

All materials updated on: November 20, 2006

15. 2.7 Setting Names of Output Files


The Files tab defines the names of output files. Override the default values suggested by the wizard with the following:

transactor_args.h transactor_if.h transactor.h transactor.cpp

All materials updated on: November 20, 2006

15. 2.8 Generating Transactor Files


After you configured the wizard, click the Generate button. Transactor files will appear in the Transactor folder:

All materials updated on: November 20, 2006

15. 2.9 Modifying Transactor Files


Work with the skeleton code generated by the wizard. The following changes are needed: adjust the RT-level interface (defined in file transactor_if.h)
implement the three transactor methods (defined in file transactor.cpp) initialize() send_message(char *msg) terminate()

Note: You will be using the SystemC templates located in the Tutorial / SystemC Transactors section of the Language Assistant while making changes.

All materials updated on: November 20, 2006

15. 3.0 Modifying transactor_if.h


Make the following adjustments to transactor_if.h:
delete all references to port data change the direction of the clk port from sc_out to sc_in rename port si to tx

Modified portion of code:


class transactor_port_if : public sc_module { public: sc_in<sc_logic > clk; sc_out<sc_logic > reset; sc_out<sc_logic > tx; transactor_port_if(sc_module_name nm) : sc_module(nm), clk("clk"), reset("reset"), tx("tx") {} };

All materials updated on: November 20, 2006

15. 3.1 Modifying transactor.cpp


Provide the implementation for the intialize() function:
load file transactor.cpp in the HDL Editor select the comment inside the body of the initialize() function void transactor::initialize() { // enter your code here } select Language Assistant from the Tools menu select SystemC in the combo box and expand the following branch: Tutorial | SystemC Transactors | initialize click the Use Template button

All materials updated on: November 20, 2006

15. 3.2 Modifying transactor.cpp (cont.)


Provide the function: implementation for the send_message()

select the comment inside the body of the send_message() function void transactor::send_message() { // enter your code here } expand the following branch in the assistant: Tutorial | SystemC Transactors | send_message click the Use Template button

All materials updated on: November 20, 2006

15. 3.3 Modifying transactor.cpp (cont.)


Provide the implementation for the terminate() function:

select the entire body of the terminate() function void transactor::terminate() { // enter your code here } expand the following branch in the assistant: Tutorial | SystemC Transactors | terminate click the Use Template button close the Language Assistant The development of the transactor is now complete.

All materials updated on: November 20, 2006

15. 3.4 Complete code for transactor.cpp


#include "transactor.h" #include <systemc.h> void transactor::terminate() { for (int i=0; i<2; i++) { wait(clk.posedge_event()); } sc_stop(); } void transactor::initialize() { reset.write(sc_logic_1); tx.write(sc_logic_1); for (int j=0; j<4 ; j++) { wait(clk.posedge_event()); } reset.write(sc_logic_0); } // see continuation in the next column >>> void transactor::send_message (char *msg) { int i = 0; while (msg[i]!='\0') { wait(clk.posedge_event()); tx.write(sc_logic_0); char c = msg[i]; for (int j=0; j<8 ; j++) { wait(clk.posedge_event()); (c>>j & 1) ? tx.write(sc_logic_1) : tx.write(sc_logic_0); } wait(clk.posedge_event()); tx.write(sc_logic_1); i++; } }

All materials updated on: November 20, 2006

15. 3.5 Developing the Testbench (test.h)


The testbench will also be implemented with the help of the Language Assistant. Select File | New | C++ Source from the menu Use the Tutorial | SystemC Transactors | test.h template from the Language Assistant Close the Language Assistant and save the file as test.h

All materials updated on: November 20, 2006

15. 3.6 Complete code for test.h


#ifndef __TEST_H__ #define __TEST_H__ #include <systemc.h> #include "transactor.h" class test : public sc_module { public: sc_port<transactor_task_if> transactor_interface; SC_CTOR(test) { SC_THREAD(main); } void main(); }; #endif //__TEST_H__

All materials updated on: November 20, 2006

15. 3.7 Developing the Testbench (test.cpp)


The testbench uses three functions implemented in the transactor: intialize(), send_message() and terminate(). Select File | New | C++ Source from the menu Use the Tutorial | SystemC Transactors | test.cpp template from the Language Assistant Close the Language Assistant and save the file as test.cpp

All materials updated on: November 20, 2006

15. 3.8 Complete code for test.cpp


Availability of the functions defined in the transactor makes the testbench code very simple.

#include "test.h" void test::main() { transactor_interface->initialize(); transactor_interface->send_message("This is an example of SystemC Transaction Level testbench."); transactor_interface->terminate(); }

All materials updated on: November 20, 2006

15. 3.9 Creating SystemC Wrapper


A wrapper module must be created that instantiates both the testbench and the transactor. Double-click Add New File in the Design Browser

Select the Wizards tab and select the SystemC Source Code icon

All materials updated on: November 20, 2006

15. 3.10 Creating SystemC Wrapper (cont.)


- The first wizard window specifies if the file should be added to the design. Leave the default setting and click Next. - The second window specifies names of source files and the module name. Enter testwrapper in the first edit box; the other boxes will be updated automatically

All materials updated on: November 20, 2006

15. 3.11 Creating SystemC Wrapper (cont.)


- The third window allows to configure the compiler; leave the default values and click Next. - The last window allows to define ports. You need to enter the following: - clk (input) - reset (output) - tx (output) - Click Finish to generate files.
All materials updated on: November 20, 2006

15. 3.12 Creating SystemC Wrapper (cont.)


The *.h and *.cpp files for the wrapper were created by the Wizard. You will now instantiate the testbench and the transactor (added code is in red). You may use the template from the Tutorial / SystemC Transactors while making changes. - Include test and transactor headers
#include <systemc.h> #include "test.h" #include "transactor.h"

- Declare pointers to test and transactor


test *ptst; transactor *ptrans; SC_CTOR(testwrapper) :

All materials updated on: November 20, 2006

15. 3.13 Creating SystemC Wrapper (cont.)


- Create hierarchy
{ ptst = new test("tst"); ptrans = new transactor("trans"); ptrans->clk(clk); ptrans->reset(reset); ptrans->tx(tx); ptst->transactor_interface.bind(*ptrans); }

- Make sure memory is freed


~testwrapper() { delete ptst; delete ptrans; }

All materials updated on: November 20, 2006

15. 3.14 Complete code for testwrapper.h


#ifndef __testwrapper_h__ #define __testwrapper_h__ #include <systemc.h> #include "test.h" #include "transactor.h" SC_MODULE( testwrapper ) { sc_out< sc_logic > reset; sc_out< sc_logic > tx; sc_in< sc_logic > clk; test *ptst; transactor *ptrans; SC_CTOR( testwrapper ): reset("reset"), tx("tx"), clk("clk") // continued in the next column { ptst = new test("tst"); ptrans = new transactor("trans"); ptrans->clk(clk); ptrans->reset(reset); ptrans->tx(tx); ptst->transactor_interface.bind(*ptrans); } ~testwrapper() { delete ptst; delete ptrans; } }; SC_MODULE_EXPORT(testwrapper); #endif //__testwrapper_h__

All materials updated on: November 20, 2006

15. 4.1 C/C++ Configuration Files


The C/C++ Configuration files (*.dlm) make SystemC compilation easy. The testwrapper.dlm was created by the wizard.

All materials updated on: November 20, 2006

15. 4.2 Editing C/C++ Configuration File


Open the testwrapper.dlm file from the Design Browser. Select the Add C/C++ library to design checkbox Add two previously created files to the Files list in the C/C++ Configuration dialog (use button above the file list): test.cpp transactor.cpp Add the Transactor subfolder to the Include Directories list (use button above the list of directories) Leave all other options at their defaults

All materials updated on: November 20, 2006

15. 4.3 Editing C/C++ Configuration File


Modified configuration should look like this:

Click Save to close the *.dlm file


All materials updated on: November 20, 2006

15. 4.4 Building the SystemC Library (*.dll)


- Right-click the *.dlm file in the Design Browser - Select the Build command from the local menu - Active-HDL will launch the gcc compiler. Check the Console for compiler messages.

All materials updated on: November 20, 2006

15. 4.5 Re-compiling the top-level


- The SystemC module (instantiated in test_env.bde) is now visible in the design library.

- Right-click the previously compiled test_env.bde file and select Compile from the menu. The simulation top-level unit will be recompiled and the exclamation mark will change into a check-mark.

The design is now ready for simulation.


All materials updated on: November 20, 2006

15. 4.6 Simulation


- Make sure the test_env unit is selected as the simulation toplevel. - Select Initialize Simulation from the Simulation menu. - The hierarchy of the design (including SystemC modules) is shown on the Structure tab in the Design Browser. SystemC modules are shown in orange.

All materials updated on: November 20, 2006

15. 4.7 Simulation (cont.)


Ports of SystemC modules instantiated in HDL can be observed in the Waveform Editor. - Click the New Waveform button. - Drag test_env signals and testwrapper signals from the Design Browser to the Wavefrom Editor. - Run simulation (use Simulation | Run menu option or Alt+F5 key).

All materials updated on: November 20, 2006

15. 4.8 Simulation (cont.)


Please note that the simulation stops automatically as the result of sc_stop() call in the terminate() method in the transactor.

All materials updated on: November 20, 2006

You might also like