Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

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-2004 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.3 (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 "systemc/kernel/sc_module.h"
00046 #include "systemc/communication/sc_signal.h"
00047 #include "systemc/tracing/sc_trace.h"
00048 
00049 
00050 // ----------------------------------------------------------------------------
00051 //  CLASS : sc_clock
00052 //
00053 //  The clock channel.
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     // constructors
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     // for backward compatibility with 1.0
00090     sc_clock( const char* name_,
00091         double         period_,            // in default time units
00092         double         duty_cycle_ = 0.5,
00093         double         start_time_ = 0.0,  // in default time units
00094         bool           posedge_first_ = true );
00095 
00096     // destructor (does nothing)
00097     virtual ~sc_clock();
00098 
00099     virtual void write( const bool& );
00100 
00101     // get the period
00102     const sc_time& period() const
00103   { return m_period; }
00104 
00105     // get the duty cycle
00106     double duty_cycle() const
00107   { return m_duty_cycle; }
00108 
00109 
00110     // get the current time
00111     static const sc_time& time_stamp();
00112 
00113     virtual const char* kind() const
00114         { return "sc_clock"; }
00115 
00116 
00117     // for backward compatibility with 1.0
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     // processes
00142     void posedge_action();
00143     void negedge_action();
00144 
00145 
00146     // error reporting
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;    // the period of this clock
00157     double   m_duty_cycle;  // the duty cycle (fraction of period)
00158     sc_time  m_start_time;  // the start time of the first edge
00159     sc_time  m_posedge_time;  // time till next positive edge
00160     sc_time  m_negedge_time;  // time till next negative edge
00161 
00162     sc_event m_next_posedge_event;
00163     sc_event m_next_negedge_event;
00164 
00165 private:
00166 
00167     // disabled
00168     sc_clock( const sc_clock& );
00169     sc_clock& operator = ( const sc_clock& );
00170 };
00171 
00172 
00173 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00174 
00175 // processes
00176 
00177 inline
00178 void
00179 sc_clock::posedge_action()
00180 {
00181     //m_posedge_event.notify_delayed();
00182     //m_value_changed_event.notify_delayed();
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     //m_negedge_event.notify_delayed();
00192     //m_value_changed_event.notify_delayed();
00193     m_next_posedge_event.notify_delayed( m_posedge_time );
00194     sc_signal<bool>::write(false);
00195 }
00196 
00197 
00198 // ----------------------------------------------------------------------------
00199 
00200 // for backward compatibility with 1.0
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 // Taf!

Generated on Fri Jan 14 08:29:00 2005 for SystemC2.1beta11(excludingMSLib)(IncludingSCV)\nProvidedby:www.openverificationfoundation.org by doxygen1.2.18