Basic use of SystemVerilog DPI-C in Riviera-PRO

This application note describes the basics of utilizing SystemVerilog DPI-C to interface with the C language in Riviera-PRO.

What is SystemVerilog DPI-C?

SystemVerilog’s DPI-C allows interfacing with the C programming language. This interfacing capability allows the use of C language functions, including those in existing C libraries, to be used in SystemVerilog testbenches.

Importing and Using C Functions

To use a C function in a SystemVerilog file, it needs to be imported:

import “DPI-C” function <function_type> function_name(arguments);

Once imported, a call to this function has the same syntax and usage as a call to a SystemVerilog function.

Exporting SystemVerilog Functions

To use a SystemVerilog function/task in your C code, it needs to be exported:

export “DPI-C” function function_name;

//function declaration
function void  function_name(arguments);
    //function body
endtask

Necessary Include Files

The "svdpi.h" file (provided with each Riviera-PRO installation: <installation_path>/interfaces/include/svdpi.h) contains constant definitions, structure definitions, and routine declarations used by the SystemVerilog DPI and must be included in the C files.

The Main Flow

Once all desired C or SystemVerilog functions have been appropriately imported or exported, the files needs to be compiled. Riviera-PRO requires explicit switches to be added to the compilation commands for both types of files as shown in Figure 1.

Figure 1: The strict DPI flow for Riviera-PRO

Note: If using the GUI, these switches can be set in the design options windows.

Figure 2: Opening the design options/properties

Figure 3: Enabling DPI strict mode

Figure 4: Setting the -dpi switch for ccomp

Figure 5: Linking the simulation library when using a Windows operating system

Figure 6: Setting the -sv_lib switch and pointing to the DPI library for the asim command

Riviera-PRO contains a basic DPI example design for reference in its installation directory (<installation_path>/examples/interfaces/dpi). For more details regarding the use of SystemVerilog DPI-C with Riviera-PRO, more information can be found in the Riviera-PRO user guide (Help -> Product Help -> Riviera-PRO Interfaces -> SystemVerilog DPI).



Printed version of site: support.aldec.com/en/support/resources/documentation/articles/1900