sc_clock.cc (12931:2dd5b061490b) sc_clock.cc (13065:eec7d19ac479)
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

--- 14 unchanged lines hidden (view full) ---

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 * Authors: Gabe Black
28 */
29
30#include "base/logging.hh"
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

--- 14 unchanged lines hidden (view full) ---

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 * Authors: Gabe Black
28 */
29
30#include "base/logging.hh"
31#include "base/types.hh"
32#include "sim/core.hh"
33#include "sim/eventq.hh"
34#include "systemc/core/kernel.hh"
35#include "systemc/core/sched_event.hh"
36#include "systemc/core/scheduler.hh"
31#include "systemc/ext/channel/sc_clock.hh"
32#include "systemc/ext/core/sc_module.hh" // for sc_gen_unique_name
33
37#include "systemc/ext/channel/sc_clock.hh"
38#include "systemc/ext/core/sc_module.hh" // for sc_gen_unique_name
39
34namespace sc_core
40namespace sc_gem5
35{
36
41{
42
37sc_clock::sc_clock() :
38 sc_interface(), sc_signal<bool>(sc_gen_unique_name("clock"))
43class ClockTick : public ScEvent
39{
44{
40 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
41}
45 private:
46 ::sc_core::sc_clock *clock;
47 ::sc_core::sc_time _period;
48 std::string _name;
49 Process *p;
50 ProcessMemberFuncWrapper<::sc_core::sc_clock> funcWrapper;
51 std::string _procName;
42
52
43sc_clock::sc_clock(const char *name) : sc_interface(), sc_signal<bool>(name)
53 public:
54 ClockTick(::sc_core::sc_clock *clock, bool to,
55 ::sc_core::sc_time _period) :
56 ScEvent([this]() { tick(); }),
57 clock(clock), _period(_period), _name(clock->name()),
58 funcWrapper(clock, to ? &::sc_core::sc_clock::tickUp :
59 &::sc_core::sc_clock::tickDown)
60 {
61 _name += (to ? ".up_tick" : ".down_tick");
62 _procName = _name + ".p";
63 p = newMethodProcess(_procName.c_str(), &funcWrapper);
64 scheduler.dontInitialize(p);
65 }
66
67 ~ClockTick()
68 {
69 if (scheduled())
70 scheduler.deschedule(this);
71 p->popListNode();
72 }
73
74 void
75 tick()
76 {
77 scheduler.schedule(this, _period);
78 p->ready();
79 }
80};
81
82};
83
84namespace sc_core
44{
85{
45 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
46}
47
86
87sc_clock::sc_clock() :
88 sc_clock(sc_gen_unique_name("clock"), sc_time(1.0, SC_NS),
89 0.5, SC_ZERO_TIME, true)
90{}
91
92sc_clock::sc_clock(const char *name) :
93 sc_clock(name, sc_time(1.0, SC_NS), 0.5, SC_ZERO_TIME, true)
94{}
95
48sc_clock::sc_clock(const char *name, const sc_time &period,
49 double duty_cycle, const sc_time &start_time,
96sc_clock::sc_clock(const char *name, const sc_time &period,
97 double duty_cycle, const sc_time &start_time,
50 bool posedge_first)
98 bool posedge_first) :
99 sc_interface(), sc_signal<bool>(name, posedge_first ? false : true),
100 _period(period), _dutyCycle(duty_cycle), _startTime(start_time),
101 _posedgeFirst(posedge_first)
51{
102{
52 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
103 _gem5UpEdge = new ::sc_gem5::ClockTick(this, true, period);
104 _gem5DownEdge = new ::sc_gem5::ClockTick(this, false, period);
53}
54
55sc_clock::sc_clock(const char *name, double period_v, sc_time_unit period_tu,
105}
106
107sc_clock::sc_clock(const char *name, double period_v, sc_time_unit period_tu,
56 double duty_cycle)
57{
58 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
59}
108 double duty_cycle) :
109 sc_clock(name, sc_time(period_v, period_tu), duty_cycle, SC_ZERO_TIME,
110 true)
111{}
60
61sc_clock::sc_clock(const char *name, double period_v, sc_time_unit period_tu,
62 double duty_cycle, double start_time_v,
112
113sc_clock::sc_clock(const char *name, double period_v, sc_time_unit period_tu,
114 double duty_cycle, double start_time_v,
63 sc_time_unit start_time_tu, bool posedge_first)
64{
65 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
66}
115 sc_time_unit start_time_tu, bool posedge_first) :
116 sc_clock(name, sc_time(period_v, period_tu), duty_cycle,
117 sc_time(start_time_v, start_time_tu), posedge_first)
118{}
67
68sc_clock::sc_clock(const char *name, double period, double duty_cycle,
119
120sc_clock::sc_clock(const char *name, double period, double duty_cycle,
69 double start_time, bool posedge_first)
121 double start_time, bool posedge_first) :
122 sc_clock(name, sc_time(period, true), duty_cycle,
123 sc_time(start_time, true), posedge_first)
124{}
125
126sc_clock::~sc_clock()
70{
127{
71 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
128 if (_gem5UpEdge->scheduled())
129 ::sc_gem5::scheduler.deschedule(_gem5UpEdge);
130 if (_gem5DownEdge->scheduled())
131 ::sc_gem5::scheduler.deschedule(_gem5DownEdge);
132 delete _gem5UpEdge;
133 delete _gem5DownEdge;
72}
73
134}
135
74sc_clock::~sc_clock() {}
75
76void
77sc_clock::write(const bool &)
78{
136void
137sc_clock::write(const bool &)
138{
79 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
139 panic("write() called on sc_clock.");
80}
81
140}
141
82const sc_time &
83sc_clock::period() const
84{
85 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
86 return *(const sc_time *)nullptr;
87}
142const sc_time &sc_clock::period() const { return _period; }
143double sc_clock::duty_cycle() const { return _dutyCycle; }
144const sc_time &sc_clock::start_time() const { return _startTime; }
145bool sc_clock::posedge_first() const { return _posedgeFirst; }
88
146
89double
90sc_clock::duty_cycle() const
91{
92 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
93 return 0.0;
94}
95
96const sc_time &
147const sc_time &
97sc_clock::start_time() const
148sc_clock::time_stamp()
98{
99 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
100 return *(const sc_time *)nullptr;
101}
102
149{
150 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
151 return *(const sc_time *)nullptr;
152}
153
103bool
104sc_clock::posedge_first() const
154void
155sc_clock::before_end_of_elaboration()
105{
156{
106 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
107 return false;
157 if (_posedgeFirst) {
158 ::sc_gem5::scheduler.schedule(_gem5UpEdge, _startTime);
159 ::sc_gem5::scheduler.schedule(_gem5DownEdge,
160 _startTime + _period * _dutyCycle);
161 } else {
162 ::sc_gem5::scheduler.schedule(_gem5DownEdge, _startTime);
163 ::sc_gem5::scheduler.schedule(_gem5UpEdge,
164 _startTime + _period * (1.0 - _dutyCycle));
165 }
108}
109
166}
167
110const sc_time &
111sc_clock::time_stamp()
112{
113 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
114 return *(const sc_time *)nullptr;
115}
116
117const char *sc_clock::kind() const { return "sc_clock"; }
118
119void sc_clock::before_end_of_elaboration() {}
120
121} // namespace sc_core
168} // namespace sc_core