TLM-2.0  2.0.3
Accellera TLM-2.0 proof-of-concept library
tlm_global_quantum.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 #ifndef __TLM_GLOBAL_QUANTUM_H__
19 #define __TLM_GLOBAL_QUANTUM_H__
20 
21 #include <systemc>
22 
23 namespace tlm {
24 
25 //
26 // tlm_global_quantum class
27 //
28 // The global quantum is the maximum time an initiator can run ahead of
29 // systemC time. All initiators should synchronize on timingpoints that
30 // are multiples of the global quantum value.
31 //
32 // sc_set_time_resolution can only be called before the first
33 // sc_time object is created. This means that after setting the
34 // global quantum it will not be possible to call sc_set_time_resolution.
35 // If sc_set_time_resolution must be called this must be done before
36 // the global quantum is set.
37 //
38 
40 {
41 public:
42  //
43  // Returns a reference to the tlm_global_quantum singleton
44  //
46  {
47  static tlm_global_quantum instance_;
48  return instance_;
49  }
50 
51 public:
52 
53  //
54  // Setter/getter for the global quantum
55  //
56  void set(const sc_core::sc_time& t)
57  {
58  m_global_quantum = t;
59  }
60 
61  const sc_core::sc_time& get() const
62  {
63  return m_global_quantum;
64  }
65 
66  //
67  // This function will calculate the maximum value for the next local
68  // quantum for an initiator. All initiators should synchronize on
69  // integer multiples of the global quantum value. The value for the
70  // local quantum of an initiator can be smaller, but should never be
71  // greater than the value returned by this method.
72  //
74  {
76  const sc_core::sc_time current = sc_core::sc_time_stamp();
77  const sc_core::sc_time g_quant = m_global_quantum;
78  return g_quant - (current % g_quant);
79  } else {
80  return sc_core::SC_ZERO_TIME;
81  }
82  }
83 
84 protected:
86  {
87  }
88 
89 protected:
91 };
92 
93 } // namespace tlm
94 
95 #endif
void set(const sc_core::sc_time &t)
sc_core::sc_time m_global_quantum
const sc_time SC_ZERO_TIME
sc_core::sc_time compute_local_quantum()
const sc_time & sc_time_stamp()
static tlm_global_quantum & instance()