scc 2025.09
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
25namespace scc {
34template <typename BASE>
35class ticking_clock : public BASE
36#ifdef CWR_SYSTEMC
37,
38 public scml_clock_observer
39#endif
40{
41public:
47 sc_core::sc_in<bool> clk_i{"clk_i"};
53 ticking_clock(sc_core::sc_module_name const& nm)
54 : BASE(nm) {}
55
61 template <typename... Args>
62 ticking_clock(sc_core::sc_module_name const& nm, Args&&... args)
63 : BASE(nm, std::forward<Args>(args)...) {}
64
67 virtual ~ticking_clock() = default;
68
69protected:
75 void end_of_elaboration() override {
76#ifdef CWR_SYSTEMC
77 if(auto scml_clk_if = scml2::get_scml_clock(clk_i)) {
78 scml_clk_if->register_observer(this);
79 handle_clock_parameters_updated(scml_clk_if);
80 BASE::end_of_elaboration();
81 return;
82 }
83#endif
84 auto clk_if = dynamic_cast<sc_core::sc_clock*>(clk_i.get_interface());
85 sc_assert(clk_if != nullptr);
86 this->set_clock_period(clk_if->period());
87 BASE::end_of_elaboration();
88 }
89#ifdef CWR_SYSTEMC
90 void handle_clock_parameters_updated(scml_clock_if* clk_if) override { this->set_clock_period(clk_if->get_period()); }
91 void handle_clock_deleted(scml_clock_if*) override{};
92#endif
93};
94
102template <typename BASE> class tickless_clock : public BASE {
103public:
109 sc_core::sc_in<sc_core::sc_time> clk_i{"clk_i"};
115 tickless_clock(sc_core::sc_module_name const& nm)
116 : BASE(nm) {
117#if SYSTEMC_VERSION < 20250221
118 SC_HAS_PROCESS(tickless_clock<BASE>);
119#endif
120 SC_METHOD(clock_cb);
121 this->sensitive << clk_i;
122 }
123
129 template <typename... Args>
130 tickless_clock(sc_core::sc_module_name const& nm, Args&&... args)
131 : BASE(nm, std::forward<Args>(args)...) {
132#if SYSTEMC_VERSION < 20250221
133 SC_HAS_PROCESS(tickless_clock<BASE>);
134#endif
135 SC_METHOD(clock_cb);
136 this->sensitive << clk_i;
137 }
138
141 virtual ~tickless_clock() = default;
142
143private:
149 void clock_cb() { this->set_clock_period(clk_i.read()); }
150};
151} // namespace scc
152#endif // _SYSC_CLOCK_IF_MIXINS_H_
ticking_clock(sc_core::sc_module_name const &nm)
Constructor for the ticking_clock class.
void end_of_elaboration() override
Method called at the end of elaboration.
virtual ~ticking_clock()=default
Virtual destructor for the tickless_clock class.
ticking_clock(sc_core::sc_module_name const &nm, Args &&... args)
Constructor for the ticking_clock class with variable number of arguments.
virtual ~tickless_clock()=default
Virtual destructor for the tickless_clock class.
tickless_clock(sc_core::sc_module_name const &nm, Args &&... args)
Constructor for the tickless_clock class with template arguments.
tickless_clock(sc_core::sc_module_name const &nm)
Constructor for the tickless_clock class.
SCC TLM utilities.