SystemC  2.3.1
Accellera SystemC proof-of-concept library
sc_prim_channel.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 /*****************************************************************************
19 
20  sc_prim_channel.h -- Abstract base class of all primitive channel classes.
21 
22  Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
23 
24  CHANGE LOG AT THE END OF THE FILE
25  *****************************************************************************/
26 
27 #ifndef SC_PRIM_CHANNEL_H
28 #define SC_PRIM_CHANNEL_H
29 
30 #include "sysc/kernel/sc_object.h"
31 #include "sysc/kernel/sc_wait.h"
33 
34 namespace sc_core {
35 
36 // ----------------------------------------------------------------------------
37 // CLASS : sc_prim_channel
38 //
39 // Abstract base class of all primitive channel classes.
40 // ----------------------------------------------------------------------------
41 
43 : public sc_object
44 {
46 
47 public:
48  enum { list_end = 0xdb };
49 public:
50  virtual const char* kind() const
51  { return "sc_prim_channel"; }
52 
53  inline bool update_requested()
54  { return m_update_next_p != (sc_prim_channel*)list_end; }
55 
56  // request the update method to be executed during the update phase
57  inline void request_update();
58 
59  // request the update method to be executed during the update phase
60  // from a process external to the simulator.
61  void async_request_update();
62 
63 protected:
64 
65  // constructors
67  explicit sc_prim_channel( const char* );
68 
69  // destructor
70  virtual ~sc_prim_channel();
71 
72  // the update method (does nothing by default)
73  virtual void update();
74 
75  // called by construction_done (does nothing by default)
76  virtual void before_end_of_elaboration();
77 
78  // called by elaboration_done (does nothing by default)
79  virtual void end_of_elaboration();
80 
81  // called by start_simulation (does nothing by default)
82  virtual void start_of_simulation();
83 
84  // called by simulation_done (does nothing by default)
85  virtual void end_of_simulation();
86 
87 protected:
88 
89  // to avoid calling sc_get_curr_simcontext()
90 
91  // static sensitivity for SC_THREADs and SC_CTHREADs
92 
93  void wait()
94  { sc_core::wait( simcontext() ); }
95 
96 
97  // dynamic sensitivity for SC_THREADs and SC_CTHREADs
98 
99  void wait( const sc_event& e )
100  { sc_core::wait( e, simcontext() ); }
101 
102  void wait( const sc_event_or_list& el )
103  { sc_core::wait( el, simcontext() ); }
104 
105  void wait( const sc_event_and_list& el )
106  { sc_core::wait( el, simcontext() ); }
107 
108  void wait( const sc_time& t )
109  { sc_core::wait( t, simcontext() ); }
110 
111  void wait( double v, sc_time_unit tu )
112  { sc_core::wait( sc_time( v, tu, simcontext() ), simcontext() ); }
113 
114  void wait( const sc_time& t, const sc_event& e )
115  { sc_core::wait( t, e, simcontext() ); }
116 
117  void wait( double v, sc_time_unit tu, const sc_event& e )
118  { sc_core::wait( sc_time( v, tu, simcontext() ), e, simcontext() ); }
119 
120  void wait( const sc_time& t, const sc_event_or_list& el )
121  { sc_core::wait( t, el, simcontext() ); }
122 
123  void wait( double v, sc_time_unit tu, const sc_event_or_list& el )
124  { sc_core::wait( sc_time( v, tu, simcontext() ), el, simcontext() ); }
125 
126  void wait( const sc_time& t, const sc_event_and_list& el )
127  { sc_core::wait( t, el, simcontext() ); }
128 
129  void wait( double v, sc_time_unit tu, const sc_event_and_list& el )
130  { sc_core::wait( sc_time( v, tu, simcontext() ), el, simcontext() ); }
131 
132  void wait( int n )
133  { sc_core::wait( n, simcontext() ); }
134 
135 
136  // static sensitivity for SC_METHODs
137 
140 
141 
142  // dynamic sensitivity for SC_METHODs
143 
144  void next_trigger( const sc_event& e )
145  { sc_core::next_trigger( e, simcontext() ); }
146 
147  void next_trigger( const sc_event_or_list& el )
148  { sc_core::next_trigger( el, simcontext() ); }
149 
150  void next_trigger( const sc_event_and_list& el )
151  { sc_core::next_trigger( el, simcontext() ); }
152 
153  void next_trigger( const sc_time& t )
154  { sc_core::next_trigger( t, simcontext() ); }
155 
156  void next_trigger( double v, sc_time_unit tu )
158 
159  void next_trigger( const sc_time& t, const sc_event& e )
160  { sc_core::next_trigger( t, e, simcontext() ); }
161 
162  void next_trigger( double v, sc_time_unit tu, const sc_event& e )
164  sc_time( v, tu, simcontext() ), e, simcontext() ); }
165 
166  void next_trigger( const sc_time& t, const sc_event_or_list& el )
167  { sc_core::next_trigger( t, el, simcontext() ); }
168 
169  void next_trigger( double v, sc_time_unit tu, const sc_event_or_list& el )
171  sc_time( v, tu, simcontext() ), el, simcontext() ); }
172 
173  void next_trigger( const sc_time& t, const sc_event_and_list& el )
174  { sc_core::next_trigger( t, el, simcontext() ); }
175 
176  void next_trigger( double v, sc_time_unit tu, const sc_event_and_list& el )
178  sc_time( v, tu, simcontext() ), el, simcontext() ); }
179 
180 
181  // for SC_METHODs and SC_THREADs and SC_CTHREADs
182 
183  bool timed_out()
184  { return sc_core::timed_out( simcontext() ); }
185 
186 
187 #if 0 // @@@@####
188  // delta count maintenance
189  sc_dt::uint64 delta_count()
190  { return simcontext()->m_delta_count; }
191 #endif
192 
193 private:
194 
195  // called during the update phase of a delta cycle (if requested)
196  void perform_update();
197 
198  // called when construction is done
199  void construction_done();
200 
201  // called when elaboration is done
202  void elaboration_done();
203 
204  // called before simulation starts
205  void start_simulation();
206 
207  // called after simulation ends
208  void simulation_done();
209 
210  // disabled
212  sc_prim_channel& operator = ( const sc_prim_channel& );
213 
214 private:
215 
216  sc_prim_channel_registry* m_registry; // Update list manager.
217  sc_prim_channel* m_update_next_p; // Next entry in update list.
218 };
219 
220 
221 // ----------------------------------------------------------------------------
222 // CLASS : sc_prim_channel_registry
223 //
224 // Registry for all primitive channels.
225 // FOR INTERNAL USE ONLY!
226 // ----------------------------------------------------------------------------
227 
229 {
230  friend class sc_simcontext;
231 
232 public:
233 
234  void insert( sc_prim_channel& );
235  void remove( sc_prim_channel& );
236 
237 
238  int size() const
239  { return m_prim_channel_vec.size(); }
240 
241  inline void request_update( sc_prim_channel& );
243 
244  bool pending_updates() const
245  {
246  return m_update_list_p != (sc_prim_channel*)sc_prim_channel::list_end
248  }
249 
250  bool pending_async_updates() const;
251 
252 private:
253 
254  // constructor
255  explicit sc_prim_channel_registry( sc_simcontext& simc_ );
256 
257  // destructor
259 
260  // called during the update phase of a delta cycle
261  void perform_update();
262 
263  // called when construction is done
264  bool construction_done();
265 
266  // called when elaboration is done
267  void elaboration_done();
268 
269  // called before simulation starts
270  void start_simulation();
271 
272  // called after simulation ends
273  void simulation_done();
274 
275  // disabled
278  sc_prim_channel_registry& operator = ( const sc_prim_channel_registry& );
279 
280 private:
281  class async_update_list;
282 
283  async_update_list* m_async_update_list_p; // external updates.
284  int m_construction_done; // # of constructs.
285  std::vector<sc_prim_channel*> m_prim_channel_vec; // existing channels.
286  sc_simcontext* m_simc; // simulator context.
287  sc_prim_channel* m_update_list_p; // internal updates.
288 };
289 
290 
291 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
292 
293 // ----------------------------------------------------------------------------
294 // CLASS : sc_prim_channel_registry
295 //
296 // Registry for all primitive channels.
297 // FOR INTERNAL USE ONLY!
298 // ----------------------------------------------------------------------------
299 
300 inline
301 void
303 {
304  prim_channel_.m_update_next_p = m_update_list_p;
305  m_update_list_p = &prim_channel_;
306 }
307 
308 // ----------------------------------------------------------------------------
309 // CLASS : sc_prim_channel
310 //
311 // Abstract base class of all primitive channel classes.
312 // ----------------------------------------------------------------------------
313 
314 // request the update method (to be executed during the update phase)
315 
316 inline
317 void
319 {
320  if( ! m_update_next_p ) {
321  m_registry->request_update( *this );
322  }
323 }
324 
325 // request the update method from external to the simulator (to be executed
326 // during the update phase)
327 
328 inline
329 void
331 {
332  m_registry->async_request_update(*this);
333 }
334 
335 
336 // called during the update phase of a delta cycle (if requested)
337 
338 inline
339 void
340 sc_prim_channel::perform_update()
341 {
342  update();
343  m_update_next_p = 0;
344 }
345 
346 
347 } // namespace sc_core
348 
349 
350 /*****************************************************************************
351 
352  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
353  changes you are making here.
354 
355  Name, Affiliation, Date: Andy Goodrich, Forte,
356  Bishnupriya Bhattacharya, Cadence Design Systems,
357  25 August, 2003
358  Description of Modification: phase callbacks
359 
360  *****************************************************************************/
361 //$Log: sc_prim_channel.h,v $
362 //Revision 1.10 2011/08/26 21:38:32 acg
363 // Philipp A. Hartmann: removed unused switch m_construction_done.
364 //
365 //Revision 1.9 2011/08/07 19:08:01 acg
366 // Andy Goodrich: moved logs to end of file so line number synching works
367 // better between versions.
368 //
369 //Revision 1.8 2011/05/09 04:07:37 acg
370 // Philipp A. Hartmann:
371 // (1) Restore hierarchy in all phase callbacks.
372 // (2) Ensure calls to before_end_of_elaboration.
373 //
374 //Revision 1.7 2011/05/05 17:44:01 acg
375 // Philip A. Hartmann: change in the name of pending_async_updates.
376 //
377 //Revision 1.6 2011/04/19 15:03:48 acg
378 // Philipp A. Hartmann: remove ASYNC_UPDATE preprocessor check from header.
379 //
380 //Revision 1.5 2011/04/19 02:36:26 acg
381 // Philipp A. Hartmann: new aysnc_update and mutex support.
382 //
383 //Revision 1.4 2011/04/05 20:48:09 acg
384 // Andy Goodrich: changes to make sure that event(), posedge() and negedge()
385 // only return true if the clock has not moved.
386 //
387 //Revision 1.3 2011/02/18 20:23:45 acg
388 // Andy Goodrich: Copyright update.
389 //
390 //Revision 1.2 2011/01/20 16:52:15 acg
391 // Andy Goodrich: changes for IEEE 1666 2011.
392 //
393 //Revision 1.1.1.1 2006/12/15 20:20:04 acg
394 //SystemC 2.3
395 //
396 //Revision 1.3 2006/05/08 17:52:47 acg
397 // Andy Goodrich:
398 // (1) added David Long's forward declarations for friend functions,
399 // methods, and operators to keep the Microsoft compiler happy.
400 // (2) Added delta_count() method to sc_prim_channel for use by
401 // sc_signal so that the friend declaration in sc_simcontext.h
402 // can be for a non-templated class (i.e., sc_prim_channel.)
403 //
404 //Revision 1.2 2006/01/03 23:18:26 acg
405 //Changed copyright to include 2006.
406 //
407 //Revision 1.1.1.1 2005/12/19 23:16:43 acg
408 //First check in of SystemC 2.1 into its own archive.
409 //
410 //Revision 1.10 2005/07/30 03:44:11 acg
411 //Changes from 2.1.
412 //
413 //Revision 1.9 2005/06/10 22:43:55 acg
414 //Added CVS change log annotation.
415 
416 #endif
417 
418 // Taf!
void next_trigger(const sc_time &t, const sc_event_or_list &el)
void wait(int, sc_simcontext *)
void wait(const sc_event_and_list &el)
friend class sc_prim_channel_registry
sc_time_unit
Definition: sc_time.h:56
void request_update(sc_prim_channel &)
void wait(const sc_time &t)
void next_trigger(double v, sc_time_unit tu, const sc_event_and_list &el)
void next_trigger(double v, sc_time_unit tu, const sc_event &e)
void next_trigger(const sc_event_or_list &el)
void next_trigger(const sc_event &e)
void next_trigger(double v, sc_time_unit tu)
uint64_t uint64
Definition: sc_nbdefs.h:183
void async_request_update(sc_prim_channel &)
void wait(double v, sc_time_unit tu, const sc_event_and_list &el)
void next_trigger(double v, sc_time_unit tu, const sc_event_or_list &el)
virtual void end_of_elaboration()
void wait(const sc_event_or_list &el)
void wait(double v, sc_time_unit tu)
bool timed_out(sc_simcontext *)
virtual void end_of_simulation()
void wait(const sc_time &t, const sc_event &e)
virtual const char * kind() const
void next_trigger(const sc_time &t, const sc_event &e)
virtual void start_of_simulation()
void next_trigger(const sc_time &t)
void next_trigger(sc_simcontext *)
void wait(double v, sc_time_unit tu, const sc_event &e)
sc_simcontext * simcontext() const
Definition: sc_object.h:81
void next_trigger(const sc_event_and_list &el)
void wait(const sc_event &e)
void wait(const sc_time &t, const sc_event_and_list &el)
void insert(sc_prim_channel &)
virtual void before_end_of_elaboration()
void wait(const sc_time &t, const sc_event_or_list &el)
void next_trigger(const sc_time &t, const sc_event_and_list &el)
void wait(double v, sc_time_unit tu, const sc_event_or_list &el)