2011年5月25日 星期三

uvm_blocking_put_port/uvm_blocking_put_imp实现的简单模型

這是一個轉貼的資料
原始網址:http://electron64.blog.163.com/blog/static/10603397020110136442862/

這個例子說明了UVM原始的架構
因此這個例子並未使用UVM library

1 /**
 2  * * tlm.sv 
 3  * * 说明: 通过简单的模型来阐述 UVM/OVMTLM uvm_put_port
 4  * *        uvm_port_imp直接连接的基本原理。直接编译运行即可。
 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   pure virtual task put_t(T trans); // 纯虚函数,put_portput_imp都必须以它为基类
12 
13   function void connect(this_type port); // connect仅仅是实现对象句柄的赋值
14     port_handle = port;
15   endfunction // connect
16 
17 endclass // port_base
18 
19 class put_port#(type T=int) extends port_base#(T);
20   virtual task put_t(T trans);
21     port_handle.put_t(trans);
22   endtask // put_t
23 endclass // put_port
24 
25 class put_imp#(type T=int, type IMP=int) extends port_base#(T);
26   local IMP m_imp;  // imp表示具体实现put_t()函数的对象句柄。
27   function new(IMP imp);
28     m_imp = imp;
29   endfunction // new
30 
31   virtual task put_t(T trans);
32     m_imp.put_t(trans);  // 调用实现对象对应的put_t()函数
33   endtask // put_t
34 
35 endclass // put_imp
36 
37 class producer;
38   put_port#(int) m_put_port;
39   function new();
40     m_put_port = new();
41   endfunction // new
42 
43   task run();
44     for(int i=0; i<10; i++) begin  // 顺序产生10int类型的transaction.
45       m_put_port.put_t(i);
46     end
47   endtask // run
48 endclass // producer
49 
50 class consumer;
51   put_imp#(int, consumer)  m_put_export;
52   function new();
53     m_put_export = new(this); //consumer句柄传递给put_impimp变量,从而实现接管put_t()最终实现
54   endfunction // new
55 
56   task put_t(int trans);
57     $display("[INFO]: Got the transaction:%d", trans);
58   endtask // put_t
59 endclass // consumer
60 
61 module top;
62   producer p;
63   consumer c;
64   initial begin
65     p = new();
66     c = new();
67     p.m_put_port.connect(c.m_put_export);  //通过句柄赋值进行连接
68     p.run();
69     #10 $finish;
70   end
71 endmodule

沒有留言: