gem5  v21.1.0.2
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"
31 #include "systemc/core/kernel.hh"
38 #include "systemc/ext/core/sc_module.hh" // for sc_gen_unique_name
40 
41 namespace sc_gem5
42 {
43 
44 class ClockTick : public ScEvent
45 {
46  private:
48  std::string name;
51 
52  public:
53  ClockTick(::sc_core::sc_clock *clock, bool to,
55  ScEvent([this]() { tick(); }),
56  _period(_period), name(clock->name()), p(nullptr),
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);
69  scheduler.reg(p);
70  }
71 
73  {
74  if (scheduled())
75  scheduler.deschedule(this);
76  if (p)
77  p->popListNode();
78  }
79 
80  void
81  tick()
82  {
83  scheduler.schedule(this, _period);
84  p->ready();
85  }
86 };
87 
88 };
89 
90 namespace 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 
98 sc_clock::sc_clock(const char *name) :
99  sc_clock(name, sc_time(1.0, SC_NS), 0.5, SC_ZERO_TIME, true)
100 {}
101 
102 sc_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) + "'";
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) + "'";
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) + "'";
128  }
129 
130  _gem5UpEdge = new ::sc_gem5::ClockTick(this, true, period);
131  _gem5DownEdge = new ::sc_gem5::ClockTick(this, false, period);
132 }
133 
134 sc_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 
140 sc_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 
147 sc_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 
154 {
155  if (_gem5UpEdge->scheduled())
157  if (_gem5DownEdge->scheduled())
159  delete _gem5UpEdge;
160  delete _gem5DownEdge;
161 }
162 
163 void
164 sc_clock::write(const bool &)
165 {
166  panic("write() called on sc_clock.");
167 }
168 
169 const sc_time &sc_clock::period() const { return _period; }
170 double sc_clock::duty_cycle() const { return _dutyCycle; }
171 const sc_time &sc_clock::start_time() const { return _startTime; }
172 bool sc_clock::posedge_first() const { return _posedgeFirst; }
173 
174 const sc_time &
176 {
177  return sc_time_stamp();
178 }
179 
180 void
182 {
185  if (_posedgeFirst) {
189  } else {
192  _startTime + _period * (1.0 - _dutyCycle));
193  }
194 }
195 
196 } // namespace sc_core
kernel.hh
sc_core::sc_clock::_startTime
sc_time _startTime
Definition: sc_clock.hh:96
sc_core::sc_clock::_dutyCycle
double _dutyCycle
Definition: sc_clock.hh:95
sc_gem5::Scheduler::reg
void reg(Process *p)
Definition: scheduler.cc:146
sc_core::sc_clock::duty_cycle
double duty_cycle() const
Definition: sc_clock.cc:170
sc_gem5::ClockTick::funcWrapper
ProcessMemberFuncWrapper<::sc_core::sc_clock > funcWrapper
Definition: sc_clock.cc:50
sc_core::sc_clock
Definition: sc_clock.hh:49
sc_core::SC_ID_CLOCK_PERIOD_ZERO_
const char SC_ID_CLOCK_PERIOD_ZERO_[]
Definition: messages.cc:35
sc_gem5::ClockTick::name
std::string name
Definition: sc_clock.cc:48
sc_gem5::Scheduler::deschedule
void deschedule(ScEvent *event)
Definition: scheduler.hh:280
sc_core::sc_clock::time_stamp
static const sc_time & time_stamp()
Definition: sc_clock.cc:175
sc_core::sc_clock::_posedgeFirst
bool _posedgeFirst
Definition: sc_clock.hh:97
sc_core::SC_ID_CLOCK_HIGH_TIME_ZERO_
const char SC_ID_CLOCK_HIGH_TIME_ZERO_[]
Definition: messages.cc:36
sc_core
Definition: messages.cc:31
sc_core::sc_time_unit
sc_time_unit
Definition: sc_time.hh:40
sc_core::sc_interface
Definition: sc_interface.hh:37
sc_gem5::ProcessMemberFuncWrapper
Definition: sc_process_handle.hh:50
sc_core::SC_ZERO_TIME
const sc_time SC_ZERO_TIME
Definition: sc_time.cc:290
messages.hh
sc_core::sc_signal
Definition: sc_signal.hh:272
sc_core::sc_clock::start_time
const sc_time & start_time() const
Definition: sc_clock.cc:171
sc_gem5::ClockTick::tick
void tick()
Definition: sc_clock.cc:81
sc_core::sc_clock::sc_clock
sc_clock()
Definition: sc_clock.cc:93
sc_core::sc_clock::tickUp
void tickUp()
Definition: sc_clock.hh:103
gem5::PowerISA::to
Bitfield< 25, 21 > to
Definition: types.hh:96
sc_core::sc_clock::period
const sc_time & period() const
Definition: sc_clock.cc:169
sc_core::SC_NS
@ SC_NS
Definition: sc_time.hh:43
sc_gem5::ClockTick::_period
::sc_core::sc_time _period
Definition: sc_clock.cc:47
sc_core::sc_clock::_period
sc_time _period
Definition: sc_clock.hh:94
SC_REPORT_ERROR
#define SC_REPORT_ERROR(msg_type, msg)
Definition: sc_report_handler.hh:127
sc_gem5::ClockTick
Definition: sc_clock.cc:44
sc_core::SC_ID_CLOCK_LOW_TIME_ZERO_
const char SC_ID_CLOCK_LOW_TIME_ZERO_[]
Definition: messages.cc:37
sc_gem5::ClockTick::~ClockTick
~ClockTick()
Definition: sc_clock.cc:72
sc_gem5::ListNode::popListNode
void popListNode()
Definition: list.hh:51
sc_main.hh
sc_core::sc_clock::before_end_of_elaboration
virtual void before_end_of_elaboration()
Definition: sc_clock.cc:181
sc_gem5::Method
Definition: process_types.hh:37
sc_core::sc_time
Definition: sc_time.hh:49
sched_event.hh
sc_core::sc_gen_unique_name
const char * sc_gen_unique_name(const char *seed)
Definition: sc_module.cc:820
sc_clock.hh
sc_gem5::Process
Definition: process.hh:62
name
const std::string & name()
Definition: trace.cc:49
sc_module.hh
sc_gem5::ScEvent::scheduled
bool scheduled()
Definition: sched_event.hh:78
sc_gem5::ClockTick::createProcess
void createProcess()
Definition: sc_clock.cc:65
sc_report_handler.hh
sc_gem5::Process::dontInitialize
bool dontInitialize()
Definition: process.hh:133
sc_gem5::ClockTick::ClockTick
ClockTick(::sc_core::sc_clock *clock, bool to, ::sc_core::sc_time _period)
Definition: sc_clock.cc:53
types.hh
sc_gem5::ClockTick::p
Process * p
Definition: sc_clock.cc:49
sc_core::sc_clock::tickDown
void tickDown()
Definition: sc_clock.hh:109
sc_core::sc_object::name
const char * name() const
Definition: sc_object.cc:44
sc_core::sc_clock::~sc_clock
virtual ~sc_clock()
Definition: sc_clock.cc:153
process_types.hh
logging.hh
sc_gem5::Scheduler::schedule
void schedule(ScEvent *event, const ::sc_core::sc_time &delay)
Definition: scheduler.hh:253
sc_gem5
Definition: sc_clock.cc:41
sc_core::sc_clock::write
virtual void write(const bool &)
Definition: sc_clock.cc:164
sc_gem5::scheduler
Scheduler scheduler
Definition: scheduler.cc:494
sc_core::sc_clock::posedge_first
bool posedge_first() const
Definition: sc_clock.cc:172
sc_core::sc_clock::_gem5UpEdge
::sc_gem5::ClockTick * _gem5UpEdge
Definition: sc_clock.hh:99
sc_core::sc_time_stamp
const sc_time & sc_time_stamp()
Definition: sc_main.cc:127
sc_gem5::ScEvent
Definition: sched_event.hh:43
scheduler.hh
sc_gem5::Process::ready
void ready()
Definition: process.cc:355
sc_core::sc_clock::_gem5DownEdge
::sc_gem5::ClockTick * _gem5DownEdge
Definition: sc_clock.hh:100
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177
eventq.hh

Generated on Tue Sep 21 2021 12:25:49 for gem5 by doxygen 1.8.17