Hi,
I would like to pass a parameter to a covergroup but I am not able to do it as below.
Please guide me how I can achieve this.
Thank you very much.
parameter N = 17;
typedef struct packed {
bit [4:0] celln;
bit [1:0] dly;
bit [1:0] st;
} cell_struct;
class cell_class #(parameter N = 17);
randc cell_struct cell_randc;
constraint c { cell_randc.celln < N; cell_randc.st < 3; }
endclass
cell_class #(N) cell_inst = new();
covergroup cg #(parameter N = 17);
celln: coverpoint `ci.celln { bins b1[] = {[0:N-1]}; }
dly : coverpoint `ci.dly;
st : coverpoint `ci.st { bins b1[] = {[0:2]}; }
celln_X_dly_X_st: cross celln, dly, st;
endgroup
cg #(N) cg_inst = new();
cgales
2
You can encapsulate your covergroup as part of a class and use the class parameter:
typedef struct packed {
bit [4:0] celln;
bit [1:0] dly;
bit [1:0] st;
} cell_struct;
class cell_class #(parameter N = 17);
randc cell_struct cell_randc;
constraint c { cell_randc.celln < N; cell_randc.st < 3; }
covergroup cg;
celln: coverpoint cell_randc.celln { bins b1[] = {[0:N-1]}; }
dly : coverpoint cell_randc.dly;
st : coverpoint cell_randc.st { bins b1[] = {[0:2]}; }
celln_X_dly_X_st: cross celln, dly, st;
endgroup
function new();
cg = new();
endfunction
endclass
module testbench();
localparam N = 17;
cell_class#(N) cell_inst = new();
initial begin
repeat (10) begin
if (!cell_inst.randomize()) begin
$display("Randomization failed");
end
else begin
$display("Randomization successful");
cell_inst.cg.sample();
end
end
end
endmodule
1 Like
It works!
Thank you for your quick response.