/ovm-2.0.1/examples/tlm/producer_consumer/fifo.sv
SystemVerilog | 144 lines | 67 code | 31 blank | 46 comment | 1 complexity | 3bd229fa9a26dc2438888428294302bb MD5 | raw file
Possible License(s): Apache-2.0
1// $Id: //dvt/vtech/dev/main/ovm/examples/tlm/producer_consumer/fifo.sv#9 $ 2//---------------------------------------------------------------------- 3// Copyright 2007-2008 Mentor Graphics Corporation 4// Copyright 2007-2008 Cadence Design Systems, Inc. 5// All Rights Reserved Worldwide 6// 7// Licensed under the Apache License, Version 2.0 (the 8// "License"); you may not use this file except in 9// compliance with the License. You may obtain a copy of 10// the License at 11// 12// http://www.apache.org/licenses/LICENSE-2.0 13// 14// Unless required by applicable law or agreed to in 15// writing, software distributed under the License is 16// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 17// CONDITIONS OF ANY KIND, either express or implied. See 18// the License for the specific language governing 19// permissions and limitations under the License. 20//---------------------------------------------------------------------- 21 22 23/* 24About: producer_consumer 25 26this test is the basic simple to illustrates how to create a producer and consumer which are completely independent and connecting them using a tlm_fifo channel 27 28 29Walk through the test: 30 31two thrads *producer* and *consumer* will use ovm_blocking_put port and ovm_blocking_get port, to transfer an integer from the producer to the consumer through fifo exports at the connection function of an environment class 32 33 34*/ 35 36 37 38//---------------------------------------------------------------------- 39// module top 40//---------------------------------------------------------------------- 41module test; 42 43`ifdef INCA 44 `include "ovm.svh" 45`else 46 import ovm_pkg::*; 47`endif 48 49 //---------------------------------------------------------------------- 50 // class producer 51 //---------------------------------------------------------------------- 52 class producer extends ovm_component; 53 54 ovm_blocking_put_port#(int) put_port; 55 56 function new(string name, ovm_component p = null); 57 super.new(name,p); 58 put_port = new("put_port", this); 59 60 endfunction 61 62 task run; 63 64 int randval; 65 string s; 66 67 for(int i = 0; i < 10; i++) 68 begin 69 randval = $random % 100; 70 #10; 71 $sformat(s, "sending %4d", randval); 72 ovm_report_info("producer", s); 73 put_port.put(randval); 74 end 75 endtask 76 77 endclass : producer 78 79 //---------------------------------------------------------------------- 80 // class consumer 81 //---------------------------------------------------------------------- 82 class consumer extends ovm_component; 83 84 ovm_blocking_get_port#(int) get_port; 85 86 function new(string name, ovm_component p = null); 87 super.new(name,p); 88 get_port = new("get_port", this); 89 endfunction 90 91 task run; 92 93 int val; 94 string s; 95 96 forever 97 begin 98 get_port.get(val); 99 $sformat(s, "receiving %4d", val); 100 ovm_report_info("consumer", s); 101 end 102 103 endtask 104 105 endclass : consumer 106 107 //---------------------------------------------------------------------- 108 // class env 109 //---------------------------------------------------------------------- 110 class env extends ovm_env; 111 producer p; 112 consumer c; 113 tlm_fifo #(int) f; 114 115 function new(string name = "env"); 116 super.new(name); 117 p = new("producer", this); 118 c = new("consumer", this); 119 f = new("fifo", this); 120 $display("fifo put_export: %s", f.m_name); 121 endfunction 122 123 function void connect(); 124 p.put_port.connect(f.put_export); 125 c.get_port.connect(f.get_export); 126 endfunction 127 128 task run(); 129 #1000 global_stop_request(); 130 endtask 131 132 endclass 133 134 // Main body of module top: 135 env e; 136 137 initial begin 138 e = new(); 139 e.run_test(); 140 //$finish; 141 end 142 143endmodule // test 144