Hi all,
I’m trying to call c function inside a c dpi file. Compilation flow are doing well but when simulation call function a fatal error occur with:
** Fatal: (vsim-12005) Undefined function ‘globalb()’ introduced from ‘/tmp/***/linux_x86_64_gcc-5.3.0/vsim_auto_compile.so’ is being called. Exiting …
Here my files:
-------------my_sv_unit_dpi.sv --------------------
module my_sv_unit_dpi_inc;
export "DPI-C" task rd_hw;
import "DPI-C" context task read_register();
task rreg;
read_register();
endtask
task rd_hw(input int addr, output int data);
#10;
data = $urandom;
$display("@%10t : Read Done [ADDR = %08h, DATA = %8h]", $time,
addr , data);
//#t = $stime;
endtask : rd_hw
endmodule : my_sv_unit_dpi_inc
module my_sv_unit_dpi (output logic a, input logic clk);
my_sv_unit_dpi_inc prova();
initial repeat(10)
begin
prova.rreg;
prova.read_register; // this works too - no wrapper needed
#500; // read every
end
endmodule
-------------my_dpi.cc --------------------
#include <iostream>
#include "svdpi.h"
#include "my_dpi.h"
#include "../source-c/device.h"
using namespace std;
extern int rd_hw(int, int*);
void init_a( void);
void init_a( void)
{
int ret;
int i, len;
uint8_t a = 0;
uint8_t part = 0;
len = 10;
for(i = 0; i < len; i++)
{
globalb();
cout << "init_a i" << std::hex << i <<endl;
}
}
int read_register(void)
{
int status;
int rddata;
init_a();
status = rd_hw(0x0, &rddata);
cout << "(C++) Data is " << std::hex << rddata << endl;
cout << "Scope is " << svGetNameFromScope(svGetScope()) << endl;
return status;
}
--------------------------------------------------------
------------------device.h-------------------
int globalb();
void globalc();
--------------------------------------------------------
--------------------globalb.c--------------------------
#include "device.h"
#include <stdio.h>
int globalb(void)
{
printf("whe are into globalb body");
globalc();
return 0;
}
--------------------------------------------------------
--------------------globalc.c--------------------------
#include <stdio.h>
#include "device.h"
void globalc(void)
{
printf("whe are into globalc body");
}
compilation flow
gcc -shared -fPIC -lm -Bsymbolic -o mylibc.so globalb.c globalc.c
vlog -64 my_sv_unit.sv
vlog -64 my_sv_unit_dpi.sv my_dpi.cc -dpiheader my_dpi.h
Where I’m wrong here?
Thanks
Regards