00001 // $Id: tlm__fifos_8svh-source.html,v 1.1 2008/10/07 21:54:28 alex.marin Exp $ 00002 //---------------------------------------------------------------------- 00003 // Copyright 2007-2008 Mentor Graphics Corporation 00004 // Copyright 2007-2008 Cadence Design Systems, Inc. 00005 // All Rights Reserved Worldwide 00006 // 00007 // Licensed under the Apache License, Version 2.0 (the 00008 // "License"); you may not use this file except in 00009 // compliance with the License. You may obtain a copy of 00010 // the License at 00011 // 00012 // http://www.apache.org/licenses/LICENSE-2.0 00013 // 00014 // Unless required by applicable law or agreed to in 00015 // writing, software distributed under the License is 00016 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 00017 // CONDITIONS OF ANY KIND, either express or implied. See 00018 // the License for the specific language governing 00019 // permissions and limitations under the License. 00020 //---------------------------------------------------------------------- 00021 00022 typedef class tlm_event; 00023 00024 //---------------------------------------------------------------------- 00025 // CLASS tlm_fifo 00026 //---------------------------------------------------------------------- 00027 class tlm_fifo #(type T = int) extends tlm_fifo_base #(T); 00028 00029 //-------------------------------------------------------------------- 00030 // local data 00031 //-------------------------------------------------------------------- 00032 local mailbox #( T ) m; 00033 local int m_size; 00034 protected int m_pending_blocked_gets; 00035 //-------------------------------------------------------------------- 00036 // constructor (new) 00037 //-------------------------------------------------------------------- 00038 function new(string name, ovm_component parent = null, int size = 1); 00039 super.new(name, parent); 00040 00041 m = new( size ); 00042 m_size = size; 00043 endfunction 00044 00045 function int size(); 00046 return m_size; 00047 endfunction 00048 00049 virtual function int used(); 00050 return m.num(); 00051 endfunction 00052 00053 function bit is_empty(); 00054 return (m.num() == 0); 00055 endfunction 00056 00057 function bit is_full(); 00058 return (m.num() == m_size); 00059 endfunction 00060 00061 task put( input T t ); 00062 m.put( t ); 00063 put_ap.write( t ); 00064 endtask 00065 00066 `ifdef INCA 00067 local T m_get_data; 00068 local semaphore m_get_sem = new(1); 00069 00070 task get( output T t ); 00071 m_pending_blocked_gets++; 00072 m_get_sem.get(); 00073 m.get( m_get_data ); 00074 t = m_get_data; 00075 m_pending_blocked_gets--; 00076 m_get_sem.put(); 00077 get_ap.write( t ); 00078 endtask 00079 00080 task peek( output T t ); 00081 m_get_sem.get(); 00082 m.peek( m_get_data ); 00083 t = m_get_data; 00084 m_get_sem.put(); 00085 00086 get_ap.write( t ); 00087 endtask 00088 00089 function bit try_get( output T t ); 00090 if( !m.try_get( m_get_data ) ) begin 00091 return 0; 00092 end 00093 00094 t = m_get_data; 00095 get_ap.write( t ); 00096 return 1; 00097 endfunction 00098 00099 function bit try_peek( output T t ); 00100 if( !m.try_peek( m_get_data ) ) begin 00101 return 0; 00102 end 00103 00104 t = m_get_data; 00105 get_ap.write( t ); 00106 return 1; 00107 endfunction 00108 00109 `else //Standard implementation 00110 00111 task get( output T t ); 00112 m_pending_blocked_gets++; 00113 m.get( t ); 00114 m_pending_blocked_gets--; 00115 get_ap.write( t ); 00116 endtask 00117 00118 task peek( output T t ); 00119 m.peek( t ); 00120 00121 get_ap.write( t ); 00122 endtask 00123 00124 function bit try_get( output T t ); 00125 if( !m.try_get( t ) ) begin 00126 return 0; 00127 end 00128 00129 get_ap.write( t ); 00130 return 1; 00131 endfunction 00132 00133 function bit try_peek( output T t ); 00134 if( !m.try_peek( t ) ) begin 00135 return 0; 00136 end 00137 00138 get_ap.write( t ); 00139 return 1; 00140 endfunction 00141 00142 `endif //IUS Workaround 00143 00144 function bit try_put( input T t ); 00145 if( !m.try_put( t ) ) begin 00146 return 0; 00147 end 00148 00149 put_ap.write( t ); 00150 return 1; 00151 endfunction 00152 00153 function bit can_put(); 00154 return m_size == 0 || m.num() < m_size; 00155 endfunction 00156 00157 function bit can_get(); 00158 return m.num() > 0 && m_pending_blocked_gets == 0; 00159 endfunction 00160 00161 function bit can_peek(); 00162 return m.num() > 0; 00163 endfunction 00164 00165 function void flush(); 00166 T t; 00167 bit r; 00168 00169 r = 1; 00170 while( r ) r = try_get( t ) ; 00171 00172 if( m.num() > 0 && m_pending_blocked_gets != 0 ) begin 00173 ovm_report_error("flush failed" , 00174 "there are blocked gets preventing the flush"); 00175 end 00176 00177 endfunction 00178 00179 endclass 00180 00181 //---------------------------------------------------------------------- 00182 // CLASS tlm_analysis_fifo 00183 //---------------------------------------------------------------------- 00184 00185 // An tlm_analysis_fifo is an unbounded tlm_fifo that also implements and 00186 // exports the write interfaces. 00187 // 00188 // It is very useful in objects such as scoreboards which need to be 00189 // connected to monitors. 00190 00191 class tlm_analysis_fifo #(type T = int) extends tlm_fifo #(T); 00192 00193 ovm_analysis_imp #(T, tlm_analysis_fifo #(T)) analysis_export; 00194 00195 function new(string name , ovm_component parent = null); 00196 super.new(name, parent, 0); // analysis fifo must be unbounded 00197 00198 analysis_export = new("analysis_export", this); 00199 00200 endfunction 00201 00202 function void write(input T t); 00203 void'(this.try_put(t)); // unbounded => must succeed 00204 endfunction 00205 00206 endclass
![]() Intelligent Design Verification Project: OVM, Revision: 1.1.0 |
Copyright (c) 2008 Intelligent Design Verification. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included here: http://www.intelligentdv.com/licenses/fdl.txt |
![]() Doxygen Version: 1.4.6 Mon Sep 29 14:20:12 2008 |