gem5  v20.1.0.0
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/core.hh"
31 #include "sim/eventq.hh"
32 #include "systemc/core/kernel.hh"
39 #include "systemc/ext/core/sc_module.hh" // for sc_gen_unique_name
41 
42 namespace sc_gem5
43 {
44 
45 class ClockTick : public ScEvent
46 {
47  private:
49  std::string name;
52 
53  public:
54  ClockTick(::sc_core::sc_clock *clock, bool to,
56  ScEvent([this]() { tick(); }),
57  _period(_period), name(clock->basename()), p(nullptr),
58  funcWrapper(clock, to ? &::sc_core::sc_clock::tickUp :
60  {
61  name += std::string(to ? "_posedge_action" : "_negedge_action");
63  }
64 
65  void
67  {
68  p = new Method(name.c_str(), &funcWrapper, true);
69  p->dontInitialize(true);
70  scheduler.reg(p);
71  }
72 
74  {
75  if (scheduled())
76  scheduler.deschedule(this);
77  if (p)
78  p->popListNode();
79  }
80 
81  void
82  tick()
83  {
84  scheduler.schedule(this, _period);
85  p->ready();
86  }
87 };
88 
89 };
90 
91 namespace sc_core
92 {
93 
95  sc_clock(sc_gen_unique_name("clock"), sc_time(1.0, SC_NS),
96  0.5, SC_ZERO_TIME, true)
97 {}
98 
99 sc_clock::sc_clock(const char *name) :
100  sc_clock(name, sc_time(1.0, SC_NS), 0.5, SC_ZERO_TIME, true)
101 {}
102 
103 sc_clock::sc_clock(const char *name, const sc_time &period,
104  double duty_cycle, const sc_time &start_time,
105  bool posedge_first) :
106  sc_interface(), sc_signal<bool>(name, posedge_first ? false : true),
107  _period(period), _dutyCycle(duty_cycle), _startTime(start_time),
108  _posedgeFirst(posedge_first)
109 {
110  if (period == SC_ZERO_TIME) {
111  std::string msg =
112  "increase the period: clock '" +
113  std::string(name) + "'";
115  }
116 
117  if (duty_cycle * period == SC_ZERO_TIME) {
118  std::string msg =
119  "increase the period or increase the duty cycle: clock '" +
120  std::string(name) + "'";
122  }
123 
124  if (duty_cycle * period == period) {
125  std::string msg =
126  "increase the period or decrease the duty cycle: clock '" +
127  std::string(name) + "'";
129  }
130 
131  _gem5UpEdge = new ::sc_gem5::ClockTick(this, true, period);
132  _gem5DownEdge = new ::sc_gem5::ClockTick(this, false, period);
133 }
134 
135 sc_clock::sc_clock(const char *name, double period_v, sc_time_unit period_tu,
136  double duty_cycle) :
137  sc_clock(name, sc_time(period_v, period_tu), duty_cycle, SC_ZERO_TIME,
138  true)
139 {}
140 
141 sc_clock::sc_clock(const char *name, double period_v, sc_time_unit period_tu,
142  double duty_cycle, double start_time_v,
143  sc_time_unit start_time_tu, bool posedge_first) :
144  sc_clock(name, sc_time(period_v, period_tu), duty_cycle,
145  sc_time(start_time_v, start_time_tu), posedge_first)
146 {}
147 
148 sc_clock::sc_clock(const char *name, double period, double duty_cycle,
149  double start_time, bool posedge_first) :
150  sc_clock(name, sc_time(period, true), duty_cycle,
151  sc_time(start_time, true), posedge_first)
152 {}
153 
155 {
156  if (_gem5UpEdge->scheduled())
158  if (_gem5DownEdge->scheduled())
160  delete _gem5UpEdge;
161  delete _gem5DownEdge;
162 }
163 
164 void
165 sc_clock::write(const bool &)
166 {
167  panic("write() called on sc_clock.");
168 }
169 
170 const sc_time &sc_clock::period() const { return _period; }
171 double sc_clock::duty_cycle() const { return _dutyCycle; }
172 const sc_time &sc_clock::start_time() const { return _startTime; }
173 bool sc_clock::posedge_first() const { return _posedgeFirst; }
174 
175 const sc_time &
177 {
178  return sc_time_stamp();
179 }
180 
181 void
183 {
186  if (_posedgeFirst) {
190  } else {
193  _startTime + _period * (1.0 - _dutyCycle));
194  }
195 }
196 
197 } // namespace sc_core
sc_gem5::Scheduler::reg
void reg(Process *p)
Definition: scheduler.cc:147
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_core::sc_clock::duty_cycle
double duty_cycle() const
Definition: sc_clock.cc:171
sc_gem5::ClockTick::funcWrapper
ProcessMemberFuncWrapper<::sc_core::sc_clock > funcWrapper
Definition: sc_clock.cc:51
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:49
sc_gem5::Scheduler::deschedule
void deschedule(ScEvent *event)
Definition: scheduler.hh:263
sc_core::sc_clock::time_stamp
static const sc_time & time_stamp()
Definition: sc_clock.cc:176
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:172
sc_gem5::ClockTick::tick
void tick()
Definition: sc_clock.cc:82
sc_core::sc_clock::sc_clock
sc_clock()
Definition: sc_clock.cc:94
sc_core::sc_clock::tickUp
void tickUp()
Definition: sc_clock.hh:103
sc_core::sc_clock::period
const sc_time & period() const
Definition: sc_clock.cc:170
sc_core::SC_NS
@ SC_NS
Definition: sc_time.hh:43
sc_gem5::ClockTick::_period
::sc_core::sc_time _period
Definition: sc_clock.cc:48
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:45
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:73
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:182
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
core.hh
sc_gem5::Process
Definition: process.hh:62
name
const std::string & name()
Definition: trace.cc:50
sc_module.hh
sc_gem5::ScEvent::scheduled
bool scheduled()
Definition: sched_event.hh:78
sc_gem5::ClockTick::createProcess
void createProcess()
Definition: sc_clock.cc:66
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:54
types.hh
sc_gem5::ClockTick::p
Process * p
Definition: sc_clock.cc:50
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:154
process_types.hh
logging.hh
sc_gem5::Scheduler::schedule
void schedule(ScEvent *event, const ::sc_core::sc_time &delay)
Definition: scheduler.hh:238
sc_gem5
Definition: sc_clock.cc:42
sc_core::sc_clock::write
virtual void write(const bool &)
Definition: sc_clock.cc:165
sc_gem5::scheduler
Scheduler scheduler
Definition: scheduler.cc:489
sc_core::sc_clock::posedge_first
bool posedge_first() const
Definition: sc_clock.cc:173
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:128
sc_gem5::ScEvent
Definition: sched_event.hh:43
scheduler.hh
sc_core::sc_clock::_gem5DownEdge
::sc_gem5::ClockTick * _gem5DownEdge
Definition: sc_clock.hh:100
sc_gem5::Process::ready
void ready()
Definition: process.cc:355
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
eventq.hh

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17