I want to Write the address of a variable (bit/logic/reg) to some other hardware registers as pointers. How to know the address of that variable?
For example,
I have a variable
bit [31:0] A ;
with new() function it was initialized.
I want to know the starting address of that array A. Is it possible in SV? In "C" language, We have "&" operator. So Can we Use DPI with C? Can anyone please explain with some example?
I think its better if you can give some info on what you wanted to do with this. As far as i know SV cannot give you the address of a variable.
Using class handle you can refer the same data with two or multiple handle.
class A;
int i;
endclass
A a1,a2;
initial begin
a1 = new();
a2 = a1; // if you update one then that value will be reflected in other
a2.i = 10;
$display("Data value in a1: %d, a2: %d",a1.i,a2.i);
end
I think you are confusing many different concepts. SystemVerilog is a Hardware Description Language (HDL). When you declare an array of hardware registers:
bit [31:0] A ;
The hardware address of the first register is 0, the second is 1, etc. When you compile your HDL to run a simulation, you have no knowledge of how the simulator implemented those registers on the host system running the simulation and where in the actually memory they are located. Even for the testbench features of the language, SystemVerilog does not have any pointer like C/C++; it has handles and references which do not let you manipulate the “address” of a variable.
When you start talking about the DPI, that becomes a slightly different story. The C language requires pointers to address arrays. So the simulator either has to provide the actual address, or provide access routines to get to the actual register.
So with these clarifications, you need to provide more explanation of what you are looking to achieve.
Thanks for the quick reply. I am currently working on HOST CONTROLLER INTERFACE for USB-3.0. In that Project I have a requirement like this:
I have to construct TRANSFER RINGS. Basically a Ring is a circular queue data structure. Ring Size is not fixed. So for that I am using variable like this:
bit [31:0] RING [$];
And the problem is, I should write the base address/ starting address of the RING variable in another Register DEQUEUE POINTER field. The Register was implemented using UVM Register Model. How can we address this problem?
Hello sir,
Thanks for the quick reply. I am currently working on HOST CONTROLLER INTERFACE for USB-3.0. In that Project I have a requirement like this:
I have to construct TRANSFER RING, whose size is not fixed. Basically a Ring is a circular queue data structure. So for that I am using variable like this:
bit [31:0] RING [$];
The problem is, I should write the base address/ starting address of the RING variable in another Register DEQUEUE POINTER field to tell the Hardware that Transfer Ring was allocated & initialized in that base address. And all Registers were implemented using UVM Register Model. How can we address this problem?
As far as i know there is no way to get address of a variable in sv.
But if you really need this…you can create a variable in c file and return the address. In SV file with DPI_C and chandle daata type you can get the adress of that variable in sv.