gem5 v24.0.0.0
Loading...
Searching...
No Matches
sc_clock.cc
Go to the documentation of this file.
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "base/logging.hh"
29#include "base/types.hh"
30#include "sim/eventq.hh"
38#include "systemc/ext/core/sc_module.hh" // for sc_gen_unique_name
40
41namespace sc_gem5
42{
43
44class ClockTick : public ScEvent
45{
46 private:
48 std::string name;
51
52 public:
55 ScEvent([this]() { tick(); }),
56 _period(_period), name(clock->name()), p(nullptr),
58 &::sc_core::sc_clock::tickDown)
59 {
60 name += std::string(to ? "_posedge_action" : "_negedge_action");
62 }
63
64 void
66 {
67 p = new Method(name.c_str(), &funcWrapper, true);
68 p->dontInitialize(true);
70 }
71
73 {
74 if (scheduled())
76 if (p)
77 p->popListNode();
78 }
79
80 void
82 {
84 p->ready();
85 }
86};
87
88};
89
90namespace sc_core
91{
92
94 sc_clock(sc_gen_unique_name("clock"), sc_time(1.0, SC_NS),
95 0.5, SC_ZERO_TIME, true)
96{}
97
99 sc_clock(name, sc_time(1.0, SC_NS), 0.5, SC_ZERO_TIME, true)
100{}
101
102sc_clock::sc_clock(const char *name, const sc_time &period,
103 double duty_cycle, const sc_time &start_time,
104 bool posedge_first) :
105 sc_interface(), sc_signal<bool>(name, posedge_first ? false : true),
106 _period(period), _dutyCycle(duty_cycle), _startTime(start_time),
107 _posedgeFirst(posedge_first)
108{
109 if (period == SC_ZERO_TIME) {
110 std::string msg =
111 "increase the period: clock '" +
112 std::string(name) + "'";
113 SC_REPORT_ERROR(SC_ID_CLOCK_PERIOD_ZERO_, msg.c_str());
114 }
115
116 if (duty_cycle * period == SC_ZERO_TIME) {
117 std::string msg =
118 "increase the period or increase the duty cycle: clock '" +
119 std::string(name) + "'";
120 SC_REPORT_ERROR(SC_ID_CLOCK_HIGH_TIME_ZERO_, msg.c_str());
121 }
122
123 if (duty_cycle * period == period) {
124 std::string msg =
125 "increase the period or decrease the duty cycle: clock '" +
126 std::string(name) + "'";
127 SC_REPORT_ERROR(SC_ID_CLOCK_LOW_TIME_ZERO_, msg.c_str());
128 }
129
130 _gem5UpEdge = new ::sc_gem5::ClockTick(this, true, period);
131 _gem5DownEdge = new ::sc_gem5::ClockTick(this, false, period);
132}
133
134sc_clock::sc_clock(const char *name, double period_v, sc_time_unit period_tu,
135 double duty_cycle) :
136 sc_clock(name, sc_time(period_v, period_tu), duty_cycle, SC_ZERO_TIME,
137 true)
138{}
139
140sc_clock::sc_clock(const char *name, double period_v, sc_time_unit period_tu,
141 double duty_cycle, double start_time_v,
142 sc_time_unit start_time_tu, bool posedge_first) :
143 sc_clock(name, sc_time(period_v, period_tu), duty_cycle,
144 sc_time(start_time_v, start_time_tu), posedge_first)
145{}
146
147sc_clock::sc_clock(const char *name, double period, double duty_cycle,
148 double start_time, bool posedge_first) :
149 sc_clock(name, sc_time(period, true), duty_cycle,
150 sc_time(start_time, true), posedge_first)
151{}
152
162
163void
164sc_clock::write(const bool &)
165{
166 panic("write() called on sc_clock.");
167}
168
169const sc_time &sc_clock::period() const { return _period; }
170double sc_clock::duty_cycle() const { return _dutyCycle; }
171const sc_time &sc_clock::start_time() const { return _startTime; }
173
174const sc_time &
176{
177 return sc_time_stamp();
178}
179
180void
195
196} // namespace sc_core
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
bool posedge_first() const
Definition sc_clock.cc:172
::sc_gem5::ClockTick * _gem5UpEdge
Definition sc_clock.hh:99
::sc_gem5::ClockTick * _gem5DownEdge
Definition sc_clock.hh:100
static const sc_time & time_stamp()
Definition sc_clock.cc:175
const sc_time & period() const
Definition sc_clock.cc:169
sc_time _startTime
Definition sc_clock.hh:96
double duty_cycle() const
Definition sc_clock.cc:170
virtual ~sc_clock()
Definition sc_clock.cc:153
virtual void before_end_of_elaboration()
Definition sc_clock.cc:181
const sc_time & start_time() const
Definition sc_clock.cc:171
virtual void write(const bool &)
Definition sc_clock.cc:164
ProcessMemberFuncWrapper<::sc_core::sc_clock > funcWrapper
Definition sc_clock.cc:50
std::string name
Definition sc_clock.cc:48
::sc_core::sc_time _period
Definition sc_clock.cc:47
ClockTick(::sc_core::sc_clock *clock, bool to, ::sc_core::sc_time _period)
Definition sc_clock.cc:53
bool dontInitialize()
Definition process.hh:133
void deschedule(ScEvent *event)
Definition scheduler.hh:280
void schedule(ScEvent *event, const ::sc_core::sc_time &delay)
Definition scheduler.hh:253
void reg(Process *p)
Definition scheduler.cc:146
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
sc_time_unit
Definition sc_time.hh:40
const char * sc_gen_unique_name(const char *seed)
Definition sc_module.cc:820
const sc_time & sc_time_stamp()
Definition sc_main.cc:127
Scheduler scheduler
Definition scheduler.cc:494
#define SC_REPORT_ERROR(msg_type, msg)
void popListNode()
Definition list.hh:51
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0