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"
| 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"
|
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 85{ 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 96sc_clock::sc_clock(const char *name, const sc_time &period, 97 double duty_cycle, const sc_time &start_time, 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) 102{ 103 _gem5UpEdge = new ::sc_gem5::ClockTick(this, true, period); 104 _gem5DownEdge = new ::sc_gem5::ClockTick(this, false, period); 105} 106 107sc_clock::sc_clock(const char *name, double period_v, sc_time_unit period_tu, 108 double duty_cycle) : 109 sc_clock(name, sc_time(period_v, period_tu), duty_cycle, SC_ZERO_TIME, 110 true) 111{} 112 113sc_clock::sc_clock(const char *name, double period_v, sc_time_unit period_tu, 114 double duty_cycle, double start_time_v, 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{} 119 120sc_clock::sc_clock(const char *name, double period, double duty_cycle, 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() 127{ 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; 134} 135 136void 137sc_clock::write(const bool &) 138{ 139 panic("write() called on sc_clock."); 140} 141 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; } 146 147const sc_time & 148sc_clock::time_stamp() 149{ 150 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 151 return *(const sc_time *)nullptr; 152} 153 154void 155sc_clock::before_end_of_elaboration() 156{ 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 } 166} 167 168} // namespace sc_core
| 66 scheduler.dontInitialize(p); 67 } 68 69 ~ClockTick() 70 { 71 if (scheduled()) 72 scheduler.deschedule(this); 73 p->popListNode(); 74 } 75 76 void 77 tick() 78 { 79 scheduler.schedule(this, _period); 80 p->ready(); 81 } 82}; 83 84}; 85 86namespace sc_core 87{ 88 89sc_clock::sc_clock() : 90 sc_clock(sc_gen_unique_name("clock"), sc_time(1.0, SC_NS), 91 0.5, SC_ZERO_TIME, true) 92{} 93 94sc_clock::sc_clock(const char *name) : 95 sc_clock(name, sc_time(1.0, SC_NS), 0.5, SC_ZERO_TIME, true) 96{} 97 98sc_clock::sc_clock(const char *name, const sc_time &period, 99 double duty_cycle, const sc_time &start_time, 100 bool posedge_first) : 101 sc_interface(), sc_signal<bool>(name, posedge_first ? false : true), 102 _period(period), _dutyCycle(duty_cycle), _startTime(start_time), 103 _posedgeFirst(posedge_first) 104{ 105 _gem5UpEdge = new ::sc_gem5::ClockTick(this, true, period); 106 _gem5DownEdge = new ::sc_gem5::ClockTick(this, false, period); 107} 108 109sc_clock::sc_clock(const char *name, double period_v, sc_time_unit period_tu, 110 double duty_cycle) : 111 sc_clock(name, sc_time(period_v, period_tu), duty_cycle, SC_ZERO_TIME, 112 true) 113{} 114 115sc_clock::sc_clock(const char *name, double period_v, sc_time_unit period_tu, 116 double duty_cycle, double start_time_v, 117 sc_time_unit start_time_tu, bool posedge_first) : 118 sc_clock(name, sc_time(period_v, period_tu), duty_cycle, 119 sc_time(start_time_v, start_time_tu), posedge_first) 120{} 121 122sc_clock::sc_clock(const char *name, double period, double duty_cycle, 123 double start_time, bool posedge_first) : 124 sc_clock(name, sc_time(period, true), duty_cycle, 125 sc_time(start_time, true), posedge_first) 126{} 127 128sc_clock::~sc_clock() 129{ 130 if (_gem5UpEdge->scheduled()) 131 ::sc_gem5::scheduler.deschedule(_gem5UpEdge); 132 if (_gem5DownEdge->scheduled()) 133 ::sc_gem5::scheduler.deschedule(_gem5DownEdge); 134 delete _gem5UpEdge; 135 delete _gem5DownEdge; 136} 137 138void 139sc_clock::write(const bool &) 140{ 141 panic("write() called on sc_clock."); 142} 143 144const sc_time &sc_clock::period() const { return _period; } 145double sc_clock::duty_cycle() const { return _dutyCycle; } 146const sc_time &sc_clock::start_time() const { return _startTime; } 147bool sc_clock::posedge_first() const { return _posedgeFirst; } 148 149const sc_time & 150sc_clock::time_stamp() 151{ 152 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 153 return *(const sc_time *)nullptr; 154} 155 156void 157sc_clock::before_end_of_elaboration() 158{ 159 if (_posedgeFirst) { 160 ::sc_gem5::scheduler.schedule(_gem5UpEdge, _startTime); 161 ::sc_gem5::scheduler.schedule(_gem5DownEdge, 162 _startTime + _period * _dutyCycle); 163 } else { 164 ::sc_gem5::scheduler.schedule(_gem5DownEdge, _startTime); 165 ::sc_gem5::scheduler.schedule(_gem5UpEdge, 166 _startTime + _period * (1.0 - _dutyCycle)); 167 } 168} 169 170} // namespace sc_core
|