RegisterLogin  
Update Profile
   
You are here: Forum  
Minimize 
SVUG Community Forum
Subject: SystemVerilog DPI
Prev Next
You are not authorized to post a reply.

Author Messages
AMALUser is Offline

Posts:24

10/15/2008 1:59 PM  
The return values from a SyetemVerilog DPI function cannot be a struct or complex type.  Only simple types are supported.  My question is how does one pass structs back to SystemVerilog from C/C++?

Should I instead of returning the struct, use output arguments? 

Another question is regarding typedefs and structs that one defines in SystemVerilog.  I have a number of functions that need a struct as arguments.  If I define them in SystemVerilog, they will be placed in the .h file automatically (by modelsim) and then they conflict with the already defined structs in the C domain.

What is the best method to do this?  Should I generate the header file once and manually modify it?

-- Amal

DAVEUser is Offline

Posts:56

10/15/2008 6:55 PM  
Yes, use an output argument for imported DPI-functions.

You do not need to use the generated header file from Modelsim in your C/C++ code, but I suggest that you figure out a way to use it without modification as it provides a level of memory reference safety.

Dave
ANSHUMANUser is Offline

Posts:3

10/16/2008 12:10 PM  
Replying to your second question, I think you can use packages to restrict the scope of your structures, and then they wont be visible outside the scope.

Anshuman
AMALUser is Offline

Posts:24

10/16/2008 1:49 PM  
My problem is not the SystemVerilog scope, but C/C+ scope.  The structure is defined in a C/C++ header (.h) file and I need to redefine it in SystemVerilog to be able to pass it to/from the function.  But if I define it in SystemVerilog, it will be automatically be placed in the dpiheader.h file.  And that conflicts with the previously defined structure in .h file.

-- Amal
HOLGERUser is Offline

Posts:1

09/09/2009 7:23 AM  
Hi Amal,

basically you need to use a pointer to pass more "complex" data types e.g. strings and structs. Furthermore, the struct can be redefined in SystemVerilog with a different name in order to avoid conflicts.

Example:

--- C code ---
typedef struct {
double a;
double b;
} results_t;

void myFunction (const char *file, results_t* results) {

...

}



--- SV code ---
package my_pkg;

// Redefine struct in SV with different name //
typedef struct {
real a;
real b;
} results;

import "DPI-C" function void myFunction (input string file, output results my_results);

function dpi_myFunction(input string file, output results my_results);
begin
myFunction(file, my_results);
end
endfunction

endpackage

bernardUser is Offline

Posts:1

10/09/2009 4:18 AM  
I have a related problem in a SceMi 2.0 transactor.  The transactor uses synthesizable Verilog and needs assignments like:


register_d = AXI32_SlaveTransactor_SetResponse( register_q );


where the function is defined as:


import "DPI-C" context function bit[AXI32_ArgT_width-1:0] AXI32_SlaveTransactor_SetResponse(input bit[APB3_32ArgT_width-1:0] TArg);


which supposes the signature in the C/C++ domain is something like:


extern "C" svBitVecVal* AXI32_SlaveTransactor_SetResponse(const svBitVecVal *MsgVector);


I'm hitting a problem with the allocation of the storage for the return value.  I don't have the flexibility to add a second argument, but if I assign space inside the function it never gets deleted and the application leaks memory.  If I return a pointer to automatic storage inside the function it goes out of scope on return.

Is there a DPI guru out there who knows how this should have worked?

Thanks in advance,

Bernard
AnkitUser is Offline

Posts:1

11/26/2009 12:29 AM  
Hi Bernard,
                You can declare a global pointer and allocate its memory dynamically, may be invoking a dpi call from hdl side, in the end
when you are done with the memory, u may call another dpi , to destroy this dynamically created vector.


You are not authorized to post a reply.



ActiveForums 3.7
  

 Copyright 2008 by SystemVerilog User Group Contact Us    Privacy Statement