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