Upload
blaise-payne
View
246
Download
2
Tags:
Embed Size (px)
Citation preview
All materials updated on: September 30, 2005
9. Building VHPI Applications9. Building VHPI Applications
The VHPI interface provides a standard-compliant mechanism for connecting C applications to VHDL models simulated in Active-HDL. It allows development of applications such as:
• Code coverage tools• Design traversals• Behavioral C models• Custom debugging environments• C/C++ based testbenches
All materials updated on: September 30, 2005
9.1 VHPI Tools in Active-HDL9.1 VHPI Tools in Active-HDL
All tools required to develop and debug VHPI applications are included in Active-HDL. Active-HDL includes:
• VHPI/PLI Wizard• C/C++ Editor• C/C++ Compiler (gcc)• C/C++ debugger (gdb)• Graphical front-end for gdb
VHPI applications can be compiled with any C/C++ compiler. However, gdb-compatible debug information is required for debugging VHPI applications in Active-HDL environment. (Debugging of C applications is described in course 10.)
All materials updated on: September 30, 2005
This tutorial shows how to create a simple VHPI application. This application will be used in the datapath sample project delivered with Active-HDL. The application traverses the design hierarchy and counts the number of signals.
The tutorial covers:
9.2 Sample VHPI Application9.2 Sample VHPI Application
• Using VHPI/PLI Wizard• Entering C/C++ code in the editor• Configuring C/C++ build environment• Connecting VHPI application to the VHDL
model (the datapath sample)
All materials updated on: September 30, 2005
9.3 Loading VHDL Design9.3 Loading VHDL Design
1. Choose Open Workspace/Design Explorer from the File menu. Then, double-click the datapath workspace icon located in the \Samples\VHDL_Designs folder.
All materials updated on: September 30, 2005
9.4 Compiling the Design9.4 Compiling the Design
2. Compile the design using the Compile All command from the Design menu.
3. Use the list box in the Design Browser to set top_testbench (tb_architecture) as the top-level unit.
All materials updated on: September 30, 2005
9.5 Running the Wizard9.5 Running the Wizard
4. Start the wizard with the VHPI/PLI Wizard command from the Tools menu.
5. Type dump_hierarchy in the VHDL Procedure/Function/ Architecture Name field. Uncheck the Generate VHPI Interface Template option and set the remaining options as shown in the figure on the right.
6. Press Add Item to List, then Generate, and close the window by clicking OK.
All materials updated on: September 30, 2005
9.6 Reviewing Created Files9.6 Reviewing Created Files
7. Review the list of files created by the wizard. The list is printed into the Console window.
# Design: Created file C:\My_Designs\Samples\Datapath\src\VHPI\vhpiuser_aldec.cpp
# Design: Created file C:\My_Designs\Samples\Datapath\src\VHPI\dump_hierarchy_vhpi.h
# Design: Created file C:\My_Designs\Samples\Datapath\src\VHPI\dump_hierarchy_vhpi.cpp
# Design: Created file C:\My_Designs\Samples\Datapath\src\VHPI\dump_hierarchy_vhpi.vhd
The files are also visible in the VHPI folder in the Design Browser.Also a DLM C/C++ configuration file is automatically added for building the application.
All materials updated on: September 30, 2005
9.7 Editing C Code9.7 Editing C Code
8. The dump_hierarchy_vhpi.cpp file contains an empty body of the dump_hierarchy_exec function.
The following slides show complete code for the modified dump_hierarchy_vhpi function and for an auxiliary traverse_hierarchy routine.
Before editing the functions add the following #include directive to the beginning of the dump_hierarchy_vhpi.cpp file:
#include <stdio.h>
All materials updated on: September 30, 2005
9.8 dump_hierarchy_vhpi function9.8 dump_hierarchy_vhpi function
vhpiHandleT rootInstHdl = NULL; // handler to rootInst component
vhpiHandleT iteratorSigHdl = NULL; // iterator for SigDecls
vhpiHandleT Hdl = NULL; // handler
vhpiHandleT archBodyHdl = NULL; // handler to archBody
vhpiHandleT entityDeclHdl = NULL; // handler to entityDecl
int numObjs = 0; // initialize objects counter
vhpi_printf("\nUsing VHPI application as Foreign Architecture to count declared signals...");
//1.
if ( rootInstHdl = vhpi_handle(vhpiRootInst, NULL) ){
//2
// signal declarations
if ( iteratorSigHdl= vhpi_iterator(vhpiSigDecls, rootInstHdl) )
//3.
while ( Hdl = vhpi_scan(iteratorSigHdl) ){
// handler points to object of type vhpiSignalDeclK (signal)
vhpi_printf("found signal: %s ", // signal name
vhpi_get_str(vhpiNameP, Hdl));
numObjs++;
}
// CONTINUED ON NEXT SLIDE
Replace the // put your code here comment in procedure dump_hierarchy_exec in the dump_hierarchy_vhpi.cpp file with following code:
All materials updated on: September 30, 2005
9.8. dump_hierarchy_vhpi (continued)9.8. dump_hierarchy_vhpi (continued)
traverse_hierarchy(rootInstHdl, &numObjs);
// fetching some information about analyzed design:
// name of architecture of top level design
if ( archBodyHdl = vhpi_handle(vhpiDesignUnit, rootInstHdl) ){
// name of entity of top level design
if ( entityDeclHdl = vhpi_handle(vhpiPrimaryUnit, archBodyHdl) ){
vhpi_printf("===============================================");
vhpi_printf("SUMMARY:");
vhpi_printf("Analyzed entire design '%s' contains %d signal(s)",vhpi_get_str(vhpiNameP, entityDeclHdl), numObjs);
}
}
}
vhpi_printf("\nEnd of Your VHPI application.......");
(function defined in the dump_hierarchy_vhpi.cpp file continued)
All materials updated on: September 30, 2005
9.9 traverse_hierarchy function 9.9 traverse_hierarchy function
PLI_VOID traverse_hierarchy(vhpiHandleT ScopeHdl, int *numObjs){
vhpiHandleT iteratorSigHdl = NULL; // iterator for SigDecls
vhpiHandleT iteratorRegHdl = NULL; // iterator for InternalRegions
vhpiHandleT Hdl = NULL; // handler
vhpiHandleT SigHdl = NULL; // handler
if (ScopeHdl==NULL) return;
if ( iteratorRegHdl = vhpi_iterator(vhpiInternalRegions, ScopeHdl) )
//1.
while ( Hdl = vhpi_scan(iteratorRegHdl) ){
//2.
vhpi_printf("%s [%d]: %s ",vhpi_get_str(vhpiKindStrP, Hdl),
vhpi_get(vhpiKindP, Hdl),
vhpi_get_str(vhpiNameP, Hdl) );
// signal declarations
if (iteratorSigHdl= vhpi_iterator(vhpiSigDecls, Hdl))
//3.
while ( SigHdl = vhpi_scan(iteratorSigHdl) ){
// handler points to object of type vhpiSignalDeclK (signal)
vhpi_printf("found signal: %s ", //signal name
vhpi_get_str(vhpiNameP, SigHdl));
(*numObjs)++;
}
traverse_hierarchy(Hdl, numObjs);
}
}
Above the dump_hierarchy_exec function type the following code:
All materials updated on: September 30, 2005
9.10 Creating the Foreign Architecture
9.10 Creating the Foreign Architecture
9. VHPI applications can be registered by using foreign subprograms or foreign architectures. This tutorial shows how to register the VHPI application by using the foreign architecture.Edit the dump_hierarchy_vhpi.vhd to include the code shown below:
After editing, check if the new code compiles correctly.
entity dump_hierarchy is
end entity dump_hierarchy;
architecture dump_hierarchy of dump_hierarchy is
attribute foreign of dump_hierarchy : architecture is
"VHPI $dsn\src\VHPI\datapath.dll;dump_hierarchy_model";
begin
end architecture dump_hierarchy;
All materials updated on: September 30, 2005
9.11 Instantiating the Foreign Architecture
9.11 Instantiating the Foreign Architecture
10. The dump_hierarchy architecture created on the previous slide has to be instantiated in the top-level unit. The neighboring pictures show component declaration and instantiation in the testbench.vhd file.
All materials updated on: September 30, 2005
9.12 C/C++ Configuration9.12 C/C++ Configuration
11.Double click on the C/C++ Configuration file $DSN/VHPI/datapath.dlm. The C/C++ configuration dialog allows to specify all options required to build the VHPI application. Verify that the settings are the same as shown in the picture below.
All materials updated on: September 30, 2005
9.13 C/C++ Compilation9.13 C/C++ Compilation
12. Click datapath.dlm with the right mouse button and choose Build from the context menu. The VHPI library (datapath.dll) will be built.
All materials updated on: September 30, 2005
9.14 Running the Simulation9.14 Running the Simulation
13. Recompile HDL files. (Two files were edited during previous tutorial steps.)
14. Choose Initialize Simulation from the Simulation menu. The VHPI application will be registered through the VHDL foreign architecture. This is reported to the Console window.# KERNEL: PLI/VHPI kernel's engine initialization done.
# VHPI: Loading library 'C:\My_Designs\Samples\Datapath\src\VHPI\datapath.dll'
# : Using VHPI application as Foreign Architecture to count declared signals...
# VHPI: found signal: CLK
# VHPI: found signal: RESET
# VHPI: found signal: START
# VHPI: found signal: CODE
# VHPI: found signal: DATA_IN
...
When the scan is complete, the design is ready for simulation.
The VHPI application starts analyzing the design and prints collected information to the Console window.