Quantcast
Channel: Cadence Functional Verification Forum
Viewing all articles
Browse latest Browse all 1069

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

$
0
0

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"contextfunctionvoid import_func();functionvoid export_func();
$display("SV: Hello from SV ");endfunctioninitialbegin
import_func();endendmodule

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.


Viewing all articles
Browse latest Browse all 1069

Trending Articles