src/sysc/communication/sc_clock.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2005 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_clock.h -- The clock channel.
00021 
00022   Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
00023 
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027 
00028   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00029   changes you are making here.
00030 
00031       Name, Affiliation, Date: Bishnupriya Bhattacharya, Cadence Design Systems,
00032                                3 October, 2003
00033   Description of Modification: sc_clock inherits from sc_signal<bool> only
00034                                instead of sc_signal_in_if<bool> and sc_module.
00035     
00036       Name, Affiliation, Date:
00037   Description of Modification:
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 //  CLASS : sc_clock
00053 //
00054 //  The clock channel.
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     // constructors
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     // for backward compatibility with 1.0
00091     sc_clock( const char* name_,
00092               double         period_,            // in default time units
00093               double         duty_cycle_ = 0.5,
00094               double         start_time_ = 0.0,  // in default time units
00095               bool           posedge_first_ = true );
00096 
00097     // destructor (does nothing)
00098     virtual ~sc_clock();
00099 
00100     virtual void write( const bool& );
00101 
00102     // get the period
00103     const sc_time& period() const
00104         { return m_period; }
00105 
00106     // get the duty cycle
00107     double duty_cycle() const
00108         { return m_duty_cycle; }
00109 
00110 
00111     // get the current time / clock characteristics
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     // for backward compatibility with 1.0
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     // processes
00150     void posedge_action();
00151     void negedge_action();
00152 
00153 
00154     // error reporting
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;          // the period of this clock
00165     double   m_duty_cycle;      // the duty cycle (fraction of period)
00166     sc_time  m_start_time;      // the start time of the first edge
00167     bool     m_posedge_first;   // true if first edge is positive
00168     sc_time  m_posedge_time;    // time till next positive edge
00169     sc_time  m_negedge_time;    // time till next negative edge
00170 
00171     sc_event m_next_posedge_event;
00172     sc_event m_next_negedge_event;
00173 
00174 private:
00175 
00176     // disabled
00177     sc_clock( const sc_clock& );
00178     sc_clock& operator = ( const sc_clock& );
00179 };
00180 
00181 
00182 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00183 
00184 // processes
00185 
00186 inline
00187 void
00188 sc_clock::posedge_action()
00189 {
00190     //m_posedge_event.notify_delayed();
00191     //m_value_changed_event.notify_delayed();
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     //m_negedge_event.notify_delayed();
00201     //m_value_changed_event.notify_delayed();
00202     m_next_posedge_event.notify_delayed( m_posedge_time );
00203     sc_signal<bool>::write(false);
00204 }
00205 
00206 
00207 // ----------------------------------------------------------------------------
00208 
00209 // for backward compatibility with 1.0
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 } // namespace sc_core
00250 
00251 #endif
00252 
00253 // Taf!

Generated on Wed Apr 25 13:53:25 2007 for SystemC by  doxygen 1.5.1