src/sysc/communication/sc_prim_channel.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2005 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.h -- Abstract base class of all primitive channel classes.
00021 
00022   Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
00023 
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027 
00028   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00029   changes you are making here.
00030 
00031       Name, Affiliation, Date: Andy Goodrich, Forte,
00032                                Bishnupriya Bhattacharya, Cadence Design Systems,
00033                                25 August, 2003
00034   Description of Modification: phase callbacks
00035     
00036  *****************************************************************************/
00037 
00038 #ifndef SC_PRIM_CHANNEL_H
00039 #define SC_PRIM_CHANNEL_H
00040 
00041 #include "sysc/kernel/sc_object.h"
00042 #include "sysc/kernel/sc_wait.h"
00043 #include "sysc/utils/sc_vector.h"
00044 
00045 namespace sc_core {
00046 
00047 // ----------------------------------------------------------------------------
00048 //  CLASS : sc_prim_channel
00049 //
00050 //  Abstract base class of all primitive channel classes.
00051 // ----------------------------------------------------------------------------
00052 
00053 class sc_prim_channel
00054 : public sc_object
00055 {
00056     friend class sc_prim_channel_registry;
00057 
00058 public:
00059     virtual const char* kind() const
00060         { return "sc_prim_channel"; }
00061 
00062     inline bool update_requested() 
00063         { return m_update_requested; }
00064 
00065     // request the update method (to be executed during the update phase)
00066     void request_update();
00067 
00068 
00069 protected:
00070 
00071     // constructors
00072     sc_prim_channel();
00073     explicit sc_prim_channel( const char* );
00074 
00075     // destructor
00076     virtual ~sc_prim_channel();
00077 
00078     // the update method (does nothing by default)
00079     virtual void update();
00080 
00081     // called by construction_done (does nothing by default)
00082     virtual void before_end_of_elaboration();
00083 
00084     // called by elaboration_done (does nothing by default)
00085     virtual void end_of_elaboration();
00086 
00087     // called by start_simulation (does nothing by default)
00088     virtual void start_of_simulation();
00089 
00090     // called by simulation_done (does nothing by default)
00091     virtual void end_of_simulation();
00092 
00093 protected:
00094 
00095     // to avoid calling sc_get_curr_simcontext()
00096 
00097 
00098     // static sensitivity for SC_THREADs and SC_CTHREADs
00099 
00100     void wait()
00101         { sc_core::wait( simcontext() ); }
00102 
00103 
00104     // dynamic sensitivity for SC_THREADs and SC_CTHREADs
00105 
00106     void wait( const sc_event& e )
00107         { sc_core::wait( e, simcontext() ); }
00108 
00109     void wait( sc_event_or_list& el )
00110         { sc_core::wait( el, simcontext() ); }
00111 
00112     void wait( sc_event_and_list& el )
00113         { sc_core::wait( el, simcontext() ); }
00114 
00115     void wait( const sc_time& t )
00116         { sc_core::wait( t, simcontext() ); }
00117 
00118     void wait( double v, sc_time_unit tu )
00119         { sc_core::wait( sc_time( v, tu, simcontext() ), simcontext() ); }
00120 
00121     void wait( const sc_time& t, const sc_event& e )
00122         { sc_core::wait( t, e, simcontext() ); }
00123 
00124     void wait( double v, sc_time_unit tu, const sc_event& e )
00125         { sc_core::wait( sc_time( v, tu, simcontext() ), e, simcontext() ); }
00126 
00127     void wait( const sc_time& t, sc_event_or_list& el )
00128         { sc_core::wait( t, el, simcontext() ); }
00129 
00130     void wait( double v, sc_time_unit tu, sc_event_or_list& el )
00131         { sc_core::wait( sc_time( v, tu, simcontext() ), el, simcontext() ); }
00132 
00133     void wait( const sc_time& t, sc_event_and_list& el )
00134         { sc_core::wait( t, el, simcontext() ); }
00135 
00136     void wait( double v, sc_time_unit tu, sc_event_and_list& el )
00137         { sc_core::wait( sc_time( v, tu, simcontext() ), el, simcontext() ); }
00138 
00139 
00140     // static sensitivity for SC_METHODs
00141 
00142     void next_trigger()
00143         { sc_core::next_trigger( simcontext() ); }
00144 
00145 
00146     // dynamic sensitivity for SC_METHODs
00147 
00148     void next_trigger( const sc_event& e )
00149         { sc_core::next_trigger( e, simcontext() ); }
00150 
00151     void next_trigger( sc_event_or_list& el )
00152         { sc_core::next_trigger( el, simcontext() ); }
00153 
00154     void next_trigger( sc_event_and_list& el )
00155         { sc_core::next_trigger( el, simcontext() ); }
00156 
00157     void next_trigger( const sc_time& t )
00158         { sc_core::next_trigger( t, simcontext() ); }
00159 
00160     void next_trigger( double v, sc_time_unit tu )
00161         {sc_core::next_trigger( sc_time( v, tu, simcontext() ), simcontext() );}
00162 
00163     void next_trigger( const sc_time& t, const sc_event& e )
00164         { sc_core::next_trigger( t, e, simcontext() ); }
00165 
00166     void next_trigger( double v, sc_time_unit tu, const sc_event& e )
00167         { sc_core::next_trigger( 
00168             sc_time( v, tu, simcontext() ), e, simcontext() ); }
00169 
00170     void next_trigger( const sc_time& t, sc_event_or_list& el )
00171         { sc_core::next_trigger( t, el, simcontext() ); }
00172 
00173     void next_trigger( double v, sc_time_unit tu, sc_event_or_list& el )
00174         { sc_core::next_trigger( 
00175             sc_time( v, tu, simcontext() ), el, simcontext() ); }
00176 
00177     void next_trigger( const sc_time& t, sc_event_and_list& el )
00178         { sc_core::next_trigger( t, el, simcontext() ); }
00179 
00180     void next_trigger( double v, sc_time_unit tu, sc_event_and_list& el )
00181         { sc_core::next_trigger( 
00182             sc_time( v, tu, simcontext() ), el, simcontext() ); }
00183 
00184 
00185     // for SC_METHODs and SC_THREADs and SC_CTHREADs
00186 
00187     bool timed_out()
00188         { return sc_core::timed_out( simcontext() ); }
00189 
00190 private:
00191 
00192     // called during the update phase of a delta cycle (if requested)
00193     void perform_update();
00194 
00195     // called when construction is done
00196     void construction_done();
00197 
00198     // called when elaboration is done
00199     void elaboration_done();
00200 
00201     // called before simulation starts
00202     void start_simulation();
00203 
00204     // called after simulation ends
00205     void simulation_done();
00206 
00207     // disabled
00208     sc_prim_channel( const sc_prim_channel& );
00209     sc_prim_channel& operator = ( const sc_prim_channel& );
00210 
00211 private:
00212 
00213     sc_prim_channel_registry* m_registry;
00214 
00215     bool m_update_requested;
00216 };
00217 
00218 
00219 // ----------------------------------------------------------------------------
00220 //  CLASS : sc_prim_channel_registry
00221 //
00222 //  Registry for all primitive channels.
00223 //  FOR INTERNAL USE ONLY!
00224 // ----------------------------------------------------------------------------
00225 
00226 class sc_prim_channel_registry
00227 {
00228     friend class sc_simcontext;
00229 
00230 public:
00231 
00232     void insert( sc_prim_channel& );
00233     void remove( sc_prim_channel& );
00234 
00235     int size() const
00236         { return m_prim_channel_vec.size(); }
00237 
00238     void request_update( sc_prim_channel& );
00239 
00240 private:
00241 
00242     // constructor
00243     explicit sc_prim_channel_registry( sc_simcontext& simc_ );
00244 
00245     // destructor
00246     ~sc_prim_channel_registry();
00247 
00248     // called during the update phase of a delta cycle
00249     void perform_update();
00250 
00251     // called when construction is done
00252     void construction_done();
00253 
00254     // called when elaboration is done
00255     void elaboration_done();
00256 
00257     // called before simulation starts
00258     void start_simulation();
00259 
00260     // called after simulation ends
00261     void simulation_done();
00262 
00263     // disabled
00264     sc_prim_channel_registry();
00265     sc_prim_channel_registry( const sc_prim_channel_registry& );
00266     sc_prim_channel_registry& operator = ( const sc_prim_channel_registry& );
00267 
00268 private:
00269 
00270     sc_simcontext*               m_simc;
00271     sc_pvector<sc_prim_channel*> m_prim_channel_vec;
00272 
00273     sc_prim_channel** m_update_array;
00274     int               m_update_size;
00275     int               m_update_last;
00276 };
00277 
00278 
00279 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00280 
00281 // ----------------------------------------------------------------------------
00282 //  CLASS : sc_prim_channel
00283 //
00284 //  Abstract base class of all primitive channel classes.
00285 // ----------------------------------------------------------------------------
00286 
00287 // request the update method (to be executed during the update phase)
00288 
00289 inline
00290 void
00291 sc_prim_channel::request_update()
00292 {
00293     if( ! m_update_requested ) {
00294         m_registry->request_update( *this );
00295         m_update_requested = true;
00296     }
00297 }
00298 
00299 
00300 // called during the update phase of a delta cycle (if requested)
00301 
00302 inline
00303 void
00304 sc_prim_channel::perform_update()
00305 {
00306     update();
00307     m_update_requested = false;
00308 }
00309 
00310 
00311 // ----------------------------------------------------------------------------
00312 //  CLASS : sc_prim_channel_registry
00313 //
00314 //  Registry for all primitive channels.
00315 //  FOR INTERNAL USE ONLY!
00316 // ----------------------------------------------------------------------------
00317 
00318 inline
00319 void
00320 sc_prim_channel_registry::request_update( sc_prim_channel& prim_channel_ )
00321 {
00322     m_update_array[++ m_update_last] = &prim_channel_;
00323 }
00324 
00325 
00326 // called during the update phase of a delta cycle
00327 
00328 inline
00329 void
00330 sc_prim_channel_registry::perform_update()
00331 {
00332     for( int i = m_update_last; i >= 0; -- i ) {
00333         m_update_array[i]->perform_update();
00334     }
00335     m_update_last = -1;
00336 }
00337 
00338 } // namespace sc_core
00339 
00340 #endif
00341 
00342 // Taf!

Generated on Wed Apr 25 13:53:25 2007 for SystemC by  doxygen 1.5.1