At the point of tcode_tx randomization inside a corresponding sequence, I want to be able to assign an integer counter value to the unconstrained part, i.e. tcode_tx[7:2].
repeat (tc_req_cnt) begin
tc_counter++;
start_item(req_item_c);
if(!req_item_c.randomize() with {send_tc == 1;
tcode_tx[7:2] == '{tc_counter};
}) begin
`uvm_fatal("BODY:", "req_item_c randomization failed")
end
`uvm_info("BODY:", req_item_c.convert2string(), UVM_MEDIUM);
finish_item(req_item_c);
if(tc_counter == 63) begin
// Reached max. tc_counter value
tc_counter = 0;
end
end
But the assignment fails for now. Any tips on how to do it correctly?
Can you make code_tx a packed array? Then you could do
tcode_tx[7:2] == tc_counter;
Hi,
the code above works, thanks! Is there no other way to do it besides assigning the value bit by bit? (type casting, streaming, anything else?)
I chose tcode_tx to be an unpacked array, because the array is passed as a parameter to a task inside a driver, where the parameter can also be a queue (thus unpacked).
My intention was to increment an integer value (here: tc_counter) and with every new sequence item assign the incremented value to the slice tcode_tx[7:2], i.e. assign the int type value to a 6 bit wide slice of an unpacked array (somehow!). That’s why I reset tc_counter to 0 if it hits 63 = 6’b111111.
Even if I assigned a constant value, as I would do to initialize an unpacked array, e.g.
tcode_tx[7:2] == '{1,1,0,0,1,0}
within the randomization part, I get a compilation error.
Why don’t you declare it as a packed array, and then cast as an unpacked array. Or you can cast it to a packed local variable and use that in your constraint.
In reply to Fipser@VA:
Why don’t you declare it as a packed array, and then cast as an unpacked array. Or you can cast it to a packed local variable and use that in your constraint.
Do you mean like:
logic [5:0] tc_val;
// ...
repeat (tc_req_cnt) begin
tc_val++;
start_item(req_item_c);
if(!req_item_c.randomize() with {send_tc == 1;
tcode_tx[7:2] == '{tc_val[5],tc_val[4],
tc_val[3],tc_val[2],
tc_val[1],tc_val[0]
};
}) begin
// ...
finish_item(req_item_c);
if(tc_val == 63) begin
// Reached max. tc counter value
tc_val = 0;
end
end
That way, I get two error messages as follows:
**** Error: …/…/xxx.svh(62): (vopt-2936) Illegal non-integral expression in random constraint.
** Error: (vopt-2064) Compiler back-end code generation process terminated with code 2.**
Line 62 is the line within the randomize() part where the assignment tcode_tx[7:2] == … is made.