virtual task cfg1(bit[47:0] dmac=0);
my_transaction tr; //call serial function /task block1
start_item(tr);
tr = new("tr");
assert(tr.randomize());
tr.dmac= dmac; //assign one field to specific value
finish_item(tr); //call serial function /task block2
endtask
virtual task cfg2(bit[47:0] dmac=0,
bit[15:0] ether_type=0
);
my_transaction tr; //call serial function /task block1
start_item(tr);
tr = new("tr");
assert(tr.randomize());
tr.dmac= dmac;
tr.ether_type= ether_type; //this one can assign 2 field to specific value
finish_item(tr); //call serial function /task block2
endtask
and I read something of design pattern.
do not copy your code.
the two task is the same except task cfg2 add another parameter assign
(tr.ether_type= ether_type;)
or it is the same for the 2 parts call serial function /task block1 and
call serial function /task block2
take the some part to function
if there is some bug in f1 , we only have to modify the code in one place(f1), not everywhere
function f1();
my_transaction tr; //call serial function /task block1
start_item(tr);
tr = new("tr");
assert(tr.randomize());
endfunction
function f2();
finish_item(tr);
endfunction
virtual task cfg1(bit[47:0] dmac=0);
f1();
tr.dmac= dmac; //assign one field to specific value
f2();
endtask
virtual task cfg2(bit[47:0] dmac=0,
bit[15:0] ether_type=0
);
f1();
tr.dmac= dmac;
tr.ether_type= ether_type; //this one can assign 2 field to specific value
f2();
endtask
this is a better way , but i do not know if there is some other solution