I'm using mailbox in a UVM SV test bench and facing some issue while trying to write in mailbox. My code looks like bellow:
class my_seqyuence extends uvm_sequence;
mailbox data;
some_user_defined_type mydata;
function new(string name = "my_sequence");
super.new(name);
data=new();
endfunction
task body();
forever begin
// blocking-get. program is blocked here... not why get is not returning...!
data.get(mydata);
decode_mydata_and_do_something_here;
end
endtask
function void writetrans(some_user_defined_type trans);
// I used print statements with mailbox size and i can see that valid trans is arriving here and successfully writing to mailbox.
data.try_put(trans)
endfunction
endclass
I'm not quite sure what went wrong... Data is arriving all the way to writetrans(*) function and eventually it's failing to write even though there is space in mailbox.
A couple of issues with your code, but without knowing exactly how you have coordinating the calling of the functions and tasks, it is difficult to know what might be the problem.
You should always test the result of try_put()
and try_get()
to see if they were successful.
You should always use parametrized mailboxes for safer type checking
mailbox #(some_user_defined_type) data;
1) An anaylsis_export or anaylsis_imp is used to connect to an analysis port of your monitor.
2) Since your mailbox is unbounded, use put() instead of a try_put(). According the the SystemVerilog LRM, try_put is meaningless for unbounded mailbox. It is only used to non-blocking put items into the mailbox. Not sure what meaningless means, but it might mean it doesnt function as expected.
From the LRM -
The try_put() method stores a message in the mailbox in strict FIFO
order. This method is meaningful only for bounded mailboxes.
3) Use num() function of the mailbox before your get() method to ensure it is greater than 1. Alternatively, you can do a try_get() and check if the return value is 1 (0-> it is empty, -1-> type mismatch)