Jump to content
Sign in to follow this  
mpeer

Unexpected behavior of uvm_tlm_fifo (Bug or bad usage?)

Recommended Posts

Hi All,

I am trying to use tlm fifo. At first putting 10 elements after that I tried getting those elements but I always get the last data from uvm_tlm_fifo.

Below is the complete code and the simulation result. Please let me know how should I use it so that I can retrieve all the elements which are being fed into it.

I know, I have put_port, get_port and fifo all three inside single component and have connections here itself. It is done intentionally.

=====================================================================

Code Here

=====================================================================

import uvm_pkg::*;

class trans extends uvm_sequence_item;

`uvm_object_utils(trans)

rand int a;

rand int b;

function new(string name="trans");

super.new(name);

endfunction

function void do_print(uvm_printer printer);

super.do_print(printer);

$display("A =%0h", a);

$display("B =%0h", B);

endfunction

endclass

//-----------------------------------//

//-----------------------------------//

class mon extends uvm_component;

`uvm_component_utils(mon)

uvm_tlm_fifo #(trans) fifo;

uvm_blocking_put_port #(trans) pp;

uvm_blocking_get_port #(trans) gp;

function new(string name = "sb", uvm_component parent = null);

super.new(name, parent);

endfunction

function void build_phase (uvm_phase phase);

super.build_phase(phase);

fifo = new ("fifo", this, 100);

pp = new ("put_port", this);

gp = new ("get_port", this);

endfunction

function void connect_phase(uvm_phase phase);

pp.connect(fifo.put_export);

gp.connect(fifo.get_export);

endfunction

task run_phase(uvm_phase phase);

trans t = new();

trans t2;

$display("Fifo capacity is %0d", fifo.size());

$display("Putting elements..");

repeat(10) begin

t.randomize();

t.print();

pp.put(t);

$display("Fifo is filled with %0d element(s)", fifo.used());

end

$display("Retrieving elements..");

repeat(10) begin

gp.get(t2);

t2.print();

$display("Fifo size after retieving one element is %0d element(s)", fifo.used());

t2 = null;

end

endtask

endclass

//-----------------------------------//

//-----------------------------------//

module test;

class test1 extends uvm_test;

`uvm_component_utils(test1)

mon m;

function new(string name="test1", uvm_component parent);

super.new(name, parent);

endfunction

function void build_phase (uvm_phase phase);

m = mon::type_id::create("mon", this);

endfunction : build_phase

endclass

initial begin

run_test("test1");

end

endmodule

=================================================================

Simulation Result:

=================================================================

UVM_INFO @ 0: reporter [RNTST] Running test test1...

Fifo capacity is 100

Putting elements..

A =ca343fb9

B =94149dec

Fifo is filled with 1 element(s)

A =13ab51b1

B =f262ab77

Fifo is filled with 2 element(s)

A =76906067

B =8c595989

Fifo is filled with 3 element(s)

A =a72b2dd1

B =cfc3e29a

Fifo is filled with 4 element(s)

A =bddac76f

B =517829e8

Fifo is filled with 5 element(s)

A =ec897a2a

B =88742996

Fifo is filled with 6 element(s)

A =f5901441

B =89d0eac5

Fifo is filled with 7 element(s)

A =dd44e7b3

B =7661e07a

Fifo is filled with 8 element(s)

A =786cb3a3

B =2a109a17

Fifo is filled with 9 element(s)

A =661c7064

B =ec640f5a

Fifo is filled with 10 element(s)

Retrieving elements..

A =661c7064

B =ec640f5a

Fifo size after retieving one element is 9 element(s)

A =661c7064

B =ec640f5a

Fifo size after retieving one element is 8 element(s)

A =661c7064

B =ec640f5a

Fifo size after retieving one element is 7 element(s)

A =661c7064

B =ec640f5a

Fifo size after retieving one element is 6 element(s)

A =661c7064

B =ec640f5a

Fifo size after retieving one element is 5 element(s)

A =661c7064

B =ec640f5a

Fifo size after retieving one element is 4 element(s)

A =661c7064

B =ec640f5a

Fifo size after retieving one element is 3 element(s)

A =661c7064

B =ec640f5a

Fifo size after retieving one element is 2 element(s)

A =661c7064

B =ec640f5a

Fifo size after retieving one element is 1 element(s)

A =661c7064

B =ec640f5a

Fifo size after retieving one element is 0 element(s)

Share this post


Link to post
Share on other sites

Hi enchanter,

I made change in run_phase().

I moved trans t = new() inside repeat(10);

Below is the code after change.

task run_phase(uvm_phase phase);

// trans t = new(); // Removed from this line

trans t2;

$display("Fifo capacity is %0d", fifo.size());

$display("Putting elements..");

repeat(10) begin

trans t = new(); // Moved here; Now for each item there will be new handle.

t.randomize();

t.print();

pp.put(t); // Putting into the fifo.

$display("Fifo is filled with %0d element(s)", fifo.used());

end

$display("Retrieving elements..");

repeat(10) begin

gp.get(t2);

t2.print();

$display("Fifo size after retieving one element is %0d element(s)", fifo.used());

t2 = null;

end

Regards

Peer Mohammed

Share this post


Link to post
Share on other sites

Hi Peer,

Make sure you use factory to create the transactions for good code. Also I usually suggest you split the declaration and allocation into 2 steps.

// Moved the declaration outside the task:

trans t;

task run_phase(uvm_phase phase);

trans t2;

$display("Fifo capacity is %0d", fifo.size());

$display("Putting elements..");

repeat(10) begin

this.t = trans::type_id::create(); // Use factory than new

this.t.randomize(); // You should rather be checking the return value here..

HTH

Srini

www.cvcblr.com/blog

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×