00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
00049
00050
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
00066 void request_update();
00067
00068
00069 protected:
00070
00071
00072 sc_prim_channel();
00073 explicit sc_prim_channel( const char* );
00074
00075
00076 virtual ~sc_prim_channel();
00077
00078
00079 virtual void update();
00080
00081
00082 virtual void before_end_of_elaboration();
00083
00084
00085 virtual void end_of_elaboration();
00086
00087
00088 virtual void start_of_simulation();
00089
00090
00091 virtual void end_of_simulation();
00092
00093 protected:
00094
00095
00096
00097
00098
00099
00100 void wait()
00101 { sc_core::wait( simcontext() ); }
00102
00103
00104
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
00141
00142 void next_trigger()
00143 { sc_core::next_trigger( simcontext() ); }
00144
00145
00146
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
00186
00187 bool timed_out()
00188 { return sc_core::timed_out( simcontext() ); }
00189
00190 private:
00191
00192
00193 void perform_update();
00194
00195
00196 void construction_done();
00197
00198
00199 void elaboration_done();
00200
00201
00202 void start_simulation();
00203
00204
00205 void simulation_done();
00206
00207
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
00221
00222
00223
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
00243 explicit sc_prim_channel_registry( sc_simcontext& simc_ );
00244
00245
00246 ~sc_prim_channel_registry();
00247
00248
00249 void perform_update();
00250
00251
00252 void construction_done();
00253
00254
00255 void elaboration_done();
00256
00257
00258 void start_simulation();
00259
00260
00261 void simulation_done();
00262
00263
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
00280
00281
00282
00283
00284
00285
00286
00287
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
00301
00302 inline
00303 void
00304 sc_prim_channel::perform_update()
00305 {
00306 update();
00307 m_update_requested = false;
00308 }
00309
00310
00311
00312
00313
00314
00315
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
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 }
00339
00340 #endif
00341
00342