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-2006 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 //$Log: sc_clock.h,v $
00041 //Revision 1.1.1.1  2006/12/15 20:31:35  acg
00042 //SystemC 2.2
00043 //
00044 //Revision 1.5  2006/01/25 00:31:11  acg
00045 // Andy Goodrich: Changed over to use a standard message id of
00046 // SC_ID_IEEE_1666_DEPRECATION for all deprecation messages.
00047 //
00048 //Revision 1.4  2006/01/24 20:43:25  acg
00049 // Andy Goodrich: convert notify_delayed() calls into notify_internal() calls.
00050 // notify_internal() is an implementation dependent version of notify_delayed()
00051 // that is simpler, and does not trigger the deprecation warning one would get
00052 // using notify_delayed().
00053 //
00054 //Revision 1.3  2006/01/18 21:42:26  acg
00055 //Andy Goodrich: Changes for check writer support, and tightening up sc_clock
00056 //port usage.
00057 //
00058 //Revision 1.2  2006/01/03 23:18:26  acg
00059 //Changed copyright to include 2006.
00060 //
00061 //Revision 1.1.1.1  2005/12/19 23:16:43  acg
00062 //First check in of SystemC 2.1 into its own archive.
00063 //
00064 //Revision 1.14  2005/06/10 22:43:55  acg
00065 //Added CVS change log annotation.
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 //  CLASS : sc_clock
00080 //
00081 //  The clock channel.
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     // constructors
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     // for backward compatibility with 1.0
00118     sc_clock( const char* name_,
00119           double         period_,            // in default time units
00120           double         duty_cycle_ = 0.5,
00121           double         start_time_ = 0.0,  // in default time units
00122           bool           posedge_first_ = true );
00123 
00124     // destructor (does nothing)
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     // get the period
00131     const sc_time& period() const
00132     { return m_period; }
00133 
00134     // get the duty cycle
00135     double duty_cycle() const
00136     { return m_duty_cycle; }
00137 
00138 
00139     // get the current time / clock characteristics
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     // for backward compatibility with 1.0
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     // processes
00178     void posedge_action();
00179     void negedge_action();
00180 
00181 
00182     // error reporting
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;      // the period of this clock
00193     double   m_duty_cycle;  // the duty cycle (fraction of period)
00194     sc_time  m_start_time;  // the start time of the first edge
00195     bool     m_posedge_first;   // true if first edge is positive
00196     sc_time  m_posedge_time;    // time till next positive edge
00197     sc_time  m_negedge_time;    // time till next negative edge
00198 
00199     sc_event m_next_posedge_event;
00200     sc_event m_next_negedge_event;
00201 
00202 private:
00203 
00204     // disabled
00205     sc_clock( const sc_clock& );
00206     sc_clock& operator = ( const sc_clock& );
00207 };
00208 
00209 
00210 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00211 
00212 // processes
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 // for backward compatibility with 1.0
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 } // namespace sc_core
00276 
00277 #endif
00278 
00279 // Taf!

Generated on Wed Jan 21 15:32:06 2009 for SystemC by  doxygen 1.5.5