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