SystemVerilog DPI Example

Sep-30-2006

   

   

  Simple DPI Example
   

SystemVerilog Code

   

1 // Author : Vivek Prasad
2 // Date : 18 Sep 2006
3 module ptr_c_sv();
4 int res;
5
6 import "DPI" context passArray = function int pA();
7 export "DPI" dV = function disVal;
8
9 function int disVal(input int xyz);
10 $display( "Array Value: %0d\n" ,xyz);
11 return -1;
12 endfunction
13
14 initial begin
15   #5 res = pA();
16   $display( "Returned: %0d\n" ,res);
17   $display( "Array Passing Over.\n" );
18 end
19
20 endmodule
You could download file sv_examples here
   

C Code

   

1 #include <stdio.h>
2 extern int dV(int r);
3
4 int passArray(){
5   int v[5];
6   int sd;
7   int d;
8   for(d=0;d<5;d++) {
9     v[d] = d*3;
10     sd = dV(v[d]);
11   }
12   return(sd);
13 }
You could download file sv_examples here
   

Simulator Output

   

 Array Value: 0
 
 Array Value: 3
 
 Array Value: 6
 
 Array Value: 9
 
 Array Value: 12
 
 Returned: -1
 
 Array Passing Over.
   

   

   

   

  

Copyright © 1998-2006

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at: deepak@asic-world.com