Hi,
I am trying to use flush function in uvm_tlm_fifo class to clear all transactions in uvm_tlm_fifo, but it can not work correctly.
the code of flush function in uvm_tlm_fifo class is as below.
// Function -- NODOCS -- flush
//
// Removes all entries from the FIFO, after which <used> returns 0
// and <is_empty> returns 1.
virtual function void flush();
T t;
bit r;
m_clear_zombie_gets();
if( m.num() > 0 && m_pending_blocked_gets.size() != 0 ) begin
uvm_report_error("flush failed" ,
"there are blocked gets preventing the flush", UVM_NONE);
return;
end
r = 1;
while( r ) r = m.try_get( t ) ;
endfunction
For " while( r ) r = m.try_get( t ) ; ", in the while loop it used mailbox m in-build function try_get().
Reference to Systemverilog IEEE 1800-2017 LRM 15.4.6 try_get():
If a message is available and the message type is equivalent to the type of the message variable, the message is retrieved, and the method returns a positive integer.
m.try_get(t) returns a positive integer number, and it will be assigned to var r, but var r is bit type, so int number bit0 will be assigned to var r actually. In that case, r may be assigned to zero, and while loop can go out even when mailbox m still has transaction in it. That is the case I meet, the flush function does not work as expected.
I also download previous release of UVM code. I found before UVM 2017 v1.1 Library Code for IEEE 1800.2 flush function is correct. the code is as below:
// Function -- NODOCS -- flush
//
// Removes all entries from the FIFO, after which <used> returns 0
// and <is_empty> returns 1.
virtual function void flush();
T t;
bit r;
r = 1;
while( r ) r = try_get( t ) ;
if( m.num() > 0 && m_pending_blocked_gets != 0 ) begin
uvm_report_error("flush failed" ,
"there are blocked gets preventing the flush", UVM_NONE);
end
endfunction