UVM_TLM通信机制

uvm_tlm通信

TLM(transaction level modeling)是一个基于事务(transaction)的通信方式。是各个组件之间进行事务传输的方式。

1、三种端口

两个组件通信可将两者分为:

producer:生产数据方,即为producer;
consumer:接收数据方,即为consumer;

根据数据发送请求发起方不同可以大致分为三种端口:
(1)port:通信请求的端口。
(2)export:作为发起请求和接受请求的中间层次端口(可做为中间级连接port和imp)。
(3)imp:只能作为接收请求的响应端。

端口优先级:port > export > imp, 使用connect()建立连接关系时,只有优先级高的才能调用connect()做连接。比如:p.put_port.connect(c.put_imp);

2、连接方式

2.1put模式:

在这里插入图片描述数据请求由producer发起,通过调用consumer中的put函数建立起连接。红色为port端口,绿色为imp端口。事务传输方向为箭头指向方向。

class transaction extends uvm_transaction;      //传输数据包
   int id;
   int data;
   ...
endclass

class producer extends uvm_component;            //数据生产方producer
   ...
   uvm_blocking_put_port#(transaction)     put_port;     //定义端口
   function void build_phase(uvm_phase phase);
      put_port = new("put_port",this);               //创建实例化端口
   endfunction
   
   task run_phase(uvm_phase phase);        
      put_port.put(tr);        //通过数据接收方consumer提供的任务put()处理数据,然后通过TLM传输数据过去
   endtask
endclass

class consumer extends uvm_component;            //数据接收方consumer
   ...
   uvm_blocking_put_imp#(transaction, consumer)     put_imp;     //定义端口
   function void build_phase(uvm_phase phase);
      put_imp = new("put_imp",this);               //创建实例化端口
   endfunction
   
   virtual task put(transaction tr);        //数据生产方producer会调用接收方consumer定义的put()任务
      process(tr);        //通过数据接收方consumer提供的任务put()处理数据
   endtask
endclass

class environment extends uvm_env;       //环境层
   ...
   producer    p;    //数据生产方
   consumer    c;    //数据接收方
   ...
   virtual function void connect_phase(uvm_phase phase);
      p.put_port.connect(c.put_imp);       //建立连接
   endfunction
endclass
2.2get模式

在这里插入图片描述数据请求由consumer发起,通过调用producer中的get函数建立起连接。红色为port端口,绿色为imp端口。事务传输方向为箭头指向方向。

class transaction extends uvm_transaction;      //传输数据包
   int id;
   int data;
   ...
endclass

class producer extends uvm_component;            //数据生产方producer
   ...
   uvm_blocking_get_imp#(transaction,producer)     get_imp;     //定义端口
   function void build_phase(uvm_phase phase);
      get_imp = new("put_imp",this);               //创建实例化端口
   endfunction
    
   virtual task get(output transaction tr);        //在imp端口所在component中定义get()任务或者方法,output方向
      tr = transaction::type_id::create("tr",this);     
   endtask
endclass

class consumer extends uvm_component;            //数据接收方consumer
   ...
   uvm_blocking_get_port#(transaction, consumer)     get_port;     //定义端口
   function void build_phase(uvm_phase phase);
      put_imp = new("put_imp",this);               //创建实例化端口
   endfunction

   task run_phase(uvm_phase phase);        
      get_port.get(tr);        //通过imp所在component定义的get()处理数据,然后通过TLM传输数据
   endtask   
endclass

class environment extends uvm_env;       //环境层
   ...
   producer    p;    //数据生产方
   consumer    c;    //数据接收方
   ...
   virtual function void connect_phase(uvm_phase phase);
      c.get_port.connect(p.get_imp);       //建立连接
   endfunction
endclass
2.3fifo模式

在这里插入图片描述
fifo之前采用put模式接口,后端采用get模式接口。

class my_monitor extends uvm_monitor;

  `uvm_component_utils(my_monitor)

  virtual dut_interface m_vif;

  uvm_blocking_put_port #(my_transaction) m2r_port;

  function new(string name = "", uvm_component parent);
    super.new(name, parent);
    this.m2r_port = new("m2r_port", this);
  endfunction
  task run_phase(uvm_phase phase);        
      put_port.put(tr);        //通过数据接收方consumer提供的任务put()处理数据,然后通过TLM传输数据过去
   endtask
endclass

class master_agent extends uvm_agent;
  
  `uvm_component_utils(master_agent)

  my_sequencer m_seqr;
  my_driver    m_driv;
  my_monitor   m_moni;
  
  uvm_blocking_put_export #(my_transaction) m_a2r_export;

  function new(string name = "", uvm_component parent);
    super.new(name, parent);
    this.m_a2r_export = new("m_a2r_export", this);
  endfunction
  virtual function void connect_phase(uvm_phase phase);
    if(is_active == UVM_ACTIVE)
      m_driv.seq_item_port.connect(m_seqr.seq_item_export);
    m_moni.m2r_port.connect(this.m_a2r_export);
  endfunction
    
endclass

class my_reference_model extends uvm_component;
  `uvm_component_utils(my_reference_model)
  
  uvm_blocking_get_port #(my_transaction) i_m2r_port;
  my_transaction item;
  function new(string name = "", uvm_component parent);
    super.new(name, parent);
    this.i_m2r_port = new("i_m2r_port", this);
  endfunction
  virtual task run_phase(uvm_phase phase);
    `uvm_info("REF_MODEL_RUN", "Refernece model running !", UVM_MEDIUM)
    
    forever begin
      i_m2r_port.get(item);
      `uvm_info("REF_REPORT", {"\n", "master agent have been sent a transaction: \n", item.sprint()}, UVM_MEDIUM);
    end
  endtask

endclass

class my_env extends uvm_env;
  `uvm_component_utils(my_env)

  master_agent m_agent;
  my_reference_model ref_model;

  uvm_tlm_analysis_fifo #(my_transaction) magt2ref_fifo;//fifo


  function new(string name = "", uvm_component parent);
    super.new(name, parent);
    magt2ref_fifo = new("magt2ref", this);//实例化
  endfunction
  
virtual function void connect_phase(uvm_phase phase);
    super.connect_phase(phase);
    `uvm_info("ENV", "Connect the agent to fifo...", UVM_MEDIUM)
    m_agent.m_a2r_export.connect(this.magt2ref_fifo.blocking_put_export);
    `uvm_info("ENV", "Connect the reference model to fifl...", UVM_MEDIUM)
    ref_model.i_m2r_port.connect(this.magt2ref_fifo.blocking_get_export);
  endfunction

endclass

通信通道图解
在这里插入图片描述
monitor与modle之间的通信通过fifo模式,agent的端口为export为中间级。出現了跨层次传输,agent为中间层也需要设置端口。

2.4analysis_port

该通信方式与以上三种不同,以上三种属于一对一传输,该种方式为一对多。
在这里插入图片描述

class my_monitor extends uvm_monitor;

  `uvm_component_utils(my_monitor)

  virtual dut_interface m_vif;

  uvm_analysis_port #(my_transaction) m2r_a_port;

  function new(string name = "", uvm_component parent);
    super.new(name, parent);
    this.m2r_a_port = new("m2r_a_port", this);
  endfunction
 task run_phase(uvm_phase phase);        
      m2r_a_port.write(tr);        //通过数据接收方consumer提供的任务write()处理数据,然后通过TLM传输数据过去
   endtask
endclass

class master_agent extends uvm_agent;
  
  `uvm_component_utils(master_agent)

  my_sequencer m_seqr;
  my_driver    m_driv;
  my_monitor   m_moni;

  agent_config m_agent_cfg;
  
  uvm_analysis_port #(my_transaction) m_a2r_a_port;

  function new(string name = "", uvm_component parent);
    super.new(name, parent);
    this.m_a2r_a_port = new("m_a2r_a_port", this);
  endfunction
virtual function void connect_phase(uvm_phase phase);
    if(is_active == UVM_ACTIVE)
      m_driv.seq_item_port.connect(m_seqr.seq_item_export);
    m_moni.m2r_a_port = this.m_a2r_a_port;
  endfunction
    
endclass


class my_reference_model extends uvm_component;
  
  `uvm_component_utils(my_reference_model)
  
  uvm_analysis_imp #(my_transaction, my_reference_model) i_m2r_a_imp;
  my_transaction item;

  function new(string name = "", uvm_component parent);
    super.new(name, parent);
    this.i_m2r_a_imp = new("i_m2r_a_imp", this);
  endfunction

  task write(my_transaction tr);

    `uvm_info("REF_REPORT", {"\n", "master agent have been sent a transaction: \n", tr.sprint()}, UVM_MEDIUM);

  endtask

endclass

class my_env extends uvm_env;
  
  `uvm_component_utils(my_env)

  master_agent m_agent;
  env_config   m_env_cfg;
 // agent_config m_agent_cfg;
  my_reference_model ref_model;


  function new(string name = "", uvm_component parent);
    super.new(name, parent);
  endfunction
 virtual function void connect_phase(uvm_phase phase);
    super.connect_phase(phase);
    `uvm_info("ENV", "Connect the agent and reference model...", UVM_MEDIUM)
    m_agent.m_a2r_a_port.connect(ref_model.i_m2r_a_imp);
  endfunction

endclass

四种通信方式完整的构成了UVM的事物传输。

  • 6
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
学习uvm必看的书。 1. Overview.............................................................................................................................................. 1 1.1 Introduction to UVM.................................................................................................................. 1 1.1.1 Coverage-Driven Verification (CDV) ........................................................................ 1 1.1.2 Testbenches and Environments .................................................................................. 1 1.2 Verification Component Overview ............................................................................................ 3 1.2.1 Data Item (Transaction) .............................................................................................. 3 1.2.2 Driver (BFM) .............................................................................................................. 3 1.2.3 Sequencer .................................................................................................................... 3 1.2.4 Monitor ....................................................................................................................... 3 1.2.5 Agent ........................................................................................................................... 4 1.2.6 Environment ................................................................................................................ 4 1.3 The UVM Class Library............................................................................................................. 5 1.4 Other UVM Facilities................................................................................................................. 7 1.4.1 UVM Factory .............................................................................................................. 7 1.4.2 Transaction-Level Modeling (TLM) .......................................................................... 8 2. Transaction-Level Modeling (TLM) ................................................................................................... 9 2.1 Overview .................................................................................................................................... 9 2.2 TLM, TLM-1, and TLM-2.0 ...................................................................................................... 9 2.2.1 TLM-1 Implementation ............................................................................................ 10 2.2.2 TLM-2.0 Implementation ......................................................................................... 10 2.3 Basics ....................................................................................................................................... 10 2.3.1 Transactions .............................................................................................................. 10 2.3.2 Transaction-Level Communication .......................................................................... 11 2.3.3 Basic TLM Communication ..................................................................................... 11 2.3.4 Communicating between Processes .......................................................................... 12 2.3.5 Blocking versus Nonblocking ................................................................................... 13 2.3.6 Connecting Transaction-Level Components ............................................................ 13 2.3.7 Peer-to-Peer connections .......................................................................................... 14 2.3.8 Port/Export Compatibility ......................................................................................... 14 2.4 Encapsulation and Hierarchy ................................................................................................... 14 2.4.1 Hierarchical Connections .......................................................................................... 14 2.4.2 Connection Types ..................................................................................................... 16 2.5 Analysis Communication ......................................................................................................... 16 2.5.1 Analysis Ports ........................................................................................................... 16 2.5.2 Analysis Exports ....................................................................................................... 17 2.6 Generic Payload ....................................................................................................................... 18 2.6.1 Attributes .................................................................................................................. 18 2.6.2 Accessors .................................................................................................................. 19 2.6.3 Extensions ................................................................................................................. 20 2.7 Core Interfaces and Ports ......................................................................................................... 21 2.8 Blocking Transport................................................................................................................... 22 2.9 Nonblocking Transport ............................................................................................................ 22 2.10 Sockets ..................................................................................................................................... 24 2.11 Time ......................................................................................................................................... 26 2.12 Use Models............................................................................................................................... 28

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值