2011年5月28日 星期六

uvm_tlm_fifo使用blocking的另一個例子

這是從http://testbench.in/UT_14_UVM_TLM_2.html
uvm_tlm_4.tar
的例子


`include "uvm.svh"
import uvm_pkg::*;

`include "consumer.sv"
`include "producer.sv"

class env extends uvm_env;
producer p;
consumer c;
uvm_tlm_fifo #(int) f;

function new(string name = "env");
super.new(name);
p = new("producer", this);
c = new("consumer", this);
f = new("fifo", this);
endfunction

function void connect();
p.put_port.connect(f.put_export);
c.get_port.connect(f.get_export);
endfunction

task run();
#1000 global_stop_request();
endtask

endclass


module test;
env e;

initial begin
e = new();
run_test();
end

endmodule

class producer extends uvm_component;

uvm_blocking_put_port#(int) put_port;

function new(string name, uvm_component p = null);
super.new(name,p);
put_port = new("put_port", this);

endfunction

task run;

int randval;

for(int i = 0; i < 10; i++)
begin
#10;
randval = $urandom_range(11,100);
`uvm_info("producer", $sformatf("sending %d",randval), UVM_MEDIUM)
put_port.put(randval);
end
endtask

endclass : producer


class consumer extends uvm_component;

uvm_blocking_get_port#(int) get_port;

function new(string name, uvm_component p = null);
super.new(name,p);
get_port = new("get_port", this);
endfunction

task run;

int val;

forever
begin
get_port.get(val);
`uvm_info("consumer", $sformatf("receiving %d", val), UVM_MEDIUM)
end

endtask

endclass : consumer

沒有留言: