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-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.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 //$Log: sc_prim_channel.h,v $
00038 //Revision 1.1.1.1  2006/12/15 20:31:35  acg
00039 //SystemC 2.2
00040 //
00041 //Revision 1.2  2006/01/03 23:18:26  acg
00042 //Changed copyright to include 2006.
00043 //
00044 //Revision 1.1.1.1  2005/12/19 23:16:43  acg
00045 //First check in of SystemC 2.1 into its own archive.
00046 //
00047 //Revision 1.10  2005/07/30 03:44:11  acg
00048 //Changes from 2.1.
00049 //
00050 //Revision 1.9  2005/06/10 22:43:55  acg
00051 //Added CVS change log annotation.
00052 //
00053 
00054 #ifndef SC_PRIM_CHANNEL_H
00055 #define SC_PRIM_CHANNEL_H
00056 
00057 #include "sysc/kernel/sc_object.h"
00058 #include "sysc/kernel/sc_wait.h"
00059 #include "sysc/kernel/sc_wait_cthread.h"
00060 
00061 namespace sc_core {
00062 
00063 // ----------------------------------------------------------------------------
00064 //  CLASS : sc_prim_channel
00065 //
00066 //  Abstract base class of all primitive channel classes.
00067 // ----------------------------------------------------------------------------
00068 
00069 class sc_prim_channel
00070 : public sc_object
00071 {
00072     friend class sc_prim_channel_registry;
00073 
00074 public:
00075     enum { list_end = 0xdb };
00076 public:
00077     virtual const char* kind() const
00078         { return "sc_prim_channel"; }
00079 
00080     inline bool update_requested() 
00081     { return m_update_next_p != (sc_prim_channel*)list_end; }
00082 
00083     // request the update method to be executed during the update phase
00084     inline void request_update();
00085 
00086 
00087 protected:
00088 
00089     // constructors
00090     sc_prim_channel();
00091     explicit sc_prim_channel( const char* );
00092 
00093     // destructor
00094     virtual ~sc_prim_channel();
00095 
00096     // the update method (does nothing by default)
00097     virtual void update();
00098 
00099     // called by construction_done (does nothing by default)
00100     virtual void before_end_of_elaboration();
00101 
00102     // called by elaboration_done (does nothing by default)
00103     virtual void end_of_elaboration();
00104 
00105     // called by start_simulation (does nothing by default)
00106     virtual void start_of_simulation();
00107 
00108     // called by simulation_done (does nothing by default)
00109     virtual void end_of_simulation();
00110 
00111 protected:
00112 
00113     // to avoid calling sc_get_curr_simcontext()
00114 
00115     // static sensitivity for SC_THREADs and SC_CTHREADs
00116 
00117     void wait()
00118         { sc_core::wait( simcontext() ); }
00119 
00120 
00121     // dynamic sensitivity for SC_THREADs and SC_CTHREADs
00122 
00123     void wait( const sc_event& e )
00124         { sc_core::wait( e, simcontext() ); }
00125 
00126     void wait( sc_event_or_list& el )
00127     { sc_core::wait( el, simcontext() ); }
00128 
00129     void wait( sc_event_and_list& el )
00130     { sc_core::wait( el, simcontext() ); }
00131 
00132     void wait( const sc_time& t )
00133         { sc_core::wait( t, simcontext() ); }
00134 
00135     void wait( double v, sc_time_unit tu )
00136         { sc_core::wait( sc_time( v, tu, simcontext() ), simcontext() ); }
00137 
00138     void wait( const sc_time& t, const sc_event& e )
00139         { sc_core::wait( t, e, simcontext() ); }
00140 
00141     void wait( double v, sc_time_unit tu, const sc_event& e )
00142         { sc_core::wait( sc_time( v, tu, simcontext() ), e, simcontext() ); }
00143 
00144     void wait( const sc_time& t, sc_event_or_list& el )
00145         { sc_core::wait( t, el, simcontext() ); }
00146 
00147     void wait( double v, sc_time_unit tu, sc_event_or_list& el )
00148         { sc_core::wait( sc_time( v, tu, simcontext() ), el, simcontext() ); }
00149 
00150     void wait( const sc_time& t, sc_event_and_list& el )
00151         { sc_core::wait( t, el, simcontext() ); }
00152 
00153     void wait( double v, sc_time_unit tu, sc_event_and_list& el )
00154         { sc_core::wait( sc_time( v, tu, simcontext() ), el, simcontext() ); }
00155 
00156     void wait( int n )
00157         { sc_core::wait( n, simcontext() ); }
00158 
00159 
00160     // static sensitivity for SC_METHODs
00161 
00162     void next_trigger()
00163     { sc_core::next_trigger( simcontext() ); }
00164 
00165 
00166     // dynamic sensitivity for SC_METHODs
00167 
00168     void next_trigger( const sc_event& e )
00169         { sc_core::next_trigger( e, simcontext() ); }
00170 
00171     void next_trigger( sc_event_or_list& el )
00172         { sc_core::next_trigger( el, simcontext() ); }
00173 
00174     void next_trigger( sc_event_and_list& el )
00175         { sc_core::next_trigger( el, simcontext() ); }
00176 
00177     void next_trigger( const sc_time& t )
00178         { sc_core::next_trigger( t, simcontext() ); }
00179 
00180     void next_trigger( double v, sc_time_unit tu )
00181         {sc_core::next_trigger( sc_time( v, tu, simcontext() ), simcontext() );}
00182 
00183     void next_trigger( const sc_time& t, const sc_event& e )
00184         { sc_core::next_trigger( t, e, simcontext() ); }
00185 
00186     void next_trigger( double v, sc_time_unit tu, const sc_event& e )
00187         { sc_core::next_trigger( 
00188         sc_time( v, tu, simcontext() ), e, simcontext() ); }
00189 
00190     void next_trigger( const sc_time& t, sc_event_or_list& el )
00191         { sc_core::next_trigger( t, el, simcontext() ); }
00192 
00193     void next_trigger( double v, sc_time_unit tu, sc_event_or_list& el )
00194         { sc_core::next_trigger( 
00195         sc_time( v, tu, simcontext() ), el, simcontext() ); }
00196 
00197     void next_trigger( const sc_time& t, sc_event_and_list& el )
00198         { sc_core::next_trigger( t, el, simcontext() ); }
00199 
00200     void next_trigger( double v, sc_time_unit tu, sc_event_and_list& el )
00201         { sc_core::next_trigger( 
00202         sc_time( v, tu, simcontext() ), el, simcontext() ); }
00203 
00204 
00205     // for SC_METHODs and SC_THREADs and SC_CTHREADs
00206 
00207     bool timed_out()
00208     { return sc_core::timed_out( simcontext() ); }
00209 
00210 
00211     // delta count maintenance
00212 
00213     sc_dt::uint64 delta_count()
00214     { return simcontext()->m_delta_count; }
00215 
00216 private:
00217 
00218     // called during the update phase of a delta cycle (if requested)
00219     void perform_update();
00220 
00221     // called when construction is done
00222     void construction_done();
00223 
00224     // called when elaboration is done
00225     void elaboration_done();
00226 
00227     // called before simulation starts
00228     void start_simulation();
00229 
00230     // called after simulation ends
00231     void simulation_done();
00232 
00233     // disabled
00234     sc_prim_channel( const sc_prim_channel& );
00235     sc_prim_channel& operator = ( const sc_prim_channel& );
00236 
00237 private:
00238 
00239     sc_prim_channel_registry* m_registry;      // Update list manager.
00240     sc_prim_channel*          m_update_next_p; // Next entry in update list.
00241 };
00242 
00243 
00244 // ----------------------------------------------------------------------------
00245 //  CLASS : sc_prim_channel_registry
00246 //
00247 //  Registry for all primitive channels.
00248 //  FOR INTERNAL USE ONLY!
00249 // ----------------------------------------------------------------------------
00250 
00251 class sc_prim_channel_registry
00252 {
00253     friend class sc_simcontext;
00254 
00255 public:
00256 
00257     void insert( sc_prim_channel& );
00258     void remove( sc_prim_channel& );
00259 
00260 
00261     int size() const
00262         { return m_prim_channel_vec.size(); }
00263 
00264     inline void request_update( sc_prim_channel& );
00265 
00266     bool pending_updates() const 
00267         { return m_update_list_p != 
00268         (sc_prim_channel*)sc_prim_channel::list_end; 
00269     }
00270 
00271 private:
00272 
00273     // constructor
00274     explicit sc_prim_channel_registry( sc_simcontext& simc_ );
00275 
00276     // destructor
00277     ~sc_prim_channel_registry();
00278 
00279     // called during the update phase of a delta cycle
00280     inline void perform_update();
00281 
00282     // called when construction is done
00283     void construction_done();
00284 
00285     // called when elaboration is done
00286     void elaboration_done();
00287 
00288     // called before simulation starts
00289     void start_simulation();
00290 
00291     // called after simulation ends
00292     void simulation_done();
00293 
00294     // disabled
00295     sc_prim_channel_registry();
00296     sc_prim_channel_registry( const sc_prim_channel_registry& );
00297     sc_prim_channel_registry& operator = ( const sc_prim_channel_registry& );
00298 
00299 private:
00300 
00301     sc_simcontext*                m_simc;
00302     std::vector<sc_prim_channel*> m_prim_channel_vec;
00303 
00304     sc_prim_channel*              m_update_list_p;
00305 };
00306 
00307 
00308 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00309 
00310 // ----------------------------------------------------------------------------
00311 //  CLASS : sc_prim_channel_registry
00312 //
00313 //  Registry for all primitive channels.
00314 //  FOR INTERNAL USE ONLY!
00315 // ----------------------------------------------------------------------------
00316 
00317 inline
00318 void
00319 sc_prim_channel_registry::request_update( sc_prim_channel& prim_channel_ )
00320 {
00321     prim_channel_.m_update_next_p = m_update_list_p;
00322     m_update_list_p = &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     sc_prim_channel* next_p; // Next update to perform.
00333     sc_prim_channel* now_p;  // Update now performing.
00334 
00335     now_p = m_update_list_p;
00336     m_update_list_p = (sc_prim_channel*)sc_prim_channel::list_end;
00337     for ( ; now_p != (sc_prim_channel*)sc_prim_channel::list_end; 
00338         now_p = next_p )
00339     {
00340         next_p = now_p->m_update_next_p;
00341     now_p->perform_update();
00342     }
00343 }
00344 
00345 // ----------------------------------------------------------------------------
00346 //  CLASS : sc_prim_channel
00347 //
00348 //  Abstract base class of all primitive channel classes.
00349 // ----------------------------------------------------------------------------
00350 
00351 // request the update method (to be executed during the update phase)
00352 
00353 inline
00354 void
00355 sc_prim_channel::request_update()
00356 {
00357     if( ! m_update_next_p ) {
00358     m_registry->request_update( *this );
00359     }
00360 }
00361 
00362 
00363 // called during the update phase of a delta cycle (if requested)
00364 
00365 inline
00366 void
00367 sc_prim_channel::perform_update()
00368 {
00369     update();
00370     m_update_next_p = 0;
00371 }
00372 
00373 
00374 } // namespace sc_core
00375 
00376 #endif
00377 
00378 // Taf!

Generated on Wed Jan 21 15:32:06 2009 for SystemC by  doxygen 1.5.5