宁安找小姐小妹包夜上门服务 ... https://blog.eetop.cn/116762 [收藏] [复制] [分享] [RSS] 【微信:99093588】宁安找小姐上门服务【微信:99093588】宁安找小姐保健按摩服务【微信:99093588】《宁安小姐服务电话》【微信:99093588】《宁安 ...

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

OVM component相互传递transaction的方法解析

已有 526 次阅读| 2013-3-6 10:11 |个人分类:验证SV/OVM/UVM

网上找了一个例子,展示OVM中Component(例如scoreboard和monitor)相互传递transaction的机制。别看这短短60多行,不好理解。

 virtual class port_base#(type T=int) ; // ¹¹ÔìÒ»¸ö³éÏóÀà
   typedef port_base#(T) this_type;
    this_type port_handle; // ÉêÃ÷Ò»¸ö¶ÔÏó¾ä±ú£¨Ö¸Õ룩
 
   pure virtual task put_t(T trans); // ´¿Ð麯Êý£¬put_portºÍput_imp¶¼±ØÐëÒÔËüΪ»ùÀà
 
   function void connect(this_type port); // connect½ö½öÊÇʵÏÖ¶ÔÏó¾ä±úµÄ¸³Öµ
     port_handle = port;
   endfunction // connect
 
 endclass // port_base
 
 class put_port#(type T=int) extends port_base#(T);
   virtual task put_t(T trans);
     port_handle.put_t(trans);
   endtask // put_t
 endclass // put_port
 
 class put_imp#(type T=int, type IMP=int) extends port_base#(T);
   local IMP m_imp;  // imp±íʾ¾ßÌåʵÏÖput_t()º¯ÊýµÄ¶ÔÏó¾ä±ú¡£
   function new(IMP imp);
     m_imp = imp;
   endfunction // new
 
   virtual task put_t(T trans);
     m_imp.put_t(trans);  // µ÷ÓÃʵÏÖ¶ÔÏó¶ÔÓ¦µÄput_t()º¯Êý
   endtask // put_t
 
 endclass // put_imp
 
 class producer;
   put_port#(int) m_put_port;
   function new();
     m_put_port = new();
   endfunction // new
 
   task run();
     for(int i=0; i<10; i++) begin  // ˳Ðò²úÉú10¸öintÀàÐ͵Ätransaction.
       m_put_port.put_t(i);
     end
   endtask // run
 endclass // producer
 
 class consumer;
   put_imp#(int, consumer)  m_put_export;
   function new();
     m_put_export = new(this); //½«consumer¾ä±ú´«µÝ¸øput_impÖÐimp±äÁ¿£¬´Ó¶øʵÏÖ½Ó¹Üput_t()×îÖÕʵÏÖ
   endfunction // new
 
   task put_t(int trans);
     $display("[INFO]: Got the transaction:%d", trans);
   endtask // put_t
 endclass // consumer
 
 module top;
   producer p;
   consumer c;
   initial begin
     p = new();
     c = new();
     p.m_put_port.connect(c.m_put_export);  //ͨ¹ý¾ä±ú¸³Öµ½øÐÐÁ¬½Ó
     p.run();
     #10 $finish;
   end
 endmodule

 

关于此例解析:

producer对象里包含了一个put_port#(int) m_put_port;

consumer里包含了一个   put_imp#(int, consumer)  m_put_export;

top中 p.m_put_port.connect(c.m_put_export); 执行的是port_base的方法,实现port_handle指向父类c.m_put_export

producer里run的      m_put_port.put_t(i)会调用put_port中的put_t方法,而其内容却是:

 class put_port#(type T=int) extends port_base#(T);
   virtual task put_t(T trans);
     port_handle.put_t(trans);
   endtask // put_t
 endclass // put_port

而port_handle此时又已经指向了c.m_put_export,所以会调用put_imp中的put_t(SV里面多态是这样的规则:如果函数加了virtual关键字,那么就是根据当前指针指向哪个类的方法就调用哪个类的;):
   virtual task put_t(T trans);
     m_imp.put_t(trans);  
   endtask // put_t

从而最终实现调用consumer中的put_t方法

OOP基础补充:

SV里面多态是这样的规则:如果函数加了virtual关键字,那么就是根据当前指针指向哪个类的方法就调用哪个类的;

virtual class 虚类只用来定义类的格式, 和成员的名字, 参数, 不能被实例化, 只能被重载, 用于在项目中定义一些标准的类, 例如driver, 这样大家extend出来的driver的基本的格式都是一样的, 易读易理解. virtual class里的方法最好使用 pure virtual 修饰, 叫做纯虚方法, 也是用来定义方法的名字和参数列表的, 方便大家统一名字.

 


 

个人觉得SV for verification那本书上的mailbox方法很好用,这个OVM传递transaction的方法理解起来有点坑爹。

 

 


点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 1

    粉丝
  • 3

    好友
  • 0

    获赞
  • 6

    评论
  • 470

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-8 18:54 , Processed in 0.022611 second(s), 14 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部