uvm通信-uvm_put_port/uvm_get_port/uvm_tlm_fifo使用示例(完整uvm环境)

资料来源

(1) 《The UVM Primer》第17章

1.uvm_put/get_port与uvm_tlm_fifo使用示例(blocking)

 1.1 top.sv

1 module top;
2    import uvm_pkg::*;
3 `include "uvm_macros.svh"
4 
5    import example_pkg::*;
6 
7    initial run_test("communication_test");
8 endmodule : top

1.2 example_pkg.sv

1 package example_pkg;
2    import uvm_pkg::*;
3 `include "uvm_macros.svh"
4 
5 
6 `include "producer.svh"
7 `include "consumer.svh"
8 `include "communication_test.svh"
9 endpackage : example_pkg

1.3 communication_test.svh

 1 class communication_test extends uvm_test;
 2    `uvm_component_utils(communication_test)
 3    
 4    producer producer_h;
 5    consumer consumer_h;
 6    uvm_tlm_fifo #(int) fifo_h;
 7 
 8    function new(string name, uvm_component parent);
 9       super.new(name, parent);
10    endfunction : new
11 
12    function void build_phase(uvm_phase phase);
13       producer_h = new("producer_h", this);
14       consumer_h = new("consumer_h", this);
15       fifo_h = new("fifo_h",this);
16    endfunction : build_phase
17 
18    function void connect_phase(uvm_phase phase);
19       producer_h.put_port_h.connect(fifo_h.put_export);
20       consumer_h.get_port_h.connect(fifo_h.get_export);
21    endfunction : connect_phase
22 
23 endclass : communication_test

1.4 producer.svh

 1 class producer extends uvm_component;
 2    `uvm_component_utils(producer);
 3 
 4    int shared;
 5    uvm_put_port #(int) put_port_h;
 6 
 7    function void build_phase(uvm_phase phase);
 8       put_port_h = new("put_port_h", this);
 9    endfunction : build_phase
10    
11    
12    function new(string name, uvm_component parent);
13       super.new(name, parent);
14    endfunction : new
15    
16    
17    task run_phase(uvm_phase phase);
18       phase.raise_objection(this);
19       repeat (3) begin
20          put_port_h.put(++shared);
21          $display("Sent %0d", shared);
22       end
23       phase.drop_objection(this);
24    endtask : run_phase
25 endclass : producer

1.5 consumer.svh

 1 class consumer extends uvm_component;
 2    `uvm_component_utils(consumer);
 3 
 4    uvm_get_port #(int) get_port_h;
 5    int shared;
 6 
 7    function void build_phase(uvm_phase phase);
 8       get_port_h = new("get_port_h", this);
 9    endfunction : build_phase
10 
11 
12    function new(string name, uvm_component parent);
13       super.new(name, parent);
14    endfunction : new
15 
16    task run_phase(uvm_phase phase);
17       forever begin
18          get_port_h.get(shared);
19          $display("Received: %0d", shared);
20       end
21    endtask : run_phase
22 endclass : consumer

2.uvm_put/get_port与uvm_tlm_fifo使用示例(nonblocking)

2.1 top.sv

 1 interface clk_bfm;
 2    bit clk;
 3    initial clk = 0;
 4    always #7 clk = ~clk;
 5 endinterface : clk_bfm
 6 
 7 
 8 module top;
 9    import uvm_pkg::*;
10 `include "uvm_macros.svh"
11 
12    import example_pkg::*;
13 
14    clk_bfm clk_bfm_i();
15 
16    initial begin
17       example_pkg::clk_bfm_i = clk_bfm_i;
18       run_test("communication_test");
19    end
20 
21 endmodule : top

2.example_pkg.sv

 1 package example_pkg;
 2    import uvm_pkg::*;
 3 `include "uvm_macros.svh"
 4 
 5    virtual clk_bfm clk_bfm_i;
 6 
 7 `include "producer.svh"
 8 `include "consumer.svh"
 9 `include "communication_test.svh"
10 endpackage : example_pkg

3.communication_test.svh

 1 class communication_test extends uvm_test;
 2    `uvm_component_utils(communication_test)
 3    
 4    producer producer_h;
 5    consumer consumer_h;
 6    uvm_tlm_fifo #(int) fifo_h;
 7 
 8    function void build_phase(uvm_phase phase);
 9       producer_h = new("producer_h", this);
10       consumer_h = new("consumer_h", this);
11       fifo_h = new("fifo_h",this);
12    endfunction : build_phase
13 
14    function new(string name, uvm_component parent);
15       super.new(name, parent);
16    endfunction : new
17 
18    function void connect_phase(uvm_phase phase);
19       producer_h.put_port_h.connect(fifo_h.put_export);
20       consumer_h.get_port_h.connect(fifo_h.get_export);
21 
22    endfunction : connect_phase
23 endclass : communication_test

4.producer.svh

 1 class producer extends uvm_component;
 2    `uvm_component_utils(producer);
 3 
 4    int shared;
 5    uvm_put_port #(int) put_port_h;
 6 
 7    function void build_phase(uvm_phase phase);
 8       
 9       put_port_h = new("put_port_h", this);
10    endfunction : build_phase
11    
12    task run_phase(uvm_phase phase);
13       phase.raise_objection(this);
14       repeat (3) begin
15          #17;
16          put_port_h.put(++shared);
17          $display("%0tns  Sent %0d", $time, shared);
18       end
19       #17;
20       phase.drop_objection(this);
21    endtask : run_phase
22 
23    function new(string name, uvm_component parent);
24       super.new(name, parent);
25    endfunction : new
26 
27 endclass : producer

5.consumer.svh

 1 class consumer extends uvm_component;
 2    `uvm_component_utils(consumer);
 3 
 4    uvm_get_port #(int) get_port_h;
 5    virtual clk_bfm clk_bfm_i;
 6    int shared;
 7 
 8    function void build_phase(uvm_phase phase);
 9       
10       get_port_h = new("get_port_h", this);
11       clk_bfm_i = example_pkg::clk_bfm_i;
12    endfunction : build_phase
13 
14    task run_phase(uvm_phase phase);
15       forever begin
16          @(posedge clk_bfm_i.clk);
17          if(get_port_h.try_get(shared))
18            $display("%0tns  Received: %0d", $time,shared);
19       end
20    endtask : run_phase
21 
22 
23    function new(string name, uvm_component parent);
24       super.new(name, parent);
25    endfunction : new
26 
27 endclass : consumer

 

posted on 2022-04-14 16:22  知北游。。  阅读(603)  评论(0编辑  收藏  举报

导航