112027Sjungma@eit.uni-kl.de/*****************************************************************************
212027Sjungma@eit.uni-kl.de
312027Sjungma@eit.uni-kl.de  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412027Sjungma@eit.uni-kl.de  more contributor license agreements.  See the NOTICE file distributed
512027Sjungma@eit.uni-kl.de  with this work for additional information regarding copyright ownership.
612027Sjungma@eit.uni-kl.de  Accellera licenses this file to you under the Apache License, Version 2.0
712027Sjungma@eit.uni-kl.de  (the "License"); you may not use this file except in compliance with the
812027Sjungma@eit.uni-kl.de  License.  You may obtain a copy of the License at
912027Sjungma@eit.uni-kl.de
1012027Sjungma@eit.uni-kl.de    http://www.apache.org/licenses/LICENSE-2.0
1112027Sjungma@eit.uni-kl.de
1212027Sjungma@eit.uni-kl.de  Unless required by applicable law or agreed to in writing, software
1312027Sjungma@eit.uni-kl.de  distributed under the License is distributed on an "AS IS" BASIS,
1412027Sjungma@eit.uni-kl.de  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512027Sjungma@eit.uni-kl.de  implied.  See the License for the specific language governing
1612027Sjungma@eit.uni-kl.de  permissions and limitations under the License.
1712027Sjungma@eit.uni-kl.de
1812027Sjungma@eit.uni-kl.de *****************************************************************************/
1912027Sjungma@eit.uni-kl.de
2012027Sjungma@eit.uni-kl.de/*****************************************************************************
2112027Sjungma@eit.uni-kl.de
2212027Sjungma@eit.uni-kl.de  sc_clock.h -- The clock channel.
2312027Sjungma@eit.uni-kl.de
2412027Sjungma@eit.uni-kl.de  Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
2512027Sjungma@eit.uni-kl.de
2612027Sjungma@eit.uni-kl.de  CHANGE LOG IS AT THE END OF THE FILE
2712027Sjungma@eit.uni-kl.de *****************************************************************************/
2812027Sjungma@eit.uni-kl.de
2912027Sjungma@eit.uni-kl.de#ifndef SC_CLOCK_H
3012027Sjungma@eit.uni-kl.de#define SC_CLOCK_H
3112027Sjungma@eit.uni-kl.de
3212027Sjungma@eit.uni-kl.de
3312027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_module.h"
3412027Sjungma@eit.uni-kl.de#include "sysc/communication/sc_signal.h"
3512027Sjungma@eit.uni-kl.de#include "sysc/tracing/sc_trace.h"
3612027Sjungma@eit.uni-kl.de
3712027Sjungma@eit.uni-kl.denamespace sc_core {
3812027Sjungma@eit.uni-kl.de
3912027Sjungma@eit.uni-kl.de// ----------------------------------------------------------------------------
4012027Sjungma@eit.uni-kl.de//  CLASS : sc_clock
4112027Sjungma@eit.uni-kl.de//
4212027Sjungma@eit.uni-kl.de//  The clock channel.
4312027Sjungma@eit.uni-kl.de// ----------------------------------------------------------------------------
4412027Sjungma@eit.uni-kl.de
4512027Sjungma@eit.uni-kl.declass sc_clock
4612027Sjungma@eit.uni-kl.de  : public sc_signal<bool,SC_ONE_WRITER>
4712027Sjungma@eit.uni-kl.de{
4812027Sjungma@eit.uni-kl.de  typedef sc_signal<bool,SC_ONE_WRITER> base_type;
4912027Sjungma@eit.uni-kl.depublic:
5012027Sjungma@eit.uni-kl.de
5112027Sjungma@eit.uni-kl.de    friend class sc_clock_posedge_callback;
5212027Sjungma@eit.uni-kl.de    friend class sc_clock_negedge_callback;
5312027Sjungma@eit.uni-kl.de
5412027Sjungma@eit.uni-kl.de    // constructors
5512027Sjungma@eit.uni-kl.de
5612027Sjungma@eit.uni-kl.de    sc_clock();
5712027Sjungma@eit.uni-kl.de
5812027Sjungma@eit.uni-kl.de    explicit sc_clock( const char* name_ );
5912027Sjungma@eit.uni-kl.de
6012027Sjungma@eit.uni-kl.de    sc_clock( const char* name_,
6112027Sjungma@eit.uni-kl.de	      const sc_time& period_,
6212027Sjungma@eit.uni-kl.de	      double         duty_cycle_ = 0.5,
6312027Sjungma@eit.uni-kl.de	      const sc_time& start_time_ = SC_ZERO_TIME,
6412027Sjungma@eit.uni-kl.de	      bool           posedge_first_ = true );
6512027Sjungma@eit.uni-kl.de
6612027Sjungma@eit.uni-kl.de    sc_clock( const char* name_,
6712027Sjungma@eit.uni-kl.de	      double         period_v_,
6812027Sjungma@eit.uni-kl.de	      sc_time_unit   period_tu_,
6912027Sjungma@eit.uni-kl.de	      double         duty_cycle_ = 0.5 );
7012027Sjungma@eit.uni-kl.de
7112027Sjungma@eit.uni-kl.de    sc_clock( const char* name_,
7212027Sjungma@eit.uni-kl.de	      double         period_v_,
7312027Sjungma@eit.uni-kl.de	      sc_time_unit   period_tu_,
7412027Sjungma@eit.uni-kl.de	      double         duty_cycle_,
7512027Sjungma@eit.uni-kl.de	      double         start_time_v_,
7612027Sjungma@eit.uni-kl.de	      sc_time_unit   start_time_tu_,
7712027Sjungma@eit.uni-kl.de	      bool           posedge_first_ = true );
7812027Sjungma@eit.uni-kl.de
7912027Sjungma@eit.uni-kl.de    // for backward compatibility with 1.0
8012027Sjungma@eit.uni-kl.de    sc_clock( const char* name_,
8112027Sjungma@eit.uni-kl.de	      double         period_,            // in default time units
8212027Sjungma@eit.uni-kl.de	      double         duty_cycle_ = 0.5,
8312027Sjungma@eit.uni-kl.de	      double         start_time_ = 0.0,  // in default time units
8412027Sjungma@eit.uni-kl.de	      bool           posedge_first_ = true );
8512027Sjungma@eit.uni-kl.de
8612027Sjungma@eit.uni-kl.de    // destructor (does nothing)
8712027Sjungma@eit.uni-kl.de    virtual ~sc_clock();
8812027Sjungma@eit.uni-kl.de
8912027Sjungma@eit.uni-kl.de    virtual void register_port( sc_port_base&, const char* if_type );
9012027Sjungma@eit.uni-kl.de    virtual void write( const bool& );
9112027Sjungma@eit.uni-kl.de
9212027Sjungma@eit.uni-kl.de    // get the period
9312027Sjungma@eit.uni-kl.de    const sc_time& period() const
9412027Sjungma@eit.uni-kl.de	{ return m_period; }
9512027Sjungma@eit.uni-kl.de
9612027Sjungma@eit.uni-kl.de    // get the duty cycle
9712027Sjungma@eit.uni-kl.de    double duty_cycle() const
9812027Sjungma@eit.uni-kl.de	{ return m_duty_cycle; }
9912027Sjungma@eit.uni-kl.de
10012027Sjungma@eit.uni-kl.de
10112027Sjungma@eit.uni-kl.de    // get the current time / clock characteristics
10212027Sjungma@eit.uni-kl.de
10312027Sjungma@eit.uni-kl.de    bool posedge_first() const
10412027Sjungma@eit.uni-kl.de        { return m_posedge_first; }
10512027Sjungma@eit.uni-kl.de
10612027Sjungma@eit.uni-kl.de    sc_time start_time() const
10712027Sjungma@eit.uni-kl.de        { return m_start_time; }
10812027Sjungma@eit.uni-kl.de
10912027Sjungma@eit.uni-kl.de    static const sc_time& time_stamp();
11012027Sjungma@eit.uni-kl.de
11112027Sjungma@eit.uni-kl.de    virtual const char* kind() const
11212027Sjungma@eit.uni-kl.de        { return "sc_clock"; }
11312027Sjungma@eit.uni-kl.de
11412027Sjungma@eit.uni-kl.de
11512027Sjungma@eit.uni-kl.de#if 0 // @@@@#### REMOVE
11612027Sjungma@eit.uni-kl.de    // for backward compatibility with 1.0
11712027Sjungma@eit.uni-kl.de
11812027Sjungma@eit.uni-kl.de    sc_signal_in_if<bool>& signal()
11912027Sjungma@eit.uni-kl.de	{ return *this; }
12012027Sjungma@eit.uni-kl.de
12112027Sjungma@eit.uni-kl.de    const sc_signal_in_if<bool>& signal() const
12212027Sjungma@eit.uni-kl.de	{ return *this; }
12312027Sjungma@eit.uni-kl.de
12412027Sjungma@eit.uni-kl.de    static void start( const sc_time& duration )
12512027Sjungma@eit.uni-kl.de	{ sc_start( duration ); }
12612027Sjungma@eit.uni-kl.de
12712027Sjungma@eit.uni-kl.de    static void start( double v, sc_time_unit tu )
12812027Sjungma@eit.uni-kl.de	{ sc_start( sc_time(v, tu) ); }
12912027Sjungma@eit.uni-kl.de
13012027Sjungma@eit.uni-kl.de    static void start( double duration = -1 )
13112027Sjungma@eit.uni-kl.de	{ sc_start( duration ); }
13212027Sjungma@eit.uni-kl.de
13312027Sjungma@eit.uni-kl.de    static void stop()
13412027Sjungma@eit.uni-kl.de	{ sc_stop(); }
13512027Sjungma@eit.uni-kl.de#endif
13612027Sjungma@eit.uni-kl.de
13712027Sjungma@eit.uni-kl.deprotected:
13812027Sjungma@eit.uni-kl.de
13912027Sjungma@eit.uni-kl.de    void before_end_of_elaboration();
14012027Sjungma@eit.uni-kl.de
14112027Sjungma@eit.uni-kl.de    // processes
14212027Sjungma@eit.uni-kl.de    void posedge_action();
14312027Sjungma@eit.uni-kl.de    void negedge_action();
14412027Sjungma@eit.uni-kl.de
14512027Sjungma@eit.uni-kl.de
14612027Sjungma@eit.uni-kl.de    // error reporting
14712027Sjungma@eit.uni-kl.de    void report_error( const char* id, const char* add_msg = 0 ) const;
14812027Sjungma@eit.uni-kl.de
14912027Sjungma@eit.uni-kl.de
15012027Sjungma@eit.uni-kl.de    void init( const sc_time&, double, const sc_time&, bool );
15112027Sjungma@eit.uni-kl.de
15212027Sjungma@eit.uni-kl.de    bool is_clock() const { return true; }
15312027Sjungma@eit.uni-kl.de
15412027Sjungma@eit.uni-kl.deprotected:
15512027Sjungma@eit.uni-kl.de
15612027Sjungma@eit.uni-kl.de    sc_time  m_period;		// the period of this clock
15712027Sjungma@eit.uni-kl.de    double   m_duty_cycle;	// the duty cycle (fraction of period)
15812027Sjungma@eit.uni-kl.de    sc_time  m_start_time;	// the start time of the first edge
15912027Sjungma@eit.uni-kl.de    bool     m_posedge_first;   // true if first edge is positive
16012027Sjungma@eit.uni-kl.de    sc_time  m_posedge_time;	// time till next positive edge
16112027Sjungma@eit.uni-kl.de    sc_time  m_negedge_time;	// time till next negative edge
16212027Sjungma@eit.uni-kl.de
16312027Sjungma@eit.uni-kl.de    sc_event m_next_posedge_event;
16412027Sjungma@eit.uni-kl.de    sc_event m_next_negedge_event;
16512027Sjungma@eit.uni-kl.de
16612027Sjungma@eit.uni-kl.deprivate:
16712027Sjungma@eit.uni-kl.de
16812027Sjungma@eit.uni-kl.de    // disabled
16912027Sjungma@eit.uni-kl.de    sc_clock( const sc_clock& );
17012027Sjungma@eit.uni-kl.de    sc_clock& operator = ( const sc_clock& );
17112027Sjungma@eit.uni-kl.de};
17212027Sjungma@eit.uni-kl.de
17312027Sjungma@eit.uni-kl.de
17412027Sjungma@eit.uni-kl.de// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
17512027Sjungma@eit.uni-kl.de
17612027Sjungma@eit.uni-kl.de// processes
17712027Sjungma@eit.uni-kl.de
17812027Sjungma@eit.uni-kl.deinline
17912027Sjungma@eit.uni-kl.devoid
18012027Sjungma@eit.uni-kl.desc_clock::posedge_action()
18112027Sjungma@eit.uni-kl.de{
18212027Sjungma@eit.uni-kl.de    m_next_negedge_event.notify_internal( m_negedge_time );
18312027Sjungma@eit.uni-kl.de	m_new_val = true;
18412027Sjungma@eit.uni-kl.de	request_update();
18512027Sjungma@eit.uni-kl.de}
18612027Sjungma@eit.uni-kl.de
18712027Sjungma@eit.uni-kl.deinline
18812027Sjungma@eit.uni-kl.devoid
18912027Sjungma@eit.uni-kl.desc_clock::negedge_action()
19012027Sjungma@eit.uni-kl.de{
19112027Sjungma@eit.uni-kl.de    m_next_posedge_event.notify_internal( m_posedge_time );
19212027Sjungma@eit.uni-kl.de	m_new_val = false;
19312027Sjungma@eit.uni-kl.de	request_update();
19412027Sjungma@eit.uni-kl.de}
19512027Sjungma@eit.uni-kl.de
19612027Sjungma@eit.uni-kl.de
19712027Sjungma@eit.uni-kl.de// ----------------------------------------------------------------------------
19812027Sjungma@eit.uni-kl.de
19912027Sjungma@eit.uni-kl.declass sc_clock_posedge_callback {
20012027Sjungma@eit.uni-kl.depublic:
20112027Sjungma@eit.uni-kl.de    sc_clock_posedge_callback(sc_clock* target_p) : m_target_p(target_p) {}
20212027Sjungma@eit.uni-kl.de    inline void operator () () { m_target_p->posedge_action(); }
20312027Sjungma@eit.uni-kl.de  protected:
20412027Sjungma@eit.uni-kl.de    sc_clock* m_target_p;
20512027Sjungma@eit.uni-kl.de};
20612027Sjungma@eit.uni-kl.de
20712027Sjungma@eit.uni-kl.declass sc_clock_negedge_callback {
20812027Sjungma@eit.uni-kl.de  public:
20912027Sjungma@eit.uni-kl.de    sc_clock_negedge_callback(sc_clock* target_p) : m_target_p(target_p) {}
21012027Sjungma@eit.uni-kl.de    inline void operator () () { m_target_p->negedge_action(); }
21112027Sjungma@eit.uni-kl.de  protected:
21212027Sjungma@eit.uni-kl.de    sc_clock* m_target_p;
21312027Sjungma@eit.uni-kl.de};
21412027Sjungma@eit.uni-kl.de
21512027Sjungma@eit.uni-kl.de
21612027Sjungma@eit.uni-kl.de} // namespace sc_core
21712027Sjungma@eit.uni-kl.de
21812027Sjungma@eit.uni-kl.de/*****************************************************************************
21912027Sjungma@eit.uni-kl.de
22012027Sjungma@eit.uni-kl.de  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
22112027Sjungma@eit.uni-kl.de  changes you are making here.
22212027Sjungma@eit.uni-kl.de
22312027Sjungma@eit.uni-kl.de      Name, Affiliation, Date: Bishnupriya Bhattacharya, Cadence Design Systems,
22412027Sjungma@eit.uni-kl.de                               3 October, 2003
22512027Sjungma@eit.uni-kl.de  Description of Modification: sc_clock inherits from sc_signal<bool> only
22612027Sjungma@eit.uni-kl.de                               instead of sc_signal_in_if<bool> and sc_module.
22712027Sjungma@eit.uni-kl.de
22812027Sjungma@eit.uni-kl.de      Name, Affiliation, Date:
22912027Sjungma@eit.uni-kl.de  Description of Modification:
23012027Sjungma@eit.uni-kl.de
23112027Sjungma@eit.uni-kl.de *****************************************************************************/
23212027Sjungma@eit.uni-kl.de//$Log: sc_clock.h,v $
23312027Sjungma@eit.uni-kl.de//Revision 1.5  2011/08/26 20:45:39  acg
23412027Sjungma@eit.uni-kl.de// Andy Goodrich: moved the modification log to the end of the file to
23512027Sjungma@eit.uni-kl.de// eliminate source line number skew when check-ins are done.
23612027Sjungma@eit.uni-kl.de//
23712027Sjungma@eit.uni-kl.de//Revision 1.4  2011/08/24 22:05:35  acg
23812027Sjungma@eit.uni-kl.de// Torsten Maehne: initialization changes to remove warnings.
23912027Sjungma@eit.uni-kl.de//
24012027Sjungma@eit.uni-kl.de//Revision 1.3  2011/02/18 20:23:45  acg
24112027Sjungma@eit.uni-kl.de// Andy Goodrich: Copyright update.
24212027Sjungma@eit.uni-kl.de//
24312027Sjungma@eit.uni-kl.de//Revision 1.2  2011/01/20 16:52:15  acg
24412027Sjungma@eit.uni-kl.de// Andy Goodrich: changes for IEEE 1666 2011.
24512027Sjungma@eit.uni-kl.de//
24612027Sjungma@eit.uni-kl.de//Revision 1.1.1.1  2006/12/15 20:20:04  acg
24712027Sjungma@eit.uni-kl.de//SystemC 2.3
24812027Sjungma@eit.uni-kl.de//
24912027Sjungma@eit.uni-kl.de//Revision 1.5  2006/01/25 00:31:11  acg
25012027Sjungma@eit.uni-kl.de// Andy Goodrich: Changed over to use a standard message id of
25112027Sjungma@eit.uni-kl.de// SC_ID_IEEE_1666_DEPRECATION for all deprecation messages.
25212027Sjungma@eit.uni-kl.de//
25312027Sjungma@eit.uni-kl.de//Revision 1.4  2006/01/24 20:43:25  acg
25412027Sjungma@eit.uni-kl.de// Andy Goodrich: convert notify_delayed() calls into notify_internal() calls.
25512027Sjungma@eit.uni-kl.de// notify_internal() is an implementation dependent version of notify_delayed()
25612027Sjungma@eit.uni-kl.de// that is simpler, and does not trigger the deprecation warning one would get
25712027Sjungma@eit.uni-kl.de// using notify_delayed().
25812027Sjungma@eit.uni-kl.de//
25912027Sjungma@eit.uni-kl.de//Revision 1.3  2006/01/18 21:42:26  acg
26012027Sjungma@eit.uni-kl.de//Andy Goodrich: Changes for check writer support, and tightening up sc_clock
26112027Sjungma@eit.uni-kl.de//port usage.
26212027Sjungma@eit.uni-kl.de//
26312027Sjungma@eit.uni-kl.de//Revision 1.2  2006/01/03 23:18:26  acg
26412027Sjungma@eit.uni-kl.de//Changed copyright to include 2006.
26512027Sjungma@eit.uni-kl.de//
26612027Sjungma@eit.uni-kl.de//Revision 1.1.1.1  2005/12/19 23:16:43  acg
26712027Sjungma@eit.uni-kl.de//First check in of SystemC 2.1 into its own archive.
26812027Sjungma@eit.uni-kl.de//
26912027Sjungma@eit.uni-kl.de//Revision 1.14  2005/06/10 22:43:55  acg
27012027Sjungma@eit.uni-kl.de//Added CVS change log annotation.
27112027Sjungma@eit.uni-kl.de//
27212027Sjungma@eit.uni-kl.de
27312027Sjungma@eit.uni-kl.de#endif
27412027Sjungma@eit.uni-kl.de
27512027Sjungma@eit.uni-kl.de// Taf!
276