TLM-2.0  2.0.3
Accellera TLM-2.0 proof-of-concept library
tlm_quantumkeeper.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 // 20-Mar-2009 John Aynsley Add set_and_sync() method
19 
20 
21 #ifndef __TLM_QUANTUMKEEPER_H__
22 #define __TLM_QUANTUMKEEPER_H__
23 
25 
26 namespace tlm_utils {
27 
28  //
29  // tlm_quantumkeeper class
30  //
31  // The tlm_quantumkeeper class is used to keep track of the local time in
32  // an initiator (how much it has run ahead of the SystemC time), to
33  // synchronize with SystemC time etc.
34  //
36  {
37  public:
38  //
39  // Static setters/getters for the global quantum value.
40  //
41  // The global quantum is the maximum time an initiator can run ahead of
42  // systemC time. All initiators will synchronize on timingpoints that are
43  // multiples of the global quantum value.
44  //
45  static void set_global_quantum(const sc_core::sc_time& t)
46  {
48  }
49 
51  {
53  }
54 
55  public:
58  m_local_time(sc_core::SC_ZERO_TIME)
59  {
60  }
61 
62  virtual ~tlm_quantumkeeper() {}
63 
64  //
65  // Increment the local time (the time the initiator is ahead of the
66  // systemC time) After incrementing the local time an initiator should
67  // check (with the need_sync method) if a sync is required.
68  //
69  virtual void inc(const sc_core::sc_time& t)
70  {
71  m_local_time += t;
72  }
73 
74  //
75  // Sets the local time (the time the initiator is ahead of the
76  // systemC time) After changing the local time an initiator should
77  // check (with the need_sync method) if a sync is required.
78  //
79  virtual void set(const sc_core::sc_time& t)
80  {
81  m_local_time = t;
82  }
83 
84  //
85  // Checks if a sync to systemC is required for this initiator. This will
86  // be the case if the local time becomes greater than the local (current)
87  // quantum value for this initiator.
88  //
89  virtual bool need_sync() const
90  {
92  }
93 
94  //
95  // Synchronize to systemC. This call will do a wait for the time the
96  // initiator was running ahead of systemC time and reset the
97  // tlm_quantumkeeper.
98  //
99  virtual void sync()
100  {
102  reset();
103  }
104 
105  //
106  // Non-virtual convenience method to set the local time and sync only if needed
107  //
109  {
110  set(t);
111  if (need_sync())
112  sync();
113  }
114 
115  //
116  // Resets the local time to SC_ZERO_TIME and computes the value of the
117  // next local quantum. This method should be called by an initiator after
118  // a wait because of a synchronization request by a target (TLM_ACCEPTED,
119  // or TLM_UPDATED).
120  //
121  virtual void reset()
122  {
125  }
126 
127  //
128  // Helper function to get the current systemC time, taken the local time
129  // into account. The current systemC time is calculated as the time
130  // returned by sc_time_stamp incremeneted with the time the initiator is
131  // running ahead.
132  //
134  {
136  }
137 
138  //
139  // Helper functions to get the time the initiator is running ahead of
140  // systenC (local time). This time should be passed to a target in the
141  // nb_transport call
142  //
144  {
145  return m_local_time;
146  }
147 
148  protected:
149  //
150  // Calculate the next local quantum for this initiator.
151  //
152  // The method can be overloaded in a derived object if an initiator wants
153  // to use another local quantum. This derived object should also take the
154  // global quantum into account. It's local quantum should not be set to a
155  // value that is larger than the quantum returned by the
156  // compute_local_quantum of the tlm_global_quantum singleton.
157  //
159  {
161  }
162 
163  protected:
166  };
167 
168 } // namespace tlm
169 
170 #endif
void wait(int, sc_simcontext *)
const sc_core::sc_time & get() const
virtual sc_core::sc_time get_local_time() const
virtual bool need_sync() const
void set_and_sync(const sc_core::sc_time &t)
virtual sc_core::sc_time get_current_time() const
static const sc_core::sc_time & get_global_quantum()
virtual void inc(const sc_core::sc_time &t)
void set(const sc_core::sc_time &t)
const sc_time SC_ZERO_TIME
virtual sc_core::sc_time compute_local_quantum()
virtual void set(const sc_core::sc_time &t)
sc_core::sc_time compute_local_quantum()
const sc_time & sc_time_stamp()
static void set_global_quantum(const sc_core::sc_time &t)
static tlm_global_quantum & instance()