SystemVerilog DPI (Direct Programming Interface) is a feature that allows users to interface between SystemVerilog and foreign programming languages such as C, C++, and SystemC.

DPI enables users to integrate their SystemVerilog designs with external components written in other languages, creating a more powerful and flexible design environment. It also provides an easy and efficient way to connect existing code, usually written in C/C++ without the knowledge and the overhead of PLI/VPI.

Import Declarations

The methods implemented in foreign languages can be called in SystemVerilog and needs to be declared first using import declarations. Imported subroutines can have zero or more input, output or inout arguments and can return a void or some result.

import "DPI-C" function void init(); 			
import "DPI-C" function int sum(int a, b); 		

Export Declarations

Methods implemented in SystemVerilog can be called in other foreign languages and need to be specified in an export declaration.

export "DPI-C" function int randomize(int range_a, range_b);


module tb_top;
	// Import the function called "system_init" implemented in C code
	import "DPI-C" function void system_init();

	initial begin
		$display ("[%0t] Call C method", $time);

#include "stdio.h"
#include "stdlib.h"
extern "C" void system_init() {
	printf("Start system initialization ...\n");