uvmbee
1
Hi,
I want to use sub task with extern “C” in C or C++ code.
When I call a task in C++, it works well.
extern "C" void check(); // at C++ code
main(){
check();
}
However, it looks dosen’t work in C code.
How to call sub task check() in Code?
//extern "C" void check();
main(){
check();
}
rag123
2
In reply to uvmbee:
Here is a sample code :
module hello_kitty;
export "DPI-C" task random_data;
import "DPI-C" context task read_from_c();
task read();
read_from_c();
endtask
task random_data(output int rdata,int wdata);
rdata = $urandom_range(0,20);
wdata = $urandom_range(0,10);
$display ("Randomized rdata = %d and wdata = %d",rdata,wdata);
endtask
endmodule :hello_kitty
module test;
hello_kitty h1();
initial repeat(10)
begin
h1.read;
// this works too - no wrapper needed
#500; // read every
end
endmodule
#include "stdio.h"
#include "svdpi.h"
extern int random_data(int*, int*);
int read_from_c(void)
{
int hi;
int hello;
int x;
x = random_data(&hi,&hello);
printf ("rdata = %d, wdata = %d \n",hi,hello);
return 0;
}
uvmbee
3
In reply to rag123:
Thank you rag123,
What I did upon your example was adding include “svdpi.h” in my C code.
But it returns compile error as below.
gcc -w -pipe -m32 -O -I/apps/vcsmx/vcs/S-2021.09/include -c ../test.c
../test.c:4:8: error: expected identifier or '(' before string constant
extern "C" void check();
^
make[1]: *** [test.o] Error 1
rag123
4
In reply to uvmbee:
works for me :) you have to post your code or give the link to the code.