Hello !
I am trying to form a pkt [whose size can be variable] which has 4 fields [whose size is also variable]. When i try to create a parameterized class with run time variable I face the below issue [which make sense/standard].
module pkt_stim;
class req_pkt #(int f1_size = 16, int f2_size = 16, int f3_size = 16, int f4_size = 16);
rand bit [f1_size-1:0] f1;
rand bit [f2_size-1:0] f2;
rand bit [f3_size-1:0] f3;
rand bit [f4_size-1:0] f4;
endclass: req_pkt
class tran_pkt #(int pkt_size = 64);
rand bit [pkt_size-1:0] pkt;
rand bit [31:0] A,B,C,D;
constraint fld_size_c {
A <= pkt_size;
B <= pkt_size;
C <= pkt_size;
D <= pkt_size;
A + B + C + D == pkt_size;
}
function void post_randomize;
req_pkt #(.f1_size(A), .f2_size(B), .f3_size(C), .f4_size(D)) rp = new();
assert (rp.randomize());
pkt = {rp.f4, rp.f3, rp.f2, rp.f1};
endfunction: post_randomize
function print_inf;
$display("Size A = %0d, B = %0d, C = %0d, D = %0d\n", A, B, C, D);
$display("f4 = %0h, f3 = %0h, f2 = %0h, f1 = %0h\n", rp.f4, rp.f3, rp.f2, rp.f1);
$display("pkt Value = %0h\n", pkt);
endfunction: print_inf
endclass: tran_pkt
initial begin
tran_pkt tp = new();
assert(tp.randomize());
tp.print_inf();
end
endmodule: pkt_stim
Error:
Error-[NCE] Non-constant expression
The following expression should be a constant.
Expression: this.A
"pkt_stim.sv", 19
Source info: req_pkt #(.f1_size(A), .f2_size(B), .f3_size(C),
.f4_size(D)) rp = new();
'this' is not an elaboration-time constant. To correct the error you may
convert this const variable to a parameter or a localparam.
Error-[NCE] Non-constant expression
The following expression should be a constant.
Expression: this.B
"pkt_stim.sv", 19
Source info: req_pkt #(.f1_size(A), .f2_size(B), .f3_size(C),
.f4_size(D)) rp = new();
'this' is not an elaboration-time constant. To correct the error you may
convert this const variable to a parameter or a localparam.
Error-[NCE] Non-constant expression
The following expression should be a constant.
Expression: this.C
"pkt_stim.sv", 19
Source info: req_pkt #(.f1_size(A), .f2_size(B), .f3_size(C),
.f4_size(D)) rp = new();
'this' is not an elaboration-time constant. To correct the error you may
convert this const variable to a parameter or a localparam.
Error-[NCE] Non-constant expression
The following expression should be a constant.
Expression: this.D
"pkt_stim.sv", 19
Source info: req_pkt #(.f1_size(A), .f2_size(B), .f3_size(C),
.f4_size(D)) rp = new();
'this' is not an elaboration-time constant. To correct the error you may
convert this const variable to a parameter or a localparam.
How can I overcome this scenario or any other better way of packetizing variable size pkt with variable size fields ?