00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2006 by all Contributors. 00005 All Rights reserved. 00006 00007 The contents of this file are subject to the restrictions and limitations 00008 set forth in the SystemC Open Source License Version 2.4 (the "License"); 00009 You may not use this file except in compliance with such restrictions and 00010 limitations. You may obtain instructions on how to receive a copy of the 00011 License at http://www.systemc.org/. Software distributed by Contributors 00012 under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 00013 ANY KIND, either express or implied. See the License for the specific 00014 language governing rights and limitations under the License. 00015 00016 *****************************************************************************/ 00017 00018 /***************************************************************************** 00019 00020 sc_prim_channel.cpp -- Abstract base class of all primitive channel 00021 classes. 00022 00023 Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21 00024 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 00029 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 00030 changes you are making here. 00031 00032 Name, Affiliation, Date: Andy Goodrich, Forte, 00033 Bishnupriya Bhattacharya, Cadence Design Systems, 00034 25 August, 2003 00035 00036 Description of Modification: phase callbacks 00037 00038 *****************************************************************************/ 00039 00040 00041 // $Log: sc_prim_channel.cpp,v $ 00042 // Revision 1.1.1.1 2006/12/15 20:31:35 acg 00043 // SystemC 2.2 00044 // 00045 // Revision 1.4 2006/01/26 21:00:50 acg 00046 // Andy Goodrich: conversion to use sc_event::notify(SC_ZERO_TIME) instead of 00047 // sc_event::notify_delayed() 00048 // 00049 // Revision 1.3 2006/01/13 18:47:42 acg 00050 // Added $Log command so that CVS comments are reproduced in the source. 00051 // 00052 00053 #include "sysc/communication/sc_prim_channel.h" 00054 #include "sysc/communication/sc_communication_ids.h" 00055 #include "sysc/kernel/sc_simcontext.h" 00056 00057 namespace sc_core { 00058 00059 // ---------------------------------------------------------------------------- 00060 // CLASS : sc_prim_channel 00061 // 00062 // Abstract base class of all primitive channel classes. 00063 // ---------------------------------------------------------------------------- 00064 00065 // constructors 00066 00067 sc_prim_channel::sc_prim_channel() 00068 : sc_object( 0 ), 00069 m_registry( simcontext()->get_prim_channel_registry() ), 00070 m_update_next_p( 0 ) 00071 { 00072 m_registry->insert( *this ); 00073 } 00074 00075 sc_prim_channel::sc_prim_channel( const char* name_ ) 00076 : sc_object( name_ ), 00077 m_registry( simcontext()->get_prim_channel_registry() ), 00078 m_update_next_p( 0 ) 00079 { 00080 m_registry->insert( *this ); 00081 } 00082 00083 00084 // destructor 00085 00086 sc_prim_channel::~sc_prim_channel() 00087 { 00088 m_registry->remove( *this ); 00089 } 00090 00091 00092 // the update method (does nothing by default) 00093 00094 void 00095 sc_prim_channel::update() 00096 {} 00097 00098 00099 // called by construction_done (does nothing by default) 00100 00101 void sc_prim_channel::before_end_of_elaboration() 00102 {} 00103 00104 // called when construction is done 00105 00106 void 00107 sc_prim_channel::construction_done() 00108 { 00109 before_end_of_elaboration(); 00110 } 00111 00112 // called by elaboration_done (does nothing by default) 00113 00114 void 00115 sc_prim_channel::end_of_elaboration() 00116 {} 00117 00118 00119 // called when elaboration is done 00120 00121 void 00122 sc_prim_channel::elaboration_done() 00123 { 00124 end_of_elaboration(); 00125 } 00126 00127 // called by start_simulation (does nothing) 00128 00129 void 00130 sc_prim_channel::start_of_simulation() 00131 {} 00132 00133 // called before simulation begins 00134 00135 void 00136 sc_prim_channel::start_simulation() 00137 { 00138 start_of_simulation(); 00139 } 00140 00141 // called by simulation_done (does nothing) 00142 00143 void 00144 sc_prim_channel::end_of_simulation() 00145 {} 00146 00147 // called after simulation ends 00148 00149 void 00150 sc_prim_channel::simulation_done() 00151 { 00152 end_of_simulation(); 00153 } 00154 00155 // ---------------------------------------------------------------------------- 00156 // CLASS : sc_prim_channel_registry 00157 // 00158 // Registry for all primitive channels. 00159 // FOR INTERNAL USE ONLY! 00160 // ---------------------------------------------------------------------------- 00161 00162 void 00163 sc_prim_channel_registry::insert( sc_prim_channel& prim_channel_ ) 00164 { 00165 if( sc_is_running() ) { 00166 SC_REPORT_ERROR( SC_ID_INSERT_PRIM_CHANNEL_, "simulation running" ); 00167 } 00168 00169 #ifdef DEBUG_SYSTEMC 00170 // check if prim_channel_ is already inserted 00171 for( int i = 0; i < size(); ++ i ) { 00172 if( &prim_channel_ == m_prim_channel_vec[i] ) { 00173 SC_REPORT_ERROR( SC_ID_INSERT_PRIM_CHANNEL_, "already inserted" ); 00174 } 00175 } 00176 #endif 00177 00178 // insert 00179 m_prim_channel_vec.push_back( &prim_channel_ ); 00180 00181 } 00182 00183 void 00184 sc_prim_channel_registry::remove( sc_prim_channel& prim_channel_ ) 00185 { 00186 int i; 00187 for( i = 0; i < size(); ++ i ) { 00188 if( &prim_channel_ == m_prim_channel_vec[i] ) { 00189 break; 00190 } 00191 } 00192 if( i == size() ) { 00193 SC_REPORT_ERROR( SC_ID_REMOVE_PRIM_CHANNEL_, 0 ); 00194 } 00195 00196 // remove 00197 m_prim_channel_vec[i] = m_prim_channel_vec[size() - 1]; 00198 m_prim_channel_vec.resize(size()-1); 00199 } 00200 00201 00202 // constructor 00203 00204 sc_prim_channel_registry::sc_prim_channel_registry( sc_simcontext& simc_ ) 00205 : m_simc( &simc_ ), m_update_list_p((sc_prim_channel*)sc_prim_channel::list_end) 00206 { 00207 } 00208 00209 00210 // destructor 00211 00212 sc_prim_channel_registry::~sc_prim_channel_registry() 00213 { 00214 } 00215 00216 // called when construction is done 00217 00218 void 00219 sc_prim_channel_registry::construction_done() 00220 { 00221 for( int i = 0; i < size(); ++ i ) { 00222 m_prim_channel_vec[i]->construction_done(); 00223 } 00224 } 00225 00226 00227 // called when elaboration is done 00228 00229 void 00230 sc_prim_channel_registry::elaboration_done() 00231 { 00232 for( int i = 0; i < size(); ++ i ) { 00233 m_prim_channel_vec[i]->elaboration_done(); 00234 } 00235 } 00236 00237 // called before simulation begins 00238 00239 void 00240 sc_prim_channel_registry::start_simulation() 00241 { 00242 for( int i = 0; i < size(); ++ i ) { 00243 m_prim_channel_vec[i]->start_simulation(); 00244 } 00245 } 00246 00247 // called after simulation ends 00248 00249 void 00250 sc_prim_channel_registry::simulation_done() 00251 { 00252 for( int i = 0; i < size(); ++ i ) { 00253 m_prim_channel_vec[i]->simulation_done(); 00254 } 00255 } 00256 00257 } // namespace sc_core 00258 00259 // Taf!