Creating an array of driver

Hi

I want to create an array of driver. The following are the codes. vsim shows Fatal error while running the simulation: Fatal: (SIGSEGV) Bad handle or reference. The Fatal error is pointing to the code with bold character.

class efm_env extends uvm_env;

   .....

   abc_drv abc_drv_ch[16];

   .....
   function new(string name="", uvm_component parent=null);
      super.new(name, parent);
   endfunction

   function void build_phase(uvm_phase phase);
      super.build_phase(phase);

      for (int i=0; i<16; i++) begin
         abc_drv_ch[i].cfg(i);
         abc_drv_ch[i] = abc_drv::type_id::create($sformatf("abc_drv_ch_%2d", i), this);
      end

   endfunction
   .....
endclass
class abc_drv extends uvm_component;
   .....
   bit [3:0] chid;
   virtual abc_if v_abc_if;

   function new (string name, uvm_component parent);
      super.new(name, parent);
   endfunction

   function void build_phase(uvm_phase phase);
      super.build_phase(phase);
      if (!uvm_config_db #(virtual abc_if )::get(
             this, "", $sformatf("drv_ch_%2d", chid), v_abc_if))
      `uvm_error("CONFIGURATION", $sformatf("Could not get virtual interface v_abc_if[%2d]", chid));
   endfunction

   function void cfg (bit [3:0] ch=0);
     **chid = ch;**  <---Fatal: (SIGSEGV) Bad handle or reference
   endfunction
   .....
endclass

Thank you for your help.
John

The problem is with this code…

for (int i=0; i<16; i++) begin
abc_drv_ch[i].cfg(i);
abc_drv_ch[i] = abc_drv::type_id::create($sformatf(“abc_drv_ch_%2d”, i), this);
end

You are trying to access the driver method cfg before creating the object of the driver. First create the object of the driver and then access the method.
The below code should work…

for (int i=0; i<16; i++) begin
abc_drv_ch[i] = abc_drv::type_id::create($sformatf(“abc_drv_ch_%2d”, i), this);
abc_drv_ch[i].cfg(i);
end

In reply to malathi@aceic.com:

But the following code is in the build phase, which will use the value of chid[3:0] to retrieve the right interface.

function void build_phase(uvm_phase phase);
      super.build_phase(phase);
      if (!uvm_config_db #(virtual abc_if )::get(
             this, "", $sformatf("drv_ch_%2d", **chid**), v_abc_if))
      `uvm_error("CONFIGURATION", $sformatf("Could not get virtual interface v_abc_if[%2d]", chid));
   endfunction

If I put

abc_drv_ch[i].cfg(i);

after

abc_drv_ch[i] = abc_drv::type_id::create($sformatf("abc_drv_ch_%2d", i), this);

, will it get the right interface in above code in build phase?

Thanks.
John

Well this will only fix the run time error problem but will not fix the design problem you are mentioning. One way to fix this would be to set the variable(chid) in config database(in efm_env) before creating the driver object and get this variable from the config database in the driver before getting the virtual interface. It is recommended to create a configuration object as described in the cookbook.