From Wikipedia, the free encyclopedia
Hardware description language API
SystemVerilog DPI (Direct Programming Interface) is an interface which can be used to interface SystemVerilog with foreign languages. These foreign languages can be C, C++, SystemC as well as others. DPIs consist of two layers: a SystemVerilog layer and a foreign language layer. Both the layers are isolated from each other.
Direct Programming Interface (DPI) allows direct inter language function calls between the SystemVerilog and Foreign language. The functions implemented in Foreign language can be called from SystemVerilog and such functions are called Import functions. Similarly, functions implemented in SystemVerilog can be called from Foreign language (C/C++ or System C); such functions are called Export functions. DPIs allow transfer of data between two domains through function arguments and return.
Function import and export[edit]1) Function Import:- A function implemented in Foreign language can be used in SystemVerilog by importing it. A Foreign language function used in SystemVerilog is called Imported function.
Properties of imported function and task[edit]A function whose results solely depends on the value of its input arguments with no side effects is called Pure function.
Properties of pure functions[edit]An Imported task or function which calls "Exported" tasks or functions or accesses SystemVerilog data objects other than its actual arguments is called Context task or function.
Properties of context tasks and functions[edit]1) A Context Imported task or function can access (read or write) any SystemVerilog data object by calling (PLI/VPI) or by calling Export task or function. Therefore, a call to Context task or function is a barrier for SystemVerilog compiler optimization.
Import declaration[edit]import "DPI-C" function int calc_parity (input int a);Export declaration[edit]
export "DPI-C" my_cfunction = function myfunction;Calling Unix functions[edit]
SystemVerilog code can call Unix functions directly by importing them, with no need for a wrapper.
Calling 'C' functions in SystemVerilog[edit]#include <stdio.h> #include <stdlib.h> extern int add(void) { int a = 10, b = 20; a = a + b; printf("Addition Successful and Result = %d\n", a); return a; }SystemVerilog code file[edit]
module tb_dpi; import "DPI-C" function int add(); import "DPI-C" function int sleep(input int secs); int j; initial begin $display("Entering in SystemVerilog Initial Block"); #20 j = add(); $display("Value of J = %d", j); $display("Sleeping for 3 seconds with Unix function"); sleep(3); $display("Exiting from SystemVerilog Initial Block"); #5 $finish; end endmodule
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4