TLM get() Method

I explained put() function in my previous post. Today I’ll explain the get() TLM method with an example code.

In terms of purpose, get() method performs the same the put() does – only difference is that get() pulls the transaction from the Producer yet put() push the transaction to theConsumer.

It is illustrated clearly in the diagram below:

Associated example code can be found below:

`include “uvm_macros.svh”

module test;

import uvm_pkg::*;

///////////// Transaction /////////////////


/// Data members
typedef enum {READ, WRITE} kind_t;
rand bit [7:0] addr;
rand byte data;
kind_t kind;

function new (string name = “”);;
kind = kind_t'($urandom_range(0,1));
endfunction: new

endclass: my_txn

///////////// Producer ///////////////////
class producer extends uvm_component;

///// Export Declaration
uvm_blocking_get_imp #(my_txn, producer) my_export;

//// Constructor
function new (string name, uvm_component parent);, parent);
my_export = new(“my_export”, this);
endfunction: new

//// get() task implementation
task get(output my_txn t);
my_txn tmp;
tmp = my_txn::type_id::create(“tmp”, this);
t = tmp;
`uvm_info (“PID”, $sformatf(“Transaction type %s is sent”, t.kind), UVM_LOW)
endtask: get

endclass: producer

//////////// Consumer ///////////////////
class consumer extends uvm_component;

//// Port Declaration
uvm_blocking_get_port #(my_txn) my_port;

function new (string name, uvm_component parent);, parent);
my_port = new(“my_port”, this);
endfunction: new

task run_phase(uvm_phase phase);
for (int i=1; i<11; i++)
my_txn txn;
`uvm_info("CID", $sformatf("Transaction no. %0d is asked for", i), UVM_LOW)

`uvm_info(“CID”, $sformatf(“Transaction type %s is received”, txn.kind), UVM_LOW)
endtask: run_phase

endclass: consumer

/////////// Env /////////////////////////
class env extends uvm_env;

producer p1;
consumer c1;

function new (string name = “env”);;
endfunction: new

//// Build Function

function void build_phase (uvm_phase phase);
p1 = producer::type_id::create(“p1”, this);
c1 = consumer::type_id::create(“c1”, this);
endfunction: build_phase

//// Connect Function
function void connect_phase (uvm_phase phase);
endfunction: connect_phase

//// Run Task
task run_phase (uvm_phase phase);
endtask: run_phase

endclass: env

env e; // Environment Instantiation

e = new();

endmodule: test



Leave a Reply

Your email address will not be published. Required fields are marked *