00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #ifndef SC_CLOCK_H
00069 #define SC_CLOCK_H
00070
00071
00072 #include "sysc/kernel/sc_module.h"
00073 #include "sysc/communication/sc_signal.h"
00074 #include "sysc/tracing/sc_trace.h"
00075
00076 namespace sc_core {
00077
00078
00079
00080
00081
00082
00083
00084 class sc_clock
00085 : public sc_signal<bool>
00086 {
00087 public:
00088
00089 friend class sc_clock_posedge_callback;
00090 friend class sc_clock_negedge_callback;
00091
00092
00093
00094 sc_clock();
00095
00096 explicit sc_clock( const char* name_ );
00097
00098 sc_clock( const char* name_,
00099 const sc_time& period_,
00100 double duty_cycle_ = 0.5,
00101 const sc_time& start_time_ = SC_ZERO_TIME,
00102 bool posedge_first_ = true );
00103
00104 sc_clock( const char* name_,
00105 double period_v_,
00106 sc_time_unit period_tu_,
00107 double duty_cycle_ = 0.5 );
00108
00109 sc_clock( const char* name_,
00110 double period_v_,
00111 sc_time_unit period_tu_,
00112 double duty_cycle_,
00113 double start_time_v_,
00114 sc_time_unit start_time_tu_,
00115 bool posedge_first_ = true );
00116
00117
00118 sc_clock( const char* name_,
00119 double period_,
00120 double duty_cycle_ = 0.5,
00121 double start_time_ = 0.0,
00122 bool posedge_first_ = true );
00123
00124
00125 virtual ~sc_clock();
00126
00127 virtual void register_port( sc_port_base&, const char* if_type );
00128 virtual void write( const bool& );
00129
00130
00131 const sc_time& period() const
00132 { return m_period; }
00133
00134
00135 double duty_cycle() const
00136 { return m_duty_cycle; }
00137
00138
00139
00140
00141 bool posedge_first() const
00142 { return m_posedge_first; }
00143
00144 sc_time start_time() const
00145 { return m_start_time; }
00146
00147 static const sc_time& time_stamp();
00148
00149 virtual const char* kind() const
00150 { return "sc_clock"; }
00151
00152
00153
00154
00155 sc_signal_in_if<bool>& signal()
00156 { return *this; }
00157
00158 const sc_signal_in_if<bool>& signal() const
00159 { return *this; }
00160
00161 static void start( const sc_time& duration )
00162 { sc_start( duration ); }
00163
00164 static void start( double v, sc_time_unit tu )
00165 { sc_start( v, tu ); }
00166
00167 static void start( double duration = -1 )
00168 { sc_start( duration ); }
00169
00170 static void stop()
00171 { sc_stop(); }
00172
00173 protected:
00174
00175 void before_end_of_elaboration();
00176
00177
00178 void posedge_action();
00179 void negedge_action();
00180
00181
00182
00183 void report_error( const char* id, const char* add_msg = 0 ) const;
00184
00185
00186 void init( const sc_time&, double, const sc_time&, bool );
00187
00188 bool is_clock() const { return true; }
00189
00190 protected:
00191
00192 sc_time m_period;
00193 double m_duty_cycle;
00194 sc_time m_start_time;
00195 bool m_posedge_first;
00196 sc_time m_posedge_time;
00197 sc_time m_negedge_time;
00198
00199 sc_event m_next_posedge_event;
00200 sc_event m_next_negedge_event;
00201
00202 private:
00203
00204
00205 sc_clock( const sc_clock& );
00206 sc_clock& operator = ( const sc_clock& );
00207 };
00208
00209
00210
00211
00212
00213
00214 inline
00215 void
00216 sc_clock::posedge_action()
00217 {
00218 m_next_negedge_event.notify_internal( m_negedge_time );
00219 m_new_val = true;
00220 request_update();
00221 }
00222
00223 inline
00224 void
00225 sc_clock::negedge_action()
00226 {
00227 m_next_posedge_event.notify_internal( m_posedge_time );
00228 m_new_val = false;
00229 request_update();
00230 }
00231
00232
00233
00234
00235
00236
00237 inline
00238 void
00239 sc_start( sc_clock& clock, const sc_time& duration )
00240 {
00241 clock.start( duration );
00242 }
00243
00244 inline
00245 void
00246 sc_start( sc_clock& clock, double v, sc_time_unit tu )
00247 {
00248 clock.start( v, tu );
00249 }
00250
00251 inline
00252 void
00253 sc_start( sc_clock& clock, double duration = -1 )
00254 {
00255 clock.start( duration );
00256 }
00257
00258 class sc_clock_posedge_callback {
00259 public:
00260 sc_clock_posedge_callback(sc_clock* target_p) { m_target_p = target_p; }
00261 inline void operator () () { m_target_p->posedge_action(); }
00262 protected:
00263 sc_clock* m_target_p;
00264 };
00265
00266 class sc_clock_negedge_callback {
00267 public:
00268 sc_clock_negedge_callback(sc_clock* target_p) { m_target_p = target_p; }
00269 inline void operator () () { m_target_p->negedge_action(); }
00270 protected:
00271 sc_clock* m_target_p;
00272 };
00273
00274
00275 }
00276
00277 #endif
00278
00279