I'm trying to create a task for a UVM sequence that takes a packed data input and uses it for a constraint on an unpacked value.
The goal is to have something that looks like this:
if((!msg.randomize() with
{
{msg_pld[0], msg_pld[1], msg_pld[2], msg_pld[3]} == 32'h01234567; //address
{msg_pld[4], msg_pld[5], msg_pld[6], msg_pld[7]} == 32'hDEADBEEF; //data
}))
`uvm_fatal("EX_SEQ", "failed to randomize message")
(the above code works just fine)
But have be it's own task that can be called with the data and address values passed in.
The code I have written to do this is as follows:
task send_message (wr_req_item msg, bit[31:0] addr, bit[31:0] data);
if((!msg.randomize() with
{
{msg_pld[0], msg_pld[1], msg_pld[2], msg_pld[3]} == addr; //address
{msg_pld[4], msg_pld[5], msg_pld[6], msg_pld[7]} == data; //data
}))
`uvm_fatal("EX_SEQ", "failed to randomize message")
//some other things that are also done in this sequence but are irrelevant to this question
endtask;
With a call looking like this:
send_message(ex_msg , 32'h01234567, 32'hDEADBEEF)
When I try to execute this though I get a compilation error saying "cannot mix packed and unpacked types in this operation"
What syntax or data types should I be using so I can have my task take in basic 32 bit values as listed for the constraints?
Edit: Added info
The error says it occurs on the following line:
{msg_pld[4], msg_pld[5], msg_pld[6], msg_pld[7]} == data; //data
msg_pld is defined as:
rand bit [7:0] msg_pld[ ];
EDIT 2:
I have a solution but it is very clunky.
The following works:
task send_message (wr_req_item msg, bit[31:0] addr, bit[31:0] data);
bit [63:0] addrdata = {addr, data}
if((!msg.randomize() with
{
{msg_pld[0], msg_pld[1], msg_pld[2], msg_pld[3], msg_pld[4], msg_pld[5], msg_pld[6], msg_pld[7]} == addrdata;
}))
`uvm_fatal("EX_SEQ", "failed to randomize message")
endtask;
However:
A) This solution is clunky, ugly code
B) I don't understand why this solution works and the original code does not
C) I don't understand why with this solution it only works when addrdata is declared as it's own variable and I can't just concatenate addr and data on the line I do the comparison (I tried this and it didn't work)
It's possible all of this lies buried deep inside legacy code seeing as in a basic setting it appears what I originally wrote would work.