of 39
7/31/2019 C15 SystemC Support
1/39
Nat ive SystemC Support
in Act ive-HDL
Design Ent ry andSimulation
Course 15
7/31/2019 C15 SystemC Support
2/39
All materials updated on: November 20, 2006
15.1. Out line15.1. Out line
1. Overview
2. 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
7/31/2019 C15 SystemC Support
3/39
All materials updated on: November 20, 2006
15. 1.1 Nat ive SystemC Suppor t15. 1.1 Nat ive SystemC Suppor t
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 betweenSystemC and HDL portions of
the Design
SystemC modules are displayedby Active-HDL debugging tools
Design entry tools for SystemCare available
7/31/2019 C15 SystemC Support
4/39All materials updated on: November 20, 2006
15. 1.2 SystemC Samples in Act ive-HDL15. 1.2 SystemC Samples in Act ive-HDL
Three SystemC designs are included in Active-HDL:
serial_receiverSimple VHDL and Verilog models of a serial receiver with aSystemC testbench (used in this training)
sc_hex_ramDesign demonstrating controlling simple memory module accessfrom SystemC
data_acquisitionA more advanced sampleutilizing the SystemCVerification Library (SCV)
Open the serial_receiverdesign to start the training
7/31/2019 C15 SystemC Support
5/39All materials updated on: November 20, 2006
15. 1.3 Overview of serial_receiver15. 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_genClock generator used both by HDL (rcv)and SystemC (testwrapper)
7/31/2019 C15 SystemC Support
6/39All materials updated on: November 20, 2006
15. 1.4 Testbench Overview15. 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
7/31/2019 C15 SystemC Support
7/39All materials updated on: November 20, 2006
15. 1.5 SystemC Files Used in t he Design15. 1.5 SystemC Files Used in t he Design
The following files are used bythe SystemC part of the design:
* .cppC++/SystemC files
* .hHeader files
* .d lmC/C++ Configuration file that automatesbuilding the SystemC library (* .dl l)
Right-click empty area in the Design Browser,
select Create New Folder, rename folderto Backupand move the files marked in redto that folder.You will re-create them in this training.
7/31/2019 C15 SystemC Support
8/39
7/31/2019 C15 SystemC Support
9/39All materials updated on: November 20, 2006
15. 2.2 Transactor Wizard Overview15. 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 withthe class structure shown in the picture above.
7/31/2019 C15 SystemC Support
10/39
All materials updated on: November 20, 2006
15. 2.3 Start ing the Wizard15. 2.3 Start ing the Wizard
1. Make sure that the HDL part of the design is compiled (left).
2. Start the wizard with the Generate SystemCTransactors command from the Tools menu (right).
7/31/2019 C15 SystemC Support
11/39
All materials updated on: November 20, 2006
15. 2.4 Select ing the Top-Level Unit15. 2.4 Select ing the Top-Level Unit
The first tab of the wizard allows to select the UUT. You needto select the rcv unit.
UUT ports are read from thedesign library.
Conversion of HDL port typesto SystemC types is done bythe wizard.
7/31/2019 C15 SystemC Support
12/39
All materials updated on: November 20, 2006
15. 2.5 Def ining Transactor Methods15. 2.5 Defining Transactor Methods
The Methods tab allows to define functions that can be usedin the testbench to stimulate the UUT.
Use New Method button todefine three functions:
initialize()
send_message (char *msg)
terminate()
All three functions should bepure virtual and public andreturn void.
7/31/2019 C15 SystemC Support
13/39
All materials updated on: November 20, 2006
15. 2.6 Set t ing Class Names15. 2.6 Set t ing Class Names
The Classes tab defines the names of classes that will beused in the transactor.
Override the default valuessuggested by the wizard withthe following:
transactor_task_if
transactor_port_if
transactor
7/31/2019 C15 SystemC Support
14/39
All materials updated on: November 20, 2006
15. 2.7 Set t ing Names of Out put Files15. 2.7 Set t ing Names of Out put Files
The Files tab defines the names of output files.
Override the default valuessuggested by the wizard withthe following:
transactor_args.h
transactor_if.h
transactor.h
transactor.cpp
7/31/2019 C15 SystemC Support
15/39
All materials updated on: November 20, 2006
15. 2.8 Generat ing Transactor Files15. 2.8 Generat ing Transactor Files
After you configured the wizard, click the Generate button.
Transactor files will appear inthe Transactor folder:
7/31/2019 C15 SystemC Support
16/39
All materials updated on: November 20, 2006
15. 2.9 Modifying Transactor Files15. 2.9 Modifying Transactor Files
Work with the skeleton code generated by the wizard. Thefollowing 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 theTutorial / SystemC Transactorssection of the Language Assistantwhile making changes.
7/31/2019 C15 SystemC Support
17/39
All materials updated on: November 20, 2006
15. 3.0 Modifying t ransactor_if.h15. 3.0 Modifying t ransactor_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 clk;
sc_out reset;
sc_out tx;
transactor_port_if(sc_module_name nm) : sc_module(nm),
clk("clk"),
reset("reset"),
tx("tx")
{}
};
7/31/2019 C15 SystemC Support
18/39
All materials updated on: November 20, 2006
15. 3.1 Modifying t ransactor.cpp15. 3.1 Modifying t ransactor.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 | init ial ize
click the Use Template button
7/31/2019 C15 SystemC Support
19/39
All materials updated on: November 20, 2006
15. 3.2 Modifying t ransactor.cpp (cont .)15. 3.2 Modifying t ransactor.cpp (cont .)
Provide the implementation for the send_message()function:
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 | SystemCTransactors | send_message
click the Use Template button
7/31/2019 C15 SystemC Support
20/39
All materials updated on: November 20, 2006
15. 3.3 Modifying t ransactor.cpp (cont .)15. 3.3 Modifying t ransactor.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 | SystemCTransactors | t erm inate
click the Use Template button
close the Language Assistant
The development of the transactor is now complete.
7/31/2019 C15 SystemC Support
21/39
All materials updated on: November 20, 2006
15. 3.4 Complete code for t ransactor.cpp15. 3.4 Complete code for t ransactor.cpp
#include "transactor.h"
#include
void transactor::terminate()
{
for (int i=0; i>
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>j & 1) ? tx.write(sc_logic_1) : tx.write(sc_logic_0);
}
wait(clk.posedge_event());
tx.write(sc_logic_1);
i++;
}
}
7/31/2019 C15 SystemC Support
22/39
All materials updated on: November 20, 2006
15. 3.5 Developing the Testbench ( t est .h)15. 3.5 Developing the Testbench ( t est .h)
The testbench will also be implemented with the help of theLanguage Assistant .
Select File | New | C++ Source from the menu
Use the Tut orial | SystemC Transactors | t est .h
template from the Language Assistant
Close the Language Assistant and save the file as test.h
7/31/2019 C15 SystemC Support
23/39
All materials updated on: November 20, 2006
15. 3.6 Complete code for t est .h15. 3.6 Complete code for t est .h
#ifndef __TEST_H__
#define __TEST_H__
#include
#include "transactor.h"
class test : public sc_module
{
public:
sc_port transactor_interface;
SC_CTOR(test)
{
SC_THREAD(main);
}
void main();
};
#endif //__TEST_H__
7/31/2019 C15 SystemC Support
24/39
All materials updated on: November 20, 2006
15. 3.7 Developing t he Testbench ( t est .cpp)15. 3.7 Developing t he Testbench ( t est .cpp)
The testbench uses three functions implemented in thetransactor: intialize(), send_message() andterminate().
Select File | New | C++ Source from the menu
Use the Tutorial | SystemC Transactors | t est .cpptemplate from the Language Assistant
Close the Language Assistant and save the file as test.cpp
7/31/2019 C15 SystemC Support
25/39
All materials updated on: November 20, 2006
15. 3.8 Complete code for t est .cpp15. 3.8 Complete code for t est .cpp
Availability of the functions defined in the transactor makesthe 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();
}
7/31/2019 C15 SystemC Support
26/39
All materials updated on: November 20, 2006
15. 3.9 Creat ing SystemC Wrapper15. 3.9 Creat ing SystemC Wrapper
A wrapper module must be created that instantiates both thetestbench and the transactor.
Double-clickAdd New File in the Design Browser
Select the Wizards taband select the SystemCSource Code icon
7/31/2019 C15 SystemC Support
27/39
All materials updated on: November 20, 2006
15. 3.10 Creat ing SystemC Wrapper (cont .)15. 3.10 Creat ing SystemC Wrapper (cont .)
- The first wizard windowspecifies if the file should
be added to the design.Leave the default settingand clickNext .
- The second windowspecifies names of sourcefiles and the modulename.
Enter testwrapper in thefirst edit box; the otherboxes will be updatedautomatically
7/31/2019 C15 SystemC Support
28/39
All materials updated on: November 20, 2006
15. 3.11 Creat ing SystemC Wrapper (cont .)15. 3.11 Creat ing SystemC Wrapper (cont .)
- The third window allows toconfigure the compiler;
leave the default valuesand clickNext .
- The last window allows to
define ports. You need toenter the following:
- clk (input)
- reset (output)
- tx (output)
- Click Finish to generate
files.
7/31/2019 C15 SystemC Support
29/39
All materials updated on: November 20, 2006
15. 3.12 Creat ing SystemC Wrapper (cont .)15. 3.12 Creat ing SystemC Wrapper (cont .)
The *.h and *.cpp files for the wrapper were created by theWizard. You will now instantiate the testbench and the transactor
(added code is in red).You may use the template from the Tutorial / SystemC Transactorswhile making changes.
- Include test and transactor headers#include #include "test.h"
#include "transactor.h"
- Declare pointers to test and transactortest *ptst;
transactor *ptrans;
SC_CTOR(testwrapper) :
7/31/2019 C15 SystemC Support
30/39
All materials updated on: November 20, 2006
15. 3.13 Creat ing SystemC Wrapper (cont .)15. 3.13 Creat ing 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;
}
7/31/2019 C15 SystemC Support
31/39
All materials updated on: November 20, 2006
15. 3.14 Complete code for t estw rapper.h15. 3.14 Complete code for t estw rapper.h
{
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__
#ifndef __testwrapper_h__
#define __testwrapper_h__
#include
#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
7/31/2019 C15 SystemC Support
32/39
All materials updated on: November 20, 2006
15. 4.1 C/ C+ + Configurat ion Files15. 4.1 C/ C+ + Configurat ion Files
The C/C++ Configuration files (*.dlm) make SystemC compilationeasy. The testwrapper.dlmwas created by the wizard.
7/31/2019 C15 SystemC Support
33/39
All materials updated on: November 20, 2006
15. 4.2 Edit ing C/ C+ + Configurat ion File15. 4.2 Edit ing C/ C+ + Configurat ion File
Open the testwrapper.dlm file from the Design Brow ser.
Select the Add C/ C+ + l ibrary 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 I nclude Directories list(use button above the list of directories)
Leave all other options at their defaults
7/31/2019 C15 SystemC Support
34/39
All materials updated on: November 20, 2006
15. 4.3 Edit ing C/ C+ + Configurat ion File15. 4.3 Edit ing C/ C+ + Configurat ion File
Modified configuration should look like this:
ClickSave to close the *.dlm file
7/31/2019 C15 SystemC Support
35/39
All materials updated on: November 20, 2006
15. 4.4 Building t he SystemC Library (* .dll)15. 4.4 Building t he SystemC Library (* .dll)
- Right-click the *.dlm file inthe Design Browser
- Select the Build command fromthe local menu
- Active-HDL will launch the gcc compiler.Check the Console for compiler messages.
R ili h l l
7/31/2019 C15 SystemC Support
36/39
All materials updated on: November 20, 2006
15. 4.5 Re-compiling t he t op-level15. 4.5 Re-compiling t he t op-level
- Right-click the previously compiled test_env.bde file andselect Compile from the menu. The simulation top-levelunit will be recompiled and the exclamation mark willchange into a check-mark.
- The SystemC module (instantiated intest_env.bde) is now visible in thedesign library.
The design is now ready for simulation.
15 4 6 Si l i
7/31/2019 C15 SystemC Support
37/39
All materials updated on: November 20, 2006
15. 4.6 Simulat ion15. 4.6 Simulat ion
- Make sure the test_envunit is selected as the simulation top-level.
- Select I nit ialize Simulat ion from the Simulation menu.
- The hierarchy of the design (including
SystemC modules) is shown on theStructure tab in the Design Browser.SystemC modules are shown in orange.
Si l i ( )15 4 7 Si l t i ( t )
7/31/2019 C15 SystemC Support
38/39
All materials updated on: November 20, 2006
15. 4.7 Simulat ion (cont .)15. 4.7 Simulat ion (cont .)
- Click the New Waveform button.
- Drag test_envsignals and testwrappersignals from
the Design Brow ser to the Wavefrom Edit or.
- Run simulation (use Simulat ion | Run menu optionor Alt+ F5 key).
Ports of SystemC modules instantiated in HDL can be observedin the Waveform Edit or.
15 4 8 Si l t i ( t )15 4 8 Si l t i ( t )
7/31/2019 C15 SystemC Support
39/39
All materials updated on: November 20, 2006
15. 4.8 Simulat ion (cont .)15. 4.8 Simulat ion (cont .)
Please note that the simulation stops automatically as the result ofsc_stop() call in the terminate() method in the transactor.