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