Tutorials

Learn More

  1. The generic payload is nothing but a transaction type used in TLM 2.0
  2. It has various data members (with protected type), enums, and methods available.

uvm_tlm_generic_payload data members and methods

typedef enum { TLM_READ_COMMAND, TLM_WRITE_COMMAND, TLM_IGNORE_COMMAND } uvm_tlm_command_e;

protected rand byte m_data[ ];
protected rand bit [63:0 ]m_address;
protected rand int unsigned m_byte_enable_length;
virtual function bit is_read();
virtual function void set_write();

Generic Payload Example

`include "uvm_macros.svh"
import uvm_pkg::*;
class producer extends uvm_component;
  uvm_tlm_generic_payload req;
  uvm_tlm_b_initiator_socket #(uvm_tlm_generic_payload) sender_port;
  uvm_tlm_time tlm_delay;
  
  `uvm_component_utils(producer)
  
  function new(string name = "producer", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    sender_port = new("sender_port", this);
    tlm_delay = new("tlm_delay", 0);
  endfunction
  
  task run_phase(uvm_phase phase);
    super.run_phase(phase);
    req = uvm_tlm_generic_payload::type_id::create("req");
    assert(req.randomize());
    req.m_address = 5;
    sender_port.b_transport(req, tlm_delay);
    req.print();
    `uvm_info(get_name(), $sformatf("Send m_address = %0h", req.m_address), UVM_NONE);
  endtask
endclass

class consumer extends uvm_component;
  uvm_tlm_b_target_socket #(consumer, uvm_tlm_generic_payload) receiver_port;
  
  `uvm_component_utils(consumer)
  
  function new(string name = "consumer", uvm_component parent = null);
    super.new(name, parent);
    receiver_port = new("receiver_port", this);
  endfunction
  
  virtual task b_transport(uvm_tlm_generic_payload req, uvm_tlm_time tlm_delay);
    req.print();
    `uvm_info(get_type_name(), $sformatf("Received m_address = %0h", req.m_address), UVM_NONE);
  endtask
endclass

class env extends uvm_env;
  producer pro;
  consumer con;
  `uvm_component_utils(env)
  
  function new(string name = "env", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    pro = producer::type_id::create("pro", this);
    con = consumer::type_id::create("con", this);
  endfunction
  
  function void connect_phase(uvm_phase phase);
    super.connect_phase(phase);
    pro.sender_port.connect(con.receiver_port);
  endfunction
endclass
              
class test extends uvm_test;
  env env_o;
  `uvm_component_utils(test)
  
  function new(string name = "test", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    env_o = env::type_id::create("env_o", this);
  endfunction
 
  task run_phase(uvm_phase phase);
    phase.raise_objection(this);
    #50;
    phase.drop_objection(this);
  endtask
endclass

module tb_top;
  initial begin
    run_test("test");
  end
endmodule

Output:

--------------------------------------------------------------------------------
Name               Type                       Size         Value                
--------------------------------------------------------------------------------
req                uvm_tlm_generic_payload    -            @2091                
  address          integral                   64           'h5                  
  command          uvm_tlm_command_e          32           UVM_TLM_WRITE_COMMAND
  response_status  uvm_tlm_response_status_e  32           UVM_TLM_OK_RESPONSE  
  streaming_width  integral                   32           'hd0515c56           
  data             darray(byte)               -1414533387  -                    
  extensions       aa(obj,obj)                0            -                    
--------------------------------------------------------------------------------
UVM_INFO testbench.sv(43) @ 0: uvm_test_top.env_o.con [consumer] Received m_address = 5
--------------------------------------------------------------------------------
Name               Type                       Size         Value                
--------------------------------------------------------------------------------
req                uvm_tlm_generic_payload    -            @2091                
  address          integral                   64           'h5                  
  command          uvm_tlm_command_e          32           UVM_TLM_WRITE_COMMAND
  response_status  uvm_tlm_response_status_e  32           UVM_TLM_OK_RESPONSE  
  streaming_width  integral                   32           'hd0515c56           
  data             darray(byte)               -1414533387  -                    
  extensions       aa(obj,obj)                0            -                    
--------------------------------------------------------------------------------
UVM_INFO testbench.sv(27) @ 0: uvm_test_top.env_o.pro [pro] Send m_address = 5

Generic Payload extension

  1. uvm_tlm_generic_payload transaction has extension container which is derived from uvm_tlm_extension class
  2. Extension containers can store additional information based on user requirements.

Generic Payload extension example

`include "uvm_macros.svh"
import uvm_pkg::*;
class gp_extension extends uvm_tlm_extension;
  rand bit enable;
  rand bit [31:0] e_addr;
  rand bit [31:0] e_data;
  
  `uvm_object_utils_begin(gp_extension)
    `uvm_field_int(enable, UVM_PRINT)
    `uvm_field_int(e_addr, UVM_PRINT)
    `uvm_field_int(e_data, UVM_PRINT)  
  `uvm_object_utils_end
  
  function new(string name = "gp_extension");
    super.new(name);
  endfunction
endclass

class producer extends uvm_component;
  uvm_tlm_generic_payload req;
  gp_extension extension;
  uvm_tlm_b_initiator_socket #(uvm_tlm_generic_payload) sender_port;
  uvm_tlm_time tlm_delay;
  
  `uvm_component_utils(producer)
  
  function new(string name = "producer", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    sender_port = new("sender_port", this);
    tlm_delay = new("tlm_delay", 0);
  endfunction
  
  task run_phase(uvm_phase phase);
    super.run_phase(phase);
    req = uvm_tlm_generic_payload::type_id::create("req");
    extension = gp_extension::type_id::create("extension");
    req.set_extension(extension);
    assert(req.randomize with {m_address == 5;});
    `uvm_info(get_name(), $sformatf("Number of extensions = %0d", req.get_num_extensions()), UVM_NONE);
    `uvm_info(get_name(), $sformatf("With set_extension: req =\n%s", req.sprint()), UVM_NONE);
    sender_port.b_transport(req, tlm_delay);
    #5;
    req.clear_extensions();
    assert(req.randomize with {m_address == 7;});
    `uvm_info(get_name(), $sformatf("With clear_extension: req =\n%s", req.sprint()), UVM_NONE);
  endtask
endclass

class consumer extends uvm_component;
  uvm_tlm_b_target_socket #(consumer, uvm_tlm_generic_payload) receiver_port;
  
  `uvm_component_utils(consumer)
  
  function new(string name = "consumer", uvm_component parent = null);
    super.new(name, parent);
    receiver_port = new("receiver_port", this);
  endfunction
  
  virtual task b_transport(uvm_tlm_generic_payload req, uvm_tlm_time tlm_delay);
    `uvm_info(get_type_name(), $sformatf("Received payload =\n%s", req.sprint()), UVM_NONE);
  endtask
endclass

class env extends uvm_env;
  producer pro;
  consumer con;
  `uvm_component_utils(env)
  
  function new(string name = "env", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    pro = producer::type_id::create("pro", this);
    con = consumer::type_id::create("con", this);
  endfunction
  
  function void connect_phase(uvm_phase phase);
    super.connect_phase(phase);
    pro.sender_port.connect(con.receiver_port);
  endfunction
endclass
              
class test extends uvm_test;
  env env_o;
  `uvm_component_utils(test)
  
  function new(string name = "test", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    env_o = env::type_id::create("env_o", this);
  endfunction
 
  task run_phase(uvm_phase phase);
    phase.raise_objection(this);
    #50;
    phase.drop_objection(this);
  endtask
endclass

module tb_top;
  initial begin
    run_test("test");
  end
endmodule

Output:

UVM_INFO testbench.sv(43) @ 0: uvm_test_top.env_o.pro [pro] Number of extensions = 1
UVM_INFO testbench.sv(44) @ 0: uvm_test_top.env_o.pro [pro] With set_extension: req =
--------------------------------------------------------------------------------------
Name               Type                       Size        Value                       
--------------------------------------------------------------------------------------
req                uvm_tlm_generic_payload    -           @405                        
  address          integral                   64          'h5                         
  command          uvm_tlm_command_e          32          UVM_TLM_WRITE_COMMAND       
  response_status  uvm_tlm_response_status_e  32          UVM_TLM_BURST_ERROR_RESPONSE
  streaming_width  integral                   32          'h4663e79e                  
  data             darray(byte)               1231984224  -                           
  extensions       aa(obj,obj)                1           -                           
    [extension]    gp_extension               -           @409                        
      enable       integral                   1           'h0                         
      e_addr       integral                   32          'h5397ad67                  
      e_data       integral                   32          'hbd319803                  
--------------------------------------------------------------------------------------

UVM_INFO testbench.sv(64) @ 0: uvm_test_top.env_o.con [consumer] Received payload =
--------------------------------------------------------------------------------------
Name               Type                       Size        Value                       
--------------------------------------------------------------------------------------
req                uvm_tlm_generic_payload    -           @405                        
  address          integral                   64          'h5                         
  command          uvm_tlm_command_e          32          UVM_TLM_WRITE_COMMAND       
  response_status  uvm_tlm_response_status_e  32          UVM_TLM_BURST_ERROR_RESPONSE
  streaming_width  integral                   32          'h4663e79e                  
  data             darray(byte)               1231984224  -                           
  extensions       aa(obj,obj)                1           -                           
    [extension]    gp_extension               -           @409                        
      enable       integral                   1           'h0                         
      e_addr       integral                   32          'h5397ad67                  
      e_data       integral                   32          'hbd319803                  
--------------------------------------------------------------------------------------

UVM_INFO testbench.sv(49) @ 5: uvm_test_top.env_o.pro [pro] With clear_extension: req =
-----------------------------------------------------------------------------------------
Name               Type                       Size         Value                         
-----------------------------------------------------------------------------------------
req                uvm_tlm_generic_payload    -            @405                          
  address          integral                   64           'h7                           
  command          uvm_tlm_command_e          32           UVM_TLM_READ_COMMAND          
  response_status  uvm_tlm_response_status_e  32           UVM_TLM_COMMAND_ERROR_RESPONSE
  streaming_width  integral                   32           'h4cc90044                    
  data             darray(byte)               -1912894104  -                             
  extensions       aa(obj,obj)                0            -                             
-----------------------------------------------------------------------------------------