I am trying to use a vpi function in iverilog that will return a value to the verilog test bench after it is called. It compiles ok but returns the following when I run
Error: $flash_dat() is a system task, it cannot be called as a function.
I have put the relevant portions of the code below. I would appreciate it if I can either get an example including the compile and run process of using a vpi function that returns a value in iverilog (I did search in google for but did not get any example for iverilog) or get a pointer to the mistake I made in this code. Thanks in advance for your time.
Thanks, Vinay
Code: verilog
always @(flash_adr) #110 flash_do <= $flash_dat(flash_adr);
.sft file
$flash_dat vpiSysFuncInt
flash_dat.c
void flash_dat_register()
{
s_vpi_systf_data tf_data;
tf_data.type = vpiSysTask;
tf_data.tfname = "$flash_dat";
tf_data.calltf = flash_dat_calltf;
tf_data.compiletf = flash_dat_compiletf;
tf_data.sizetf = 0;
tf_data.user_data = 0;
vpi_register_systf(&tf_data);
}
void (*vlog_startup_routines[])() = {
flash_dat_register,
0
};
static unsigned int flash_dat_calltf()
{
unsigned int addr= tf_getp(1);
tf_putp (0,((flash_array[addr+1]<<16)|flash_array[addr]));
return ((flash_array[addr+1]<<16)|flash_array[addr]);
}
Compile:
SOURCES=tb_norflash16.v flash_dat.sft $(wildcard ../rtl/*.v)
all: tb_norflash16 flash_dat.vpi
isim:
vvp -M. -mflash_dat tb_norflash16
tb_norflash16: $(SOURCES)
iverilog -o tb_norflash16 $(SOURCES)
flash_dat.vpi: flash_dat.c flash_dat.sft
iverilog-vpi $^
The answer was kind of right in front of my eyes I need to change
tf_data.type = vpiSysTask;
to
tf_data.type = vpiSysFunc;
Thanks for the help