Home System Verilog Constructs DPI
Main Menu
Home
System Verilog
    - Constructs
        -- Introduction
        -- Data Types
        -- Type Casting
        -- SV Arrays
        -- Assoc Arrays
        -- Dynamic Array
        -- Queues
        -- Operators
        -- Procedural statements
        -- Classes
        -- OOP Concepts
        -- Inter process communication
        -- Randomization
        -- Interface
        -- Clocking block
        -- Conststraits
        -- Coverage
        -- DPI
        -- Regular expression
        -- Files
    - SV Classes
    - Functional Coverage SV
    - Examples
    - Tools
    - Links
    - Books
    - Interview Questions SV
Verilog
Methodologies
Open Vera
Digital Concepts
Verification Basics
Protocols
Scripting
Articles
Videos
Interview Questions
Computer Architechture
C and C++
Blog/Article
AsicGuru Blog
Tags Cloud
Ads
Usefull Sites
Know Your IP/Location
Local Information India
Buy Car/Inverter Batteries
Real Estate India
Sports Accessories India
DPI
Share This Articale:

What is System Verilog DPI (Direct Programming Interface)

Direct programming interface or DPI is a interface between the System Verilog and the C language. It allows you to call the sytem verilog functions in C language and Vice Versa

why :

1. you can reuse your existing c code with system verilog

Sytem Verilog :


module hello();
import "DPI-C" function void print_hello();

initial
begin
print_hello();
end

endmodule

C :

===

void print_hello() {
printf("Hello World From C \n");
}

How to run :


    Step 1. Compile your C code
gcc -shared -o hello.so hello.c
Step 2. Compile your SV code
vlog -sv hello.sv
Step 3. link and load
vsim -c hello -sv_lib hello
Step 4. Run
VSIM> run -all

output :
VSIM 1> run -all
# Hello World From C
# ** Note: $finish : hello.sv(7)
# Time: 0 ns Iteration: 0 Instance: /hello

GCC option :

-shared

Produce a shared object which can then be linked with other objects to form an executable.

Explanation :

In the above example we are calling a C funtion print_hello() in system

verilog code. Following are the points to note :

  • we need to import the C function in system verilog with statement 'import "DPI-C"'
  • we should have actual funtion implementiaon in C file
  • Call the C funtion in your system verilog code
  • remember to link library at loading time
  • import declaration can occur anywhere where a SystemVerilog task or function definition is allowed

NOTE : C function should not comsume time like the system verilog functions

Imported Functions :

  • Functions implemented in foreign language can be called in system verilog, such functions are called Imported functions

Exported Functions :

  • System verilog functions that are called from foeign language should appear in exported function declerations

 

This Articles is written/submitted by puneet (Puneet Aggarwal). You can also contribute to Asicguru.com. Click here to start


Prev << Coverage

Next >> Regular expression

 
Login/Register
Register
Sign In
Login with :-
gmail-yahoo-twitter-facebook
| | |  
  •  
  • Bookmark
    ADS