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 // ----------------------------------------------------------------------------
38 // CLASS : sc_clock
39 //
40 // The clock channel.
41 // ----------------------------------------------------------------------------
42 
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 
138 
139  // processes
140  void posedge_action();
141  void negedge_action();
142 
143 
144  // error reporting
145  void report_error( const char* id, const char* add_msg = 0 ) const;
146 
147 
148  void init( const sc_time&, double, const sc_time&, bool );
149 
150  bool is_clock() const { return true; }
151 
152 protected:
153 
154  sc_time m_period; // the period of this clock
155  double m_duty_cycle; // the duty cycle (fraction of period)
156  sc_time m_start_time; // the start time of the first edge
157  bool m_posedge_first; // true if first edge is positive
158  sc_time m_posedge_time; // time till next positive edge
159  sc_time m_negedge_time; // time till next negative edge
160 
163 
164 private:
165 
166  // disabled
167  sc_clock( const sc_clock& );
168  sc_clock& operator = ( const sc_clock& );
169 };
170 
171 
172 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
173 
174 // processes
175 
176 inline
177 void
179 {
180  m_next_negedge_event.notify_internal( m_negedge_time );
181  m_new_val = true;
182  request_update();
183 }
184 
185 inline
186 void
188 {
189  m_next_posedge_event.notify_internal( m_posedge_time );
190  m_new_val = false;
191  request_update();
192 }
193 
194 
195 // ----------------------------------------------------------------------------
196 
198 public:
200  inline void operator () () { m_target_p->posedge_action(); }
201  protected:
203 };
204 
206  public:
208  inline void operator () () { m_target_p->negedge_action(); }
209  protected:
211 };
212 
213 
214 } // namespace sc_core
215 
216 /*****************************************************************************
217 
218  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
219  changes you are making here.
220 
221  Name, Affiliation, Date: Bishnupriya Bhattacharya, Cadence Design Systems,
222  3 October, 2003
223  Description of Modification: sc_clock inherits from sc_signal<bool> only
224  instead of sc_signal_in_if<bool> and sc_module.
225 
226  Name, Affiliation, Date:
227  Description of Modification:
228 
229  *****************************************************************************/
230 //$Log: sc_clock.h,v $
231 //Revision 1.5 2011/08/26 20:45:39 acg
232 // Andy Goodrich: moved the modification log to the end of the file to
233 // eliminate source line number skew when check-ins are done.
234 //
235 //Revision 1.4 2011/08/24 22:05:35 acg
236 // Torsten Maehne: initialization changes to remove warnings.
237 //
238 //Revision 1.3 2011/02/18 20:23:45 acg
239 // Andy Goodrich: Copyright update.
240 //
241 //Revision 1.2 2011/01/20 16:52:15 acg
242 // Andy Goodrich: changes for IEEE 1666 2011.
243 //
244 //Revision 1.1.1.1 2006/12/15 20:20:04 acg
245 //SystemC 2.3
246 //
247 //Revision 1.5 2006/01/25 00:31:11 acg
248 // Andy Goodrich: Changed over to use a standard message id of
249 // SC_ID_IEEE_1666_DEPRECATION for all deprecation messages.
250 //
251 //Revision 1.4 2006/01/24 20:43:25 acg
252 // Andy Goodrich: convert notify_delayed() calls into notify_internal() calls.
253 // notify_internal() is an implementation dependent version of notify_delayed()
254 // that is simpler, and does not trigger the deprecation warning one would get
255 // using notify_delayed().
256 //
257 //Revision 1.3 2006/01/18 21:42:26 acg
258 //Andy Goodrich: Changes for check writer support, and tightening up sc_clock
259 //port usage.
260 //
261 //Revision 1.2 2006/01/03 23:18:26 acg
262 //Changed copyright to include 2006.
263 //
264 //Revision 1.1.1.1 2005/12/19 23:16:43 acg
265 //First check in of SystemC 2.1 into its own archive.
266 //
267 //Revision 1.14 2005/06/10 22:43:55 acg
268 //Added CVS change log annotation.
269 //
270 
271 #endif
272 
273 // Taf!
sc_time start_time() const
Definition: sc_clock.h:104
sc_clock_negedge_callback(sc_clock *target_p)
Definition: sc_clock.h:207
sc_time_unit
Definition: sc_time.h:56
bool m_posedge_first
Definition: sc_clock.h:157
virtual void write(const bool &)
sc_time m_negedge_time
Definition: sc_clock.h:159
sc_event m_next_posedge_event
Definition: sc_clock.h:161
double duty_cycle() const
Definition: sc_clock.h:95
const sc_time & period() const
Definition: sc_clock.h:91
virtual const char * kind() const
Definition: sc_clock.h:109
static const sc_time & time_stamp()
sc_event m_next_negedge_event
Definition: sc_clock.h:162
bool is_clock() const
Definition: sc_clock.h:150
void before_end_of_elaboration()
bool posedge_first() const
Definition: sc_clock.h:101
sc_clock_posedge_callback(sc_clock *target_p)
Definition: sc_clock.h:199
void sc_start()
sc_time m_posedge_time
Definition: sc_clock.h:158
void report_error(const char *id, const char *add_msg=0) const
sc_time m_start_time
Definition: sc_clock.h:156
const sc_time SC_ZERO_TIME
virtual ~sc_clock()
double m_duty_cycle
Definition: sc_clock.h:155
sc_time m_period
Definition: sc_clock.h:154
void init(const sc_time &, double, const sc_time &, bool)
void posedge_action()
Definition: sc_clock.h:178
virtual void register_port(sc_port_base &, const char *if_type)
void negedge_action()
Definition: sc_clock.h:187
void sc_stop()