scc  2022.4.0
SystemC components library
sc_clock_ext.h
1 /*******************************************************************************
2  * Copyright 2022 MINRES Technologies GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *******************************************************************************/
16 
17 #ifndef _SCC_SC_CLOCK_EXT_H_
18 #define _SCC_SC_CLOCK_EXT_H_
19 
20 #include <cci_configuration>
21 #include <sysc/communication/sc_clock.h>
22 
28 namespace scc {
32 struct sc_clock_ext : public sc_core::sc_clock {
33 
34  cci::cci_param<sc_core::sc_time> period;
35  cci::cci_param<double> duty_cycle;
36  cci::cci_param<sc_core::sc_time> initial_delay;
37 
38  sc_clock_ext(const char* name_, const sc_core::sc_time& period_, double duty_cycle_ = 0.5,
39  const sc_core::sc_time& start_time_ = sc_core::SC_ZERO_TIME, bool posedge_first_ = true)
40  : sc_core::sc_clock(name_, period_, duty_cycle_, start_time_, posedge_first_)
41  , period(get_cci_name(name_, "period"), period_, "The period of the generated clock")
42  , duty_cycle(get_cci_name(name_, "duty_cycle"), duty_cycle_, "The duty cycle of the generated clock")
43  , initial_delay(get_cci_name(name_, "start_time"), start_time_, "The start time of the generated clock") {
44  // period.register_post_write_callback(&sc_clock_ext::period_write_callback,this);
45  }
46 
47  virtual ~sc_clock_ext() = default;
48 
49 protected:
50  void end_of_elaboration() override {
51  init(period.get_value(), duty_cycle.get_value(), initial_delay.get_value(), m_posedge_first);
52  if(initial_delay.get_value() != m_start_time) {
53  if(m_posedge_first) {
54  m_next_posedge_event.cancel();
55  m_next_posedge_event.notify(initial_delay.get_value());
56  } else {
57  m_next_negedge_event.cancel();
58  m_next_negedge_event.notify(initial_delay.get_value());
59  }
60  }
61  }
62  void period_write_callback(const cci::cci_param_write_event<int>& ev) {}
63  static inline std::string get_cci_name(const char* base, const char* name) { return std::string(base) + "_" + name; }
64 };
65 } // namespace scc // end of scc-sysc
67 #endif //
SCC SystemC utilities.
A clock source with construction time configurable start delay.
Definition: sc_clock_ext.h:32