Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

when use DPI, pass arrays of type byte to C function

Status
Not open for further replies.

jimnan

Newbie level 2
Joined
May 1, 2007
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,298
How to pass pass arrays of type byte to C function in Systemverilog DPI ?

Below are my test code, VCS seem convert char to int.
Why a[1]~ a[3] become 0 ?
They should be 3/5/7 respectively.
(LRM 3.1 spec. said SV could pass datatype byte as argument )

Can anyone try this code in modelsim or ncverilog ?


///// C code

int arr_read( char *a)
{
int i;
for(i=0; i<5; i++) {
printf("in c code , a[%d] =%d\n",i, a); }
}


///// system verilog codeimport "DPI-C" function arr_read(byte a[5]);
module test ();
byte array_src[5] = {2,3,5,7,9};
initial begin : t1_label
$display("array_src[0] is %h", array_src[0]);
$display("array_src[1] is %h", array_src[1]);
$display("array_src[2] is %h", array_src[2]);
arr_read(array_src, array_src2, error);
end : t1_labelendmodule

// output display

> array_src[0] is 02
> array_src[1] is 03
> array_src[2] is 05
> in c code , a[0] =2
> in c code , a[1] =0
> in c code , a[2] =0
> in c code , a[3] =0
> in c code , a[4] =3
 

I couldn't run your code due to various syntax errors and undefined variables. Try this:
Code:
import "DPI-C" function void arr_read(byte a[5]);
module test ();
  byte array_src[5] = '{2,3,5,7,9};
  initial begin : t1_label
    $display("array_src[0] is %h", array_src[0]);
    $display("array_src[1] is %h", array_src[1]);
    $display("array_src[2] is %h", array_src[2]);
    arr_read(array_src);
  end : t1_label
endmodule
Code:
#include <stdio.h>
void arr_read(char *a)
{
  int i;
  for(i=0; i<5; i++)
    printf("in c code , a[%d] =%d\n",i, a[i]);
}
I used MinGW to compile the C into a Windows DLL. Here is ModelSim's output:
Code:
# array_src[0] is 02
# array_src[1] is 03
# array_src[2] is 05
# in c code , a[0] =2
# in c code , a[1] =3
# in c code , a[2] =5
# in c code , a[3] =7
# in c code , a[4] =9
Interesting little experiment! This is the first time I've tried SystemVerilog and DPI.
 

Hi echo47,
Thanks for your testing!
I thnink VCS has problem when pass datatype byte array.
And I'm waiting for their reply.

SV co-work with C is powerful ~
^_^
 

Sure, SV co-work with C/C++ is very powerful...
But presently, in the simulation env, it's very difficult to debug C/C++...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top