In reply to jishan_bukhari:
As replied by Mr.cgales it’s not recommended to parametrize the class to generate the no.of transactions. In case even if it is parametrized, to call the random method you need not pass the transaction class handle as an argument to randomize the object which is passed as an argument. Instead of it, inside the random method you can use this keyword to refer to the object to be randomized. This will work even the parameter is overridden with different values
module test;
class axi_transaction;
typedef enum {WRITE=0, READ=1} rw_e;
rand rw_e re;
rand bit [31:0] addr, data;
endclass:axi_transaction
//derived class as asked in question
class axi_wr_rd_transaction #(int REPEAT_COUNT=50) extends axi_transaction;
//variable declared to control randomization of rw signal
bit rw_temp;
//variable to monitor loop count for easiness to debug in log file
static int count;
//constraint declaration, will assign value to rw opposite according to rw_temp
constraint limit{if(rw_temp==1) rw==0; else rw==1;}
//pre randomize method to control randomization of addr and data variables according to
rw_temp variable
function void pre_randomize();
if(rw_temp==0)
begin
addr.rand_mode(1);
data.rand_mode(1);
end
else
begin
addr.rand_mode(0);
data.rand_mode(0);
end
$write("Sr.no.=%0d \t rw=%s \t",++count,rw.name);
endfunction:pre_randomize
//post randomization mathod , will assign rw value to rw_temp variable and display the addr and data.
function void post_randomize();
rw_temp=rw;
$display(" addr=%0d \t data=%0d",addr,data);
//rw.rand_mode(1);
endfunction:post_randomize
//method to generate REPEAT_COUNT number of randomized transaction
function void random();
begin
repeat(REPEAT_COUNT)
void'(this.randomize());// this refers to the handle with which the method is called, here it is axi_trans
end
endfunction:random
endclass:axi_wr_rd_transaction
//module declaration
module ei_sv_crv_assign_3_ex_2;
//class instance and handle creation
axi_wr_rd_transaction #(10) axi_tran=new();
initial
begin
$display("*************************** SIMULATION STARTED ************************");
void'(axi_tran.random());
$display("*************************** SIMULATION ENDED ************************");
end
endmodule
Regards,
Shanthi