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