登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Design IC

慢即是快,快即是慢

 
 
 

日志

 
 

uvm_tlm_fifo的实现简单模型  

2011-03-09 15:39:05|  分类: SystemVerilog |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

对于put_port/put_export; get_port/get_export的模型前面都有介绍,对于这样的直接连接,函数调用的initiator直接指向最终target,不耗费Delta时间。而UVM_TLM_FIFO的引入,提供了内部的put/get的实现同步机制,让消费者和生产者都可以通过port直接调用。不过,带来的效果是,get/put的同步是在tlm_fifo内部的进程进行实现的,通过mailbox的同步来完成,所以会消耗Delta时间。

一个简化的uvm_tlm_fifo实现程序,便于理解tlm_fifo背后的机制。

源代码如下:


  1 /**

  2  ** tlm_fifo.sv

  3  ** 说明: 通过简单的模型来阐述 UVM/OVMTLM uvm_tlm_fifo

  4  **       的基本原理。直接编译运行即可。

  5  ** 作者:http://electron64.blog.163.com

  6  */

  7 virtual class port_base#(type T=int) ; // 构造一个抽象类

  8   typedef port_base#(T) this_type;

  9   protected this_type port_handle; // 申明一个对象句柄(指针)

 10

 11   virtual task get_t(output T trans);

 12   endtask  // 虚函数,get_portget_imp都必须以它为基类

 13   virtual task put_t(T trans); // 虚函数,put_portput_imp都必须以它为基类

 14   endtask

 15   function void connect(this_type port); // connect仅仅是实现对象句柄的赋值

 16     port_handle = port;

 17   endfunction // connect

 18

 19 endclass // port_base

 20

 21 class get_port#(type T=int) extends port_base#(T);

 22   virtual task get_t(output T trans);

 23     port_handle.get_t(trans);

 24   endtask // get_t

 25 endclass // get_port

 26

 27 class get_imp#(type T=int, type IMP=int) extends port_base#(T);

 28   local IMP m_imp;  // imp表示具体实现get_t()函数的对象句柄。

 29   function new(IMP imp);

 30     m_imp = imp;

 31   endfunction // new

 32

 33   virtual task get_t(output T trans);

 34     m_imp.get_t(trans);  // 调用实现对象对应的get_t()函数

 35   endtask // get_t

 36

 37 endclass // get_imp

 38

 39 class put_port#(type T=int) extends port_base#(T);

 40   virtual task put_t(T trans);

 41     port_handle.put_t(trans);

 42   endtask // put_t

 43 endclass // put_port

 44

 45 class put_imp#(type T=int, type IMP=int) extends port_base#(T);

 46   local IMP m_imp;  // imp表示具体实现put_t()函数的对象句柄。

 47   function new(IMP imp);

 48     m_imp = imp;

 49   endfunction // new

 50

 51   virtual task put_t(T trans);

 52     m_imp.put_t(trans);  // 调用实现对象对应的put_t()函数

 53   endtask // put_t

 54

 55 endclass // put_imp

 56

 57 class tlm_fifo#(type T=int);

 58   typedef tlm_fifo#(T) this_type;

 59   put_imp#(T,this_type) put_export;

 60   get_imp#(T,this_type) get_export;

 61

 62   local mailbox #(T) m;

 63

 64   function new();

 65     m = new(1);

 66     put_export = new(this);

 67     get_export = new(this);

 68   endfunction // new

 69

 70   virtual task put_t(T trans);

 71     m.put(trans);

 72 `ifdef VERBOSE

 73     $display("[tlm_fifo.put_t]: Generate transaction:%d", trans);

 74 `endif

 75   endtask // put_t

 76

 77   virtual task get_t(output T trans);

 78     m.get(trans);

 79 `ifdef VERBOSE

 80     $display("[tlm_fifo.get_t]: Get transaction:%d", trans);

 81 `endif

 82  endtask // get_t

 83

 84 endclass // tlm_fifo

 85

 86

 87 class producer;

 88   put_port#(int) m_put_port;

 89   function new();

 90     m_put_port = new();

 91   endfunction // new

 92

 93   task run(int num=10);

 94     int trans;

 95     for(int i=0; i<num; i++) begin  // 顺序产生10int类型的transaction.

 96       trans = $random;

 97       #5 m_put_port.put_t(trans);

 98       $display("@%0t [Producer]: Generate transaction:<%0d>", $time, trans);

 99     end

100   endtask // run

101 endclass // producer

102

103 class consumer;

104   get_port#(int)  m_get_port;

105   function new();

106     m_get_port = new();

107   endfunction // new

108

109   task run(int num=10);

110     int t;

111     t = -1;

112     for(int i=0; i<num; i++) begin  // 顺序产生10int类型的transaction.

113       #i  m_get_port.get_t(t);

114       $display("@%0t [Consumer]: Get transaction:@{%0d}@", $time, t);

115     end

116   endtask // run

117 endclass // consumer

118

119 module top;

120   producer p;

121   consumer c;

122   tlm_fifo f;

123   initial begin

124     p = new();

125     c = new();

126     f =  new();

127     c.m_get_port.connect(f.get_export);  //通过句柄赋值进行连接

128     p.m_put_port.connect(f.put_export);

129     fork

130       c.run();

131       p.run();

132     join

133     #10 $finish;

134   end

135 endmodule

136


在tlm_fifo中,运行了两个进程,这两个进程通过mailbox进行同步。他们分别对应了get_t()和put_t()。 可以通过`define VERBOSE看tlm_fifo中函数调用状况。

将VERBOSE定义之后运行结果如下:


# [tlm_fifo.put_t]: Generate transaction:  303379748
# @5 [Producer]: Generate transaction:<303379748>
# [tlm_fifo.get_t]: Get transaction:  303379748
# @5 [Consumer]: Get transaction:@{303379748}@
# [tlm_fifo.put_t]: Generate transaction:-1064739199
# @10 [Producer]: Generate transaction:<-1064739199>
# [tlm_fifo.get_t]: Get transaction:-1064739199
# @10 [Consumer]: Get transaction:@{-1064739199}@
# [tlm_fifo.put_t]: Generate transaction:-2071669239
# @15 [Producer]: Generate transaction:<-2071669239>
# [tlm_fifo.get_t]: Get transaction:-2071669239
# @15 [Consumer]: Get transaction:@{-2071669239}@
# [tlm_fifo.put_t]: Generate transaction:-1309649309
# @20 [Producer]: Generate transaction:<-1309649309>
# [tlm_fifo.get_t]: Get transaction:-1309649309
# @20 [Consumer]: Get transaction:@{-1309649309}@
# [tlm_fifo.put_t]: Generate transaction:  112818957
# @25 [Producer]: Generate transaction:<112818957>
# [tlm_fifo.get_t]: Get transaction:  112818957
# @25 [Consumer]: Get transaction:@{112818957}@
# [tlm_fifo.put_t]: Generate transaction: 1189058957
# @30 [Producer]: Generate transaction:<1189058957>
# [tlm_fifo.get_t]: Get transaction: 1189058957
# @30 [Consumer]: Get transaction:@{1189058957}@
# [tlm_fifo.put_t]: Generate transaction:-1295874971
# @35 [Producer]: Generate transaction:<-1295874971>
# [tlm_fifo.get_t]: Get transaction:-1295874971
# @36 [Consumer]: Get transaction:@{-1295874971}@
# [tlm_fifo.put_t]: Generate transaction:-1992863214
# @40 [Producer]: Generate transaction:<-1992863214>
# [tlm_fifo.get_t]: Get transaction:-1992863214
# @43 [Consumer]: Get transaction:@{-1992863214}@
# [tlm_fifo.put_t]: Generate transaction:   15983361
# @45 [Producer]: Generate transaction:<15983361>
# [tlm_fifo.get_t]: Get transaction:   15983361
# @51 [Consumer]: Get transaction:@{15983361}@
# [tlm_fifo.put_t]: Generate transaction:  114806029
# @51 [Producer]: Generate transaction:<114806029>
# [tlm_fifo.get_t]: Get transaction:  114806029
# @60 [Consumer]: Get transaction:@{114806029}@
# ** Note: $finish    : tlm_fifo.sv(133)
#    Time: 70 ns  Iteration: 0  Instance: /top


  评论这张
 
阅读(3295)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018