Constructor/argument

hi, a small query
while writing each test bench components
a user defines a function (for example
function new( mailbox gen2drv,virtual intf vif);
this.gen2drv=gen2drv;
this.vif=vif;
endfunction
what is the need of writing this and why we put mailbox ,virtual interface etc. in argument?

The generator & driver should access the same mailbox so that driver can get the data that is generated by the generator. In order to make them access the same mailbox, the mailbox object will be created in the environment class & it is passed to the driver & generator through the constructor of the driver & generator in which we will assign the mailbox passed from the environmet to the local mailbox handles declared in generator & driver.

Similarly, the virtual interface in the driver must point to the static interface in the top module. So while creating the test in top module the static interface is passed to the test constructor & assign the static interface to the virtual interface in the test.

Now form test we pass the virtual interface to environment & then from environment it will be passed to the driver constructor.

The code is provided below for reference


class generator;
mailbox #(trans)gen2drv;// local mailbox
...
function new(mailbox #(trans)gen2drv);
this.gen2drv = gen2drv;// assigning the mailbox which is created in environment-class to the local mailbox
endfunction

endclass

class driver;

mailbox #(trans)gen2drv;// local mailbox
virtual ahb_if.DRV ahb_wr_if;//local virtual interfcae

function new(virtual ahb_if.DRV ahb_wr_if,  mailbox #(trans)gen2drv);
this.ahb_wr_if = ahb_wr_if;//assigning the virtual interface passed from env to the local virtual interface
this.gen2drv = gen2drv;// assigning the mailbox which is created in environment class to the local mailbox
endfunction
....
endclass

class environment;
mailbox #(trans)gen2drv = new();//creating mailbox object
virtual ahb_if.DRV ahb_wr_if;// local virtual interface 

driver drv;
generator gen;

task build;
gen = new(gen2rd);// creating generator instance & passing the mailbox
drv = new(ahb_wr_if,gen2rv);// creating driver instance and passing virtual interface & mailbox
endtask

function new(virtual ahb_if.DRV ahb_wr_if);
this.ahb_wr_if = ahb_wr_if;// assigning virtual interface passed from test to the local virtual interface
endfucntion
...

endclass

class test;

virtual ahb_if.DRV ahb_wr_if;//local virtual interface
environment env;

function new(virtual ahb_if.DRV ahb_wr_if);
this.ahb_wr_if = ahb_wr_if;// assigning the interface passed form top module to the local virtual interface
env = new(ahb_wr_if);// creating the environment object and passing the virtual interface

endfunction
..
endclass

module top();

bit clk;
test t;
ahb_if intf(clk);//static interface instance

initial begin 

t = new(intf);//creating the test object and passing static interface
...
end


In reply to shanthi:

Thank you shanthi
this is very helpful.