Hi TVAR,
I’ve managed to get this working using a virtual interface wrapper class. I normally derive such a wrapper from ovm_object but I had to use an ovm_component base class here instead in order to get the top-level wrapper objects into the configuration database. I will go through the main points below.
Firstly, here is the virtual interface wrapper class. Note that the virtual interface reference is passed as a constructor argument.
class if_wrapper extends ovm_component;
virtual chip_if if1;
function new(string name,virtual chip_if if_,ovm_component parent = null);
super.new(name,parent);
if1 = if_;
endfunction : new
endclass : if_wrapper
I have used an instance of this wrapper in the driver and monitor classes.
class dut_driver extends ovm_driver
ovm_get_port #(basic_transaction) tx_in_port;
virtual chip_if if1;
if_wrapper if_wr;
...
virtual function void connect();
if1 = if_wr.if1;
endfunction : connect
task run();
basic_transaction tx;
forever begin
#10;
tx_in_port.get(tx);
addr = tx.addr;
data = tx.data;
ovm_report_message("DRV",tx.convert2string());
if1.driver.addr = addr;
if1.driver.data = data;
end
endtask: run
`ovm_component_utils_begin(dut_driver)
`ovm_field_object(if_wr,OVM_ALL_ON)
`ovm_component_utils_end
endclass: dut_driver
The monitor code is similar except it is connected to the DUT through a different modport. Note that the field automation macro for the interface wrapper is required to configure it.
In the top level module, I create a DUT, interface and wrapper object on each iteration of the generate loop.
module test;
genvar i;
generate
for(i=0; i < `NUM; i++)
begin: c_gen
chip_if dut_if(.clk);
chip dut ( .dut_if, .clk );
if_wrapper if_wr = new($psprintf("if_wrapper_%0d",i),dut_if);
end
endgenerate
...
endmodule: test
The test class is also declared in the top level module. After creating each environment, it searches for the relevant wrapper using find_component which it then passes to set_config_object to fix the reference in the driver and monitor.
class test1 extends ovm_test;
`ovm_component_utils(test1)
verif_env env[`NUM];
if_wrapper if_wr;
...
virtual function void build();
super.build();
for (int i=0; i < `NUM; i++) begin
$cast(env[i],ovm_factory::create_component("verif_env","",$psprintf("env%0d",i),this) );
$cast(if_wr,find_component($psprintf("if_wrapper_%0d",i)));
set_config_object($psprintf("env%0d.*",i),"if_wr",if_wr,0);
end
endfunction : build
endclass: test1
This compiles and runs with no errors or warnings on QuestaSim 6.3f and Incisive 6.20-s005.
Hope that gives you some ideas to solve your problems.
Regards,
Dave