Main Content

Use Generated DPI Functions in SystemVerilog

To use the generated DPI component in a SystemVerilog environment, first import the generated functions with “DPI” declarations within your SystemVerilog module. Then, call and schedule the generated functions. When you compile the SystemVerilog code that contains the imported generated functions, use a DPI-aware SystemVerilog compiler and specify the component file names.

The following example demonstrates adding the generated DPI component for the DPI_blk block to a SystemVerilog module.

  1. Import the generated functions:

    import "DPI" function void DPI_blk1_initialize();
    import "DPI" function void DPI_blk1_ouptut(output real blk1_Y_Out1);
    import "DPI" function void DPI_blk1_update(input real blk1_U_On1);
  2. Call the Initialize function.

    DPI_blk1_initialize();
  3. Schedule the output and update function calls:

    DPI_blk1_output( blk1_Y_Out1);
    DPI_blk1_update( blk1_U_In1);

Example

import "DPI" function void DPI_blk1_initialize();
import "DPI" function void DPI_blk1_ouptut(output real blk1_Y_Out1);
import "DPI" function void DPI_blk1_update(input real blk1_U_On1);

module test_twoblock_tb;

		initial begin
			DPI_blk1_initialize();
		end

		always@(posedge clk) begin
			#1
			DPI_blk1_output(blk1_Y_Out1);
			DPI_blk1_update(blk1_U_In1);
		end

		always@(posedge clk)
			begin
				blk1_U_In1 = blk1_U_In1 + 1.0;
			end