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
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
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
00065
00066
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
00084 inline void request_update();
00085
00086
00087 protected:
00088
00089
00090 sc_prim_channel();
00091 explicit sc_prim_channel( const char* );
00092
00093
00094 virtual ~sc_prim_channel();
00095
00096
00097 virtual void update();
00098
00099
00100 virtual void before_end_of_elaboration();
00101
00102
00103 virtual void end_of_elaboration();
00104
00105
00106 virtual void start_of_simulation();
00107
00108
00109 virtual void end_of_simulation();
00110
00111 protected:
00112
00113
00114
00115
00116
00117 void wait()
00118 { sc_core::wait( simcontext() ); }
00119
00120
00121
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
00161
00162 void next_trigger()
00163 { sc_core::next_trigger( simcontext() ); }
00164
00165
00166
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
00206
00207 bool timed_out()
00208 { return sc_core::timed_out( simcontext() ); }
00209
00210
00211
00212
00213 sc_dt::uint64 delta_count()
00214 { return simcontext()->m_delta_count; }
00215
00216 private:
00217
00218
00219 void perform_update();
00220
00221
00222 void construction_done();
00223
00224
00225 void elaboration_done();
00226
00227
00228 void start_simulation();
00229
00230
00231 void simulation_done();
00232
00233
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;
00240 sc_prim_channel* m_update_next_p;
00241 };
00242
00243
00244
00245
00246
00247
00248
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
00274 explicit sc_prim_channel_registry( sc_simcontext& simc_ );
00275
00276
00277 ~sc_prim_channel_registry();
00278
00279
00280 inline void perform_update();
00281
00282
00283 void construction_done();
00284
00285
00286 void elaboration_done();
00287
00288
00289 void start_simulation();
00290
00291
00292 void simulation_done();
00293
00294
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
00309
00310
00311
00312
00313
00314
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
00327
00328 inline
00329 void
00330 sc_prim_channel_registry::perform_update()
00331 {
00332 sc_prim_channel* next_p;
00333 sc_prim_channel* now_p;
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
00347
00348
00349
00350
00351
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
00364
00365 inline
00366 void
00367 sc_prim_channel::perform_update()
00368 {
00369 update();
00370 m_update_next_p = 0;
00371 }
00372
00373
00374 }
00375
00376 #endif
00377
00378