Hi All,
Can we return data from System verilog task?
Does its possible or any work around?
Thanks,
Mehul
Hi All,
Can we return data from System verilog task?
Does its possible or any work around?
Thanks,
Mehul
In reply to mehul.gor:
User-defined SV tasks can have output arguments.
A task may have output arguments whose values are assigned upon returning from the task.
If an input argument is a class reference, you can update the class object by reference at any time during the task call.
In reply to dave_59:
I am using DPI for interface of C and System verilog.
In C code, i am using below function which return data from given address using READ function.
data = READ(address);
READ function require to be blocking as it perform read operation via system verilog driver.
I have defined READ task in system verilog. But how to return data from this READ task?
In reply to mehul.gor:
In Verilog/SystemVerilog, a potentially time consuming routine must be written as a task.
task READ_DPI(input int address, output int data);
#100 data = MEM[address];
endtask
export "DPI-C" task READ_DPI;
If you compile this code generating a DPI header file, it will produce this prototype:
DPI_LINK_DECL int
READ_DPI(
int address,
int* data);
An output argument is passed by reference in C. Note that the int return value of a DPI exported task is used for disables, and can be ignored if not used.
Your code can call this routine as:
#include "dpi.h"
...
READ_DPI(address,&data);
...
If you really need the READ routine to be a function in C, you can put a wrapper around it:
int READ(
int address) {
int data;
READ_DPI(address &data);
return data;
}
In reply to dave_59:
It Works! Thanks Dave.