SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_clock.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 /*****************************************************************************
21 
22  sc_clock.h -- The clock channel.
23 */
33 #ifndef SC_CLOCK_H
34 #define SC_CLOCK_H
35 
36 
37 #include "sysc/kernel/sc_module.h"
39 #include "sysc/tracing/sc_trace.h"
40 
41 namespace sc_core {
42 
50  : public sc_signal<bool,SC_ONE_WRITER>
51 {
53 public:
54 
57 
58  // constructors
59 
60  sc_clock();
61 
62  explicit sc_clock( const char* name_ );
63 
64  sc_clock( const char* name_,
65  const sc_time& period_,
66  double duty_cycle_ = 0.5,
67  const sc_time& start_time_ = SC_ZERO_TIME,
68  bool posedge_first_ = true );
69 
70  sc_clock( const char* name_,
71  double period_v_,
72  sc_time_unit period_tu_,
73  double duty_cycle_ = 0.5 );
74 
75  sc_clock( const char* name_,
76  double period_v_,
77  sc_time_unit period_tu_,
78  double duty_cycle_,
79  double start_time_v_,
80  sc_time_unit start_time_tu_,
81  bool posedge_first_ = true );
82 
83  // for backward compatibility with 1.0
84  sc_clock( const char* name_,
85  double period_, // in default time units
86  double duty_cycle_ = 0.5,
87  double start_time_ = 0.0, // in default time units
88  bool posedge_first_ = true );
89 
90  // destructor (does nothing)
91  virtual ~sc_clock();
92 
93  virtual void register_port( sc_port_base&, const char* if_type );
94  virtual void write( const bool& );
95 
96  // get the period
97  const sc_time& period() const
98  { return m_period; }
99 
100  // get the duty cycle
101  double duty_cycle() const
102  { return m_duty_cycle; }
103 
104 
105  // get the current time / clock characteristics
106 
107  bool posedge_first() const
108  { return m_posedge_first; }
109 
111  { return m_start_time; }
112 
113  static const sc_time& time_stamp();
114 
115  virtual const char* kind() const
116  { return "sc_clock"; }
117 
118 
119 #if 0 // @@@@#### REMOVE
120  // for backward compatibility with 1.0
121 
122  sc_signal_in_if<bool>& signal()
123  { return *this; }
124 
125  const sc_signal_in_if<bool>& signal() const
126  { return *this; }
127 
128  static void start( const sc_time& duration )
129  { sc_start( duration ); }
130 
131  static void start( double v, sc_time_unit tu )
132  { sc_start( sc_time(v, tu) ); }
133 
134  static void start( double duration = -1 )
135  { sc_start( duration ); }
136 
137  static void stop()
138  { sc_stop(); }
139 #endif
140 
141 protected:
142 
143  void before_end_of_elaboration();
144 
145  // processes
146  void posedge_action();
147  void negedge_action();
148 
149 
150  // error reporting
151  void report_error( const char* id, const char* add_msg = 0 ) const;
152 
153 
154  void init( const sc_time&, double, const sc_time&, bool );
155 
156  bool is_clock() const { return true; }
157 
158 protected:
159 
160  sc_time m_period; // the period of this clock
161  double m_duty_cycle; // the duty cycle (fraction of period)
162  sc_time m_start_time; // the start time of the first edge
163  bool m_posedge_first; // true if first edge is positive
164  sc_time m_posedge_time; // time till next positive edge
165  sc_time m_negedge_time; // time till next negative edge
166 
169 
170 private:
171 
172  // disabled
173  sc_clock( const sc_clock& );
174  sc_clock& operator = ( const sc_clock& );
175 };
176 
177 
178 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
179 
180 // processes
181 
182 inline
183 void
185 {
186  m_next_negedge_event.notify_internal( m_negedge_time );
187  m_new_val = true;
188  request_update();
189 }
190 
191 inline
192 void
194 {
195  m_next_posedge_event.notify_internal( m_posedge_time );
196  m_new_val = false;
197  request_update();
198 }
199 
200 
201 // ----------------------------------------------------------------------------
202 
204 public:
205  sc_clock_posedge_callback(sc_clock* target_p) : m_target_p(target_p) {}
206  inline void operator () () { m_target_p->posedge_action(); }
207  protected:
209 };
210 
212  public:
213  sc_clock_negedge_callback(sc_clock* target_p) : m_target_p(target_p) {}
214  inline void operator () () { m_target_p->negedge_action(); }
215  protected:
217 };
218 
219 
220 } // namespace sc_core
221 
222 /*****************************************************************************
223 
224  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
225  changes you are making here.
226 
227  Name, Affiliation, Date: Bishnupriya Bhattacharya, Cadence Design Systems,
228  3 October, 2003
229  Description of Modification: sc_clock inherits from sc_signal<bool> only
230  instead of sc_signal_in_if<bool> and sc_module.
231 
232  Name, Affiliation, Date:
233  Description of Modification:
234 
235  *****************************************************************************/
236 //$Log: sc_clock.h,v $
237 //Revision 1.5 2011/08/26 20:45:39 acg
238 // Andy Goodrich: moved the modification log to the end of the file to
239 // eliminate source line number skew when check-ins are done.
240 //
241 //Revision 1.4 2011/08/24 22:05:35 acg
242 // Torsten Maehne: initialization changes to remove warnings.
243 //
244 //Revision 1.3 2011/02/18 20:23:45 acg
245 // Andy Goodrich: Copyright update.
246 //
247 //Revision 1.2 2011/01/20 16:52:15 acg
248 // Andy Goodrich: changes for IEEE 1666 2011.
249 //
250 //Revision 1.1.1.1 2006/12/15 20:20:04 acg
251 //SystemC 2.3
252 //
253 //Revision 1.5 2006/01/25 00:31:11 acg
254 // Andy Goodrich: Changed over to use a standard message id of
255 // SC_ID_IEEE_1666_DEPRECATION for all deprecation messages.
256 //
257 //Revision 1.4 2006/01/24 20:43:25 acg
258 // Andy Goodrich: convert notify_delayed() calls into notify_internal() calls.
259 // notify_internal() is an implementation dependent version of notify_delayed()
260 // that is simpler, and does not trigger the deprecation warning one would get
261 // using notify_delayed().
262 //
263 //Revision 1.3 2006/01/18 21:42:26 acg
264 //Andy Goodrich: Changes for check writer support, and tightening up sc_clock
265 //port usage.
266 //
267 //Revision 1.2 2006/01/03 23:18:26 acg
268 //Changed copyright to include 2006.
269 //
270 //Revision 1.1.1.1 2005/12/19 23:16:43 acg
271 //First check in of SystemC 2.1 into its own archive.
272 //
273 //Revision 1.14 2005/06/10 22:43:55 acg
274 //Added CVS change log annotation.
275 //
276 
277 #endif
278 
279 // Taf!
SC_API const sc_time SC_ZERO_TIME
sc_time m_negedge_time
Definition: sc_clock.h:165
Specialization of sc_signal_in_if<T> for type bool.
virtual const char * kind() const
Definition: sc_clock.h:115
The sc_signal<T> primitive channel class.
double duty_cycle() const
Definition: sc_clock.h:101
Abstract base class for class sc_port_b.
Definition: sc_port.h:81
The clock channel.
Definition: sc_clock.h:49
The event class.
Definition: sc_event.h:256
bool m_posedge_first
Definition: sc_clock.h:163
SC_API void sc_start()
The sc_signal<T> input/output interface class.
bool is_clock() const
Definition: sc_clock.h:156
void posedge_action()
Definition: sc_clock.h:184
sc_time m_posedge_time
Definition: sc_clock.h:164
sc_time m_period
Definition: sc_clock.h:160
double m_duty_cycle
Definition: sc_clock.h:161
void negedge_action()
Definition: sc_clock.h:193
sc_event m_next_negedge_event
Definition: sc_clock.h:168
The time class.
Definition: sc_time.h:82
sc_event m_next_posedge_event
Definition: sc_clock.h:167
Base class of all hierarchical modules and channels.
sc_clock_posedge_callback(sc_clock *target_p)
Definition: sc_clock.h:205
sc_clock_negedge_callback(sc_clock *target_p)
Definition: sc_clock.h:213
SC_API void sc_stop()
const sc_time & period() const
Definition: sc_clock.h:97
sc_time start_time() const
Definition: sc_clock.h:110
bool posedge_first() const
Definition: sc_clock.h:107
#define SC_API
Definition: sc_cmnhdr.h:168
sc_time_unit
Enumeration of time units.
Definition: sc_time.h:64
sc_time m_start_time
Definition: sc_clock.h:162