• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. Whether DPI - C functions can be used in the environment...

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 66
  • Views 1631
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Whether DPI - C functions can be used in the environment where the top is in C.

Vimala
Vimala over 11 years ago

I have created a simple example for dpi functions. Below is the code:

CODE: C_file.c

#include "stdio.h" 
#include "svdpi.h" 
//int main()
//{
extern void export_func(void); 
void import_func() 
{ 
export_func(); 
} 
//}

CODE: SV_file.sv

module sv_file; 
export "DPI-C" function export_func; 
import "DPI-C" context function void import_func(); 
function void export_func(); 
$display("SV: Hello from SV "); 
endfunction 
initial 
begin 
import_func(); 
end 
endmodule

I am running the code with the command,
irun –sv sv_file.sv c_file.c

The dpi functions are working fine as expected.

But this code is without main() function. When I try running the code with main function, the sv code is not able to find the import_func definition in C.
1. So I wanted to know whether dpi functions can be used in an environment where we have only C testcases instead without sv testcases (ie) C is in the top of the environment and execution starts and ends in C.
2. And, I am not able to run the code when I am trying to use only the export function (ie) calling the C-defined function in SV. Is it possible to use only the export function without import?

Your help will be very useful for me. Thank you.

  • Cancel
  • StephenH
    StephenH over 11 years ago

    Your C code cannot define main(), because there can only be one main() in a C program, and that belongs to ncsim! The simulator main() has to be in control of the simulation, and your DPI-C code can only be a slave to the simulator.

    Whatyou probably need to do is adapt your C tests so that the bus accesses into the RTL do via function calls like write_bus() and read_bus() which map onto Verilog tasks that actually do the pin-wiggling. You C test can't have a main() so you could call it something else like c_test() and DPI-import that into SV, so that SV can initiate the C test via "initial c_test();" os similar...

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • arnabd88
    arnabd88 over 9 years ago

    We have a C++ simulated processor model and attempting to plugin rtl interconnect between the cores and cache interface using dpi.

    However, if the main is controlled by ncsim, it doesn't seems C can reside as the top module.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information