30a31,36
> #include "base/types.hh"
> #include "sim/core.hh"
> #include "sim/eventq.hh"
> #include "systemc/core/kernel.hh"
> #include "systemc/core/sched_event.hh"
> #include "systemc/core/scheduler.hh"
34c40
< namespace sc_core
---
> namespace sc_gem5
37,38c43
< sc_clock::sc_clock() :
< sc_interface(), sc_signal<bool>(sc_gen_unique_name("clock"))
---
> class ClockTick : public ScEvent
40,41c45,51
< warn("%s not implemented.\n", __PRETTY_FUNCTION__);
< }
---
> private:
> ::sc_core::sc_clock *clock;
> ::sc_core::sc_time _period;
> std::string _name;
> Process *p;
> ProcessMemberFuncWrapper<::sc_core::sc_clock> funcWrapper;
> std::string _procName;
43c53,84
< sc_clock::sc_clock(const char *name) : sc_interface(), sc_signal<bool>(name)
---
> public:
> ClockTick(::sc_core::sc_clock *clock, bool to,
> ::sc_core::sc_time _period) :
> ScEvent([this]() { tick(); }),
> clock(clock), _period(_period), _name(clock->name()),
> funcWrapper(clock, to ? &::sc_core::sc_clock::tickUp :
> &::sc_core::sc_clock::tickDown)
> {
> _name += (to ? ".up_tick" : ".down_tick");
> _procName = _name + ".p";
> p = newMethodProcess(_procName.c_str(), &funcWrapper);
> scheduler.dontInitialize(p);
> }
>
> ~ClockTick()
> {
> if (scheduled())
> scheduler.deschedule(this);
> p->popListNode();
> }
>
> void
> tick()
> {
> scheduler.schedule(this, _period);
> p->ready();
> }
> };
>
> };
>
> namespace sc_core
45,46d85
< warn("%s not implemented.\n", __PRETTY_FUNCTION__);
< }
47a87,95
> sc_clock::sc_clock() :
> sc_clock(sc_gen_unique_name("clock"), sc_time(1.0, SC_NS),
> 0.5, SC_ZERO_TIME, true)
> {}
>
> sc_clock::sc_clock(const char *name) :
> sc_clock(name, sc_time(1.0, SC_NS), 0.5, SC_ZERO_TIME, true)
> {}
>
50c98,101
< bool posedge_first)
---
> bool posedge_first) :
> sc_interface(), sc_signal<bool>(name, posedge_first ? false : true),
> _period(period), _dutyCycle(duty_cycle), _startTime(start_time),
> _posedgeFirst(posedge_first)
52c103,104
< warn("%s not implemented.\n", __PRETTY_FUNCTION__);
---
> _gem5UpEdge = new ::sc_gem5::ClockTick(this, true, period);
> _gem5DownEdge = new ::sc_gem5::ClockTick(this, false, period);
56,59c108,111
< double duty_cycle)
< {
< warn("%s not implemented.\n", __PRETTY_FUNCTION__);
< }
---
> double duty_cycle) :
> sc_clock(name, sc_time(period_v, period_tu), duty_cycle, SC_ZERO_TIME,
> true)
> {}
63,66c115,118
< sc_time_unit start_time_tu, bool posedge_first)
< {
< warn("%s not implemented.\n", __PRETTY_FUNCTION__);
< }
---
> sc_time_unit start_time_tu, bool posedge_first) :
> sc_clock(name, sc_time(period_v, period_tu), duty_cycle,
> sc_time(start_time_v, start_time_tu), posedge_first)
> {}
69c121,126
< double start_time, bool posedge_first)
---
> double start_time, bool posedge_first) :
> sc_clock(name, sc_time(period, true), duty_cycle,
> sc_time(start_time, true), posedge_first)
> {}
>
> sc_clock::~sc_clock()
71c128,133
< warn("%s not implemented.\n", __PRETTY_FUNCTION__);
---
> if (_gem5UpEdge->scheduled())
> ::sc_gem5::scheduler.deschedule(_gem5UpEdge);
> if (_gem5DownEdge->scheduled())
> ::sc_gem5::scheduler.deschedule(_gem5DownEdge);
> delete _gem5UpEdge;
> delete _gem5DownEdge;
74,75d135
< sc_clock::~sc_clock() {}
<
79c139
< warn("%s not implemented.\n", __PRETTY_FUNCTION__);
---
> panic("write() called on sc_clock.");
82,87c142,145
< const sc_time &
< sc_clock::period() const
< {
< warn("%s not implemented.\n", __PRETTY_FUNCTION__);
< return *(const sc_time *)nullptr;
< }
---
> const sc_time &sc_clock::period() const { return _period; }
> double sc_clock::duty_cycle() const { return _dutyCycle; }
> const sc_time &sc_clock::start_time() const { return _startTime; }
> bool sc_clock::posedge_first() const { return _posedgeFirst; }
89,95d146
< double
< sc_clock::duty_cycle() const
< {
< warn("%s not implemented.\n", __PRETTY_FUNCTION__);
< return 0.0;
< }
<
97c148
< sc_clock::start_time() const
---
> sc_clock::time_stamp()
103,104c154,155
< bool
< sc_clock::posedge_first() const
---
> void
> sc_clock::before_end_of_elaboration()
106,107c157,165
< warn("%s not implemented.\n", __PRETTY_FUNCTION__);
< return false;
---
> if (_posedgeFirst) {
> ::sc_gem5::scheduler.schedule(_gem5UpEdge, _startTime);
> ::sc_gem5::scheduler.schedule(_gem5DownEdge,
> _startTime + _period * _dutyCycle);
> } else {
> ::sc_gem5::scheduler.schedule(_gem5DownEdge, _startTime);
> ::sc_gem5::scheduler.schedule(_gem5UpEdge,
> _startTime + _period * (1.0 - _dutyCycle));
> }
110,120d167
< const sc_time &
< sc_clock::time_stamp()
< {
< warn("%s not implemented.\n", __PRETTY_FUNCTION__);
< return *(const sc_time *)nullptr;
< }
<
< const char *sc_clock::kind() const { return "sc_clock"; }
<
< void sc_clock::before_end_of_elaboration() {}
<