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 --- 32 unchanged lines hidden (view full) --- 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 scheduler.reg(p); 70 scheduler.dontInitialize(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 } --- 69 unchanged lines hidden (view full) --- 156{ 157 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 158 return *(const sc_time *)nullptr; 159} 160 161void 162sc_clock::before_end_of_elaboration() 163{ |
164 _gem5UpEdge->createProcess(); 165 _gem5DownEdge->createProcess(); |
166 if (_posedgeFirst) { 167 ::sc_gem5::scheduler.schedule(_gem5UpEdge, _startTime); 168 ::sc_gem5::scheduler.schedule(_gem5DownEdge, 169 _startTime + _period * _dutyCycle); 170 } else { 171 ::sc_gem5::scheduler.schedule(_gem5DownEdge, _startTime); 172 ::sc_gem5::scheduler.schedule(_gem5UpEdge, 173 _startTime + _period * (1.0 - _dutyCycle)); 174 } 175} 176 177} // namespace sc_core |