scc  2022.4.0
SystemC components library
clock_if_mixins.h
1 /*******************************************************************************
2  * Copyright 2021 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 _SYSC_CLOCK_IF_MIXINS_H_
18 #define _SYSC_CLOCK_IF_MIXINS_H_
19 
20 #include <systemc>
21 #ifdef CWR_SYSTEMC
22 #include "scml_clock/scml_clock_if.h"
23 #endif
24 
25 namespace scc {
26 
27 template <typename BASE>
28 class ticking_clock : public BASE
29 #ifdef CWR_SYSTEMC
30 ,
31  public scml_clock_observer
32 #endif
33 {
34 public:
35  sc_core::sc_in<bool> clk_i{"clk_i"};
36 
37  ticking_clock(sc_core::sc_module_name const& nm)
38  : BASE(nm) {}
39 
40 protected:
41  void end_of_elaboration() override {
42 #ifdef CWR_SYSTEMC
43  if(auto scml_clk_if = scml2::get_scml_clock(clk_i)) {
44  scml_clk_if->register_observer(this);
45  handle_clock_parameters_updated(scml_clk_if);
46  BASE::end_of_elaboration();
47  return;
48  }
49 #endif
50  auto clk_if = dynamic_cast<sc_core::sc_clock*>(clk_i.get_interface());
51  sc_assert(clk_if != nullptr);
52  this->set_clock_period(clk_if->period());
53  BASE::end_of_elaboration();
54  }
55 #ifdef CWR_SYSTEMC
56  void handle_clock_parameters_updated(scml_clock_if* clk_if) override { this->set_clock_period(clk_if->get_period()); }
57  void handle_clock_deleted(scml_clock_if*) override{};
58 #endif
59 };
60 
61 template <typename BASE> class tickless_clock : public BASE {
62 public:
63  sc_core::sc_in<sc_core::sc_time> clk_i;
64 
65  tickless_clock(sc_core::sc_module_name const& nm)
66  : BASE(nm) {
67  SC_HAS_PROCESS(tickless_clock<BASE>);
68  SC_METHOD(clock_cb);
69  this->sensitive << clk_i;
70  }
71 
72 private:
73  void clock_cb() { this->set_clock_period(clk_i.read()); }
74 };
75 } // namespace scc
76 #endif // _SYSC_CLOCK_IF_MIXINS_H_
SCC SystemC utilities.