sc_clock.hh revision 13276
15390SN/A/*
25445SN/A * Copyright 2018 Google, Inc.
35390SN/A *
45390SN/A * Redistribution and use in source and binary forms, with or without
55390SN/A * modification, are permitted provided that the following conditions are
65390SN/A * met: redistributions of source code must retain the above copyright
75390SN/A * notice, this list of conditions and the following disclaimer;
85390SN/A * redistributions in binary form must reproduce the above copyright
95390SN/A * notice, this list of conditions and the following disclaimer in the
105390SN/A * documentation and/or other materials provided with the distribution;
115390SN/A * neither the name of the copyright holders nor the names of its
125390SN/A * contributors may be used to endorse or promote products derived from
135390SN/A * this software without specific prior written permission.
145390SN/A *
155390SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
165390SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
175390SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
185390SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
195390SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
205390SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
215390SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
225390SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
235390SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
245390SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
255390SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
265390SN/A *
275390SN/A * Authors: Gabe Black
285390SN/A */
295390SN/A
305390SN/A#ifndef __SYSTEMC_EXT_CHANNEL_SC_CLOCK_HH__
315390SN/A#define __SYSTEMC_EXT_CHANNEL_SC_CLOCK_HH__
325445SN/A
335636Sgblack@eecs.umich.edu#include "../core/sc_time.hh"
345636Sgblack@eecs.umich.edu#include "sc_signal.hh"
355636Sgblack@eecs.umich.edu
365390SN/Anamespace sc_gem5
375390SN/A{
385390SN/A
395390SN/Aclass ClockTick;
405390SN/A
415636Sgblack@eecs.umich.edu} // namespace sc_gem5
425390SN/A
435636Sgblack@eecs.umich.edunamespace sc_core
445636Sgblack@eecs.umich.edu{
455445SN/A
465445SN/Atemplate <class T>
475445SN/Aclass sc_in;
485445SN/A
495445SN/Aclass sc_time;
505390SN/A
515390SN/Aclass sc_clock : public sc_signal<bool>
525390SN/A{
535390SN/A  public:
545390SN/A    sc_clock();
555390SN/A    explicit sc_clock(const char *name);
565636Sgblack@eecs.umich.edu
575390SN/A    sc_clock(const char *name, const sc_time &period,
585390SN/A             double duty_cycle=0.5, const sc_time &start_time=SC_ZERO_TIME,
595445SN/A             bool posedge_first=true);
605445SN/A
615445SN/A    sc_clock(const char *name, double period_v, sc_time_unit period_tu,
625445SN/A             double duty_cycle=0.5);
635445SN/A
645445SN/A    sc_clock(const char *name, double period_v, sc_time_unit period_tu,
655445SN/A             double duty_cycle, double start_time_v,
665445SN/A             sc_time_unit start_time_tu, bool posedge_first=true);
675445SN/A
685636Sgblack@eecs.umich.edu    // Deprecated.
695445SN/A    sc_clock(const char *name, double period, double duty_cycle=0.5,
705390SN/A             double start_time=0.0, bool posedge_first=true);
715390SN/A
725636Sgblack@eecs.umich.edu    virtual ~sc_clock();
735636Sgblack@eecs.umich.edu
745636Sgblack@eecs.umich.edu    virtual void write(const bool &);
755636Sgblack@eecs.umich.edu
765636Sgblack@eecs.umich.edu    const sc_time &period() const;
775636Sgblack@eecs.umich.edu    double duty_cycle() const;
78    const sc_time &start_time() const;
79    bool posedge_first() const;
80
81    // Nonstandard
82    static const sc_time &time_stamp();
83
84    virtual const char *kind() const { return "sc_clock"; }
85
86  protected:
87    virtual void before_end_of_elaboration();
88
89  private:
90    friend class ::sc_gem5::ClockTick;
91
92    // Disabled
93    sc_clock(const sc_clock &) : sc_interface(), sc_signal<bool>() {}
94    sc_clock &operator = (const sc_clock &) { return *this; }
95
96    sc_time _period;
97    double _dutyCycle;
98    sc_time _startTime;
99    bool _posedgeFirst;
100
101    ::sc_gem5::ClockTick *_gem5UpEdge;
102    ::sc_gem5::ClockTick *_gem5DownEdge;
103
104    void
105    tickUp()
106    {
107        m_new_val = true;
108        request_update();
109    }
110    void
111    tickDown()
112    {
113        m_new_val = false;
114        request_update();
115    }
116};
117
118typedef sc_in<bool> sc_in_clk;
119
120// Deprecated
121typedef sc_inout<bool> sc_inout_clk;
122typedef sc_out<bool> sc_out_clk;
123
124} // namespace sc_core
125
126#endif  //__SYSTEMC_EXT_CHANNEL_SC_CLOCK_HH__
127