First question is that, Is it the correct way of defining 2D array?
2nd Question.
I want to define my function ‘enable_func()’ in such a way that it gives me the 2D array. I want the following 2D array:
You have to construct a dynamic array either by using new[…] or copy by assignment. You can only new one dimension of a dynamic array at a time. The second dimension would have to be a loop. You cannot assign individual array elements before they are constructed.
X = new[N];
foreach(X[i]) X[i] = new[M];
or
X = '{{ip1_slave,slave}, {A_master,master}, {B_master,master},{master_chain,master}};
Array names are not pointers. By default, function arguments are copied on input. You you either need to make this argument an output, or passed by reference.
Actually from the heirarchy that I defined, I want an array of masters and slaves that I need to enable. Example in the above case, I am passing ip1_slave and B_master to the function. In the function I want an array that contains all the slave and masters that I need to enable. The reason I am using 2D array is because both the master and slave have a different configuration registers. Kindly modify my function definition.
It is going to be very difficult to teach you SystemVerilog in a forum a question at a time. I suggest you search for some books or on-line tutorials first. Once you familiarize yourself with SystemVerilog, then you can start learning OVM.
I want the above array because I want to enable ip1_slave and to enable it I first have to enable A_master and master_chain. Similarly to enable B_master I first have to enable master_chain.
I did the following but it didnt work:
function enable_func(ip_chain array[]);
foreach (array[i])
begin
ip_chain X[];
do
X[i]=tree[ip_chain].master;
while(X[i]=X[i]);
end