SystemC  Recoding Infrastructure for SystemC v0.6.2 derived from Accellera SystemC 2.3.1
Accellera SystemC proof-of-concept library
sc_clock.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_clock.h -- The clock channel.
21 
22  Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
23 
24  CHANGE LOG IS AT THE END OF THE FILE
25  *****************************************************************************/
26 
27 #ifndef SC_CLOCK_H
28 #define SC_CLOCK_H
29 
30 
31 #include "sysc/kernel/sc_module.h"
33 #include "sysc/tracing/sc_trace.h"
34 
35 namespace sc_core {
36 
37 /**************************************************************************/
43 class sc_clock
44  : public sc_signal<bool,SC_ONE_WRITER>
45 {
47 public:
48 
51 
52  // constructors
53 
54  sc_clock();
55 
56  explicit sc_clock( const char* name_ );
57 
58  sc_clock( const char* name_,
59  const sc_time& period_,
60  double duty_cycle_ = 0.5,
61  const sc_time& start_time_ = SC_ZERO_TIME,
62  bool posedge_first_ = true );
63 
64  sc_clock( const char* name_,
65  double period_v_,
66  sc_time_unit period_tu_,
67  double duty_cycle_ = 0.5 );
68 
69  sc_clock( const char* name_,
70  double period_v_,
71  sc_time_unit period_tu_,
72  double duty_cycle_,
73  double start_time_v_,
74  sc_time_unit start_time_tu_,
75  bool posedge_first_ = true );
76 
77  // for backward compatibility with 1.0
78  sc_clock( const char* name_,
79  double period_, // in default time units
80  double duty_cycle_ = 0.5,
81  double start_time_ = 0.0, // in default time units
82  bool posedge_first_ = true );
83 
84  // destructor (does nothing)
85  virtual ~sc_clock();
86 
87  virtual void register_port( sc_port_base&, const char* if_type );
88  virtual void write( const bool& );
89 
90  // get the period
91  const sc_time& period() const
92  { return m_period; }
93 
94  // get the duty cycle
95  double duty_cycle() const
96  { return m_duty_cycle; }
97 
98 
99  // get the current time / clock characteristics
100 
101  bool posedge_first() const
102  { return m_posedge_first; }
103 
105  { return m_start_time; }
106 
107  static const sc_time& time_stamp();
108 
109  virtual const char* kind() const
110  { return "sc_clock"; }
111 
112 
113 #if 0 // @@@@#### REMOVE
114  // for backward compatibility with 1.0
115 
116  sc_signal_in_if<bool>& signal()
117  { return *this; }
118 
119  const sc_signal_in_if<bool>& signal() const
120  { return *this; }
121 
122  static void start( const sc_time& duration )
123  { sc_start( duration ); }
124 
125  static void start( double v, sc_time_unit tu )
126  { sc_start( sc_time(v, tu) ); }
127 
128  static void start( double duration = -1 )
129  { sc_start( duration ); }
130 
131  static void stop()
132  { sc_stop(); }
133 #endif
134 
135 protected:
136 
141  // 09/20/2015 GL.
143 
144  // processes
145  void posedge_action();
146  void negedge_action();
147 
148 
149  // error reporting
150  void report_error( const char* id, const char* add_msg = 0 ) const;
151 
152 
153  void init( const sc_time&, double, const sc_time&, bool );
154 
155  bool is_clock() const { return true; }
156 
157 protected:
158 
159  sc_time m_period; // the period of this clock
160  double m_duty_cycle; // the duty cycle (fraction of period)
161  sc_time m_start_time; // the start time of the first edge
162  bool m_posedge_first; // true if first edge is positive
163  sc_time m_posedge_time; // time till next positive edge
164  sc_time m_negedge_time; // time till next negative edge
165 
168 
169 private:
170 
171  // disabled
172  sc_clock( const sc_clock& );
173  sc_clock& operator = ( const sc_clock& );
174 };
175 
176 
177 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
178 
179 // processes
180 
181 inline
182 void
184 {
185  // 02/23/2015 GL: acquire a lock to protect concurrent communication
186  chnl_scoped_lock lock( m_mutex );
187 
188  m_next_negedge_event.notify_internal( m_negedge_time );
189  m_new_val = true;
190  request_update();
191  // 02/23/2015 GL: return releases the lock
192 }
193 
194 inline
195 void
197 {
198  // 02/23/2015 GL: acquire a lock to protect concurrent communication
199  chnl_scoped_lock lock( m_mutex );
200 
201  m_next_posedge_event.notify_internal( m_posedge_time );
202  m_new_val = false;
203  request_update();
204  // 02/23/2015 GL: return releases the lock
205 }
206 
207 
208 // ----------------------------------------------------------------------------
209 
211 public:
213  inline void operator () () { m_target_p->posedge_action(); }
214  protected:
216 };
217 
219  public:
221  inline void operator () () { m_target_p->negedge_action(); }
222  protected:
224 };
225 
226 
227 } // namespace sc_core
228 
229 /*****************************************************************************
230 
231  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
232  changes you are making here.
233 
234  Name, Affiliation, Date: Bishnupriya Bhattacharya, Cadence Design Systems,
235  3 October, 2003
236  Description of Modification: sc_clock inherits from sc_signal<bool> only
237  instead of sc_signal_in_if<bool> and sc_module.
238 
239  Name, Affiliation, Date:
240  Description of Modification:
241 
242  *****************************************************************************/
243 //$Log: sc_clock.h,v $
244 //Revision 1.5 2011/08/26 20:45:39 acg
245 // Andy Goodrich: moved the modification log to the end of the file to
246 // eliminate source line number skew when check-ins are done.
247 //
248 //Revision 1.4 2011/08/24 22:05:35 acg
249 // Torsten Maehne: initialization changes to remove warnings.
250 //
251 //Revision 1.3 2011/02/18 20:23:45 acg
252 // Andy Goodrich: Copyright update.
253 //
254 //Revision 1.2 2011/01/20 16:52:15 acg
255 // Andy Goodrich: changes for IEEE 1666 2011.
256 //
257 //Revision 1.1.1.1 2006/12/15 20:20:04 acg
258 //SystemC 2.3
259 //
260 //Revision 1.5 2006/01/25 00:31:11 acg
261 // Andy Goodrich: Changed over to use a standard message id of
262 // SC_ID_IEEE_1666_DEPRECATION for all deprecation messages.
263 //
264 //Revision 1.4 2006/01/24 20:43:25 acg
265 // Andy Goodrich: convert notify_delayed() calls into notify_internal() calls.
266 // notify_internal() is an implementation dependent version of notify_delayed()
267 // that is simpler, and does not trigger the deprecation warning one would get
268 // using notify_delayed().
269 //
270 //Revision 1.3 2006/01/18 21:42:26 acg
271 //Andy Goodrich: Changes for check writer support, and tightening up sc_clock
272 //port usage.
273 //
274 //Revision 1.2 2006/01/03 23:18:26 acg
275 //Changed copyright to include 2006.
276 //
277 //Revision 1.1.1.1 2005/12/19 23:16:43 acg
278 //First check in of SystemC 2.1 into its own archive.
279 //
280 //Revision 1.14 2005/06/10 22:43:55 acg
281 //Added CVS change log annotation.
282 //
283 
284 #endif
285 
286 // Taf!
double duty_cycle() const
Definition: sc_clock.h:95
Specialization of sc_signal_in_if&lt;T&gt; for type bool.
Definition: sc_signal_ifs.h:96
sc_time m_period
Definition: sc_clock.h:159
sc_event m_next_negedge_event
Definition: sc_clock.h:167
sc_clock_negedge_callback(sc_clock *target_p)
Definition: sc_clock.h:220
double m_duty_cycle
Definition: sc_clock.h:160
CHNL_MTX_TYPE_ m_mutex
A mutex to protect concurrent communication.
The clock channel.
Definition: sc_clock.h:43
virtual const char * kind() const
Definition: sc_clock.h:109
sc_time m_posedge_time
Definition: sc_clock.h:163
virtual void write(const bool &)
sc_time m_start_time
Definition: sc_clock.h:161
sc_time start_time() const
Definition: sc_clock.h:104
void posedge_action()
Definition: sc_clock.h:183
bool m_posedge_first
Definition: sc_clock.h:162
virtual ~sc_clock()
void negedge_action()
Definition: sc_clock.h:196
void report_error(const char *id, const char *add_msg=0) const
virtual void register_port(sc_port_base &, const char *if_type)
void before_end_of_elaboration()
This function is not supported by the out-of-order simulation in the current release.
The event class.
Definition: sc_event.h:260
bool posedge_first() const
Definition: sc_clock.h:101
void sc_start()
sc_clock_posedge_callback(sc_clock *target_p)
Definition: sc_clock.h:212
Abstract base class for class sc_port_b.
Definition: sc_port.h:69
const sc_time & period() const
Definition: sc_clock.h:91
sc_time m_negedge_time
Definition: sc_clock.h:164
sc_event m_next_posedge_event
Definition: sc_clock.h:166
const sc_time SC_ZERO_TIME
void init(const sc_time &, double, const sc_time &, bool)
static const sc_time & time_stamp()
The chnl_scoped_lock class to lock (and automatically release) a mutex.
void sc_stop()
bool is_clock() const
Definition: sc_clock.h:155
sc_time_unit
Definition: sc_time.h:56