DexterH
DexterH

Reputation: 5

get virtual interface once in package

I try to write a package which include some common tasks and functions for test environment use. For example,

package test_misc_pkg;
`include "uvm_macros.svh"
import uvm_pkg::*;

task wait_rest();
  virtual test_if test_vif;
  if (!uvm_config_db #(virtual test_if)::get(null, "uvm_test_top.env", "test_vif", test_vif))
    `uvm_fatal("NOVIF", "virtual interface should be set")

  @(posedge test_vif.clk);
  //do something...
endtask

endpackage : test_misc_pkg

Then, test env can just call wait_rest() after import test_misc_pkg.

But, if there are other task use same test_vif, I still need to get db in the beginning of every tasks. My question is, can we just get uvm_config_db once in the package, let all tasks can use test_vif directly?

Or, any better way to do this?

Thanks.

Upvotes: 0

Views: 468

Answers (2)

dave_59
dave_59

Reputation: 42673

If you are trying to reduce the overhead of calling uvm_config_db::get(), you could test to see it is null, and then do the get.

task wait_rest();
  virtual test_if test_vif; // this is a static variable
  if (test_vif == null) begin
     if (!uvm_config_db #(virtual test_if)::get(null, "uvm_test_top.env", "test_vif", test_vif))
    `uvm_fatal("NOVIF", "virtual interface should be set")
end
  @(posedge test_vif.clk);
  //do something...
endtask

Upvotes: 0

Matthew
Matthew

Reputation: 13967

You could make you virtual interface a global variable:

package test_misc_pkg;
  `include "uvm_macros.svh"
  import uvm_pkg::*;

  virtual test_if test_vif;

  function void set_vif();
    if (!uvm_config_db #(virtual test_if)::get(null, "uvm_test_top.env", "test_vif", test_vif))
      `uvm_fatal("NOVIF", "virtual interface should be set")
  endfunction

  task wait_rest();
    @(posedge test_vif.clk);
    //do something...
  endtask

endpackage : test_misc_pkg

and the write a function (eg set_vif()) to give the global virtual interface a value. You could then call this function in the connect_phase, for example. It all seems a little unconventional, though.

Upvotes: 2

Related Questions