FONT SIZE : AAA
With SystemVerilog, you can write a part of design in C or C++ and use it from SystemVerilog. SystemVerilog can import C functions via import command. Once a C function is imported, it can be called as a regular SystemVerilog function or task (depending on the import command syntax). Similarly SystemVerilog function or task can be exported to C side. These exported SystemVerilog functions (or tasks) can be called from C functions. Exported SystemVerilog tasks can be used to mimic #delay or @wait from C functions.
For simulating SystemVerilog with C code, it is important to make sure that they are compatible. xelab has an option –dpiheader . This generates a C header fifi le for the imported and exported functions. The C function defifi nition prototype must match with this generated header for successful linking of functions.
Use the Tcl command xsc to compile the C fifi les and then link with xelab . Only simple scalar types are permitted as function return for imported or exported DPI functions. The permitted data types that can be passed between C and SystemVerilog are mentioned in Table 11.1 .
Let us take an example to elaborate. A SystemVerilog fifi le hdl.sv (with the design top name TESTBENCH ) calls a C function defifi ned in fifi le helper.c . The prototype for the function as defifi ned in hdl.sv is

To generate the equivalent C prototype for function, you need to elaborate the design using xelab with the additional command line option –dpiheader . This will generate a header fifi le with the name dpi.h . For this case, the dpi.h will contain the C prototype of the equivalent function.

SV_PACKED_DATA_NELEMS() is defifi ned in svdpi.h which is included. SV_ PACKED_DATA_NELEMS rounds the bits into chunks of 32 bits needed to hold. So number from 1 to 32 will become 1 , 33 – 64 will become 2 , and so on. The C code needs to have the same prototype for function . The C code can be compiled into a dynamic library dpi.so with the command xsc as:
xsc helper.c
The next step is to create the simulation kernel with xelab command where the name of the dpi library is specififi ed.
xelab TESTBENCH –snapshot SIM1 –sv_lib dpi
Once the kernel is created, the simulation can be run using xsim command. This will open up a Tcl shell that takes all the simulation commands.
Manufacturer:Xilinx
Product Categories: Connecteurs
Lifecycle:Obsolete -
RoHS: No RoHS
Manufacturer:Xilinx
Product Categories:
Lifecycle:Obsolete -
RoHS: No RoHS
Manufacturer:Xilinx
Product Categories: Interface IC
Lifecycle:Obsolete -
RoHS: -
Manufacturer:Xilinx
Product Categories: FPGAs (Field Programmable Gate Array)
Lifecycle:Active Active
RoHS: No RoHS
Manufacturer:Xilinx
Product Categories:
Lifecycle:Any -
RoHS:
Support