scc 2025.09
SystemC components library
tlm_signal.h
1/*******************************************************************************
2 * Copyright 2018 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 _TLM_TLM_SIGNAL_H_
18#define _TLM_TLM_SIGNAL_H_
19
20#include "tlm_signal_gp.h"
21#include "tlm_signal_sockets.h"
22#include <scc/peq.h>
23
25namespace tlm {
27namespace scc {
28
29template <typename SIG = bool, typename TYPES = tlm_signal_baseprotocol_types<SIG>, int N = 32>
30struct tlm_signal : public sc_core::sc_module,
31 public tlm_signal_fw_transport_if<SIG, TYPES>,
32 public tlm_signal_bw_transport_if<SIG, TYPES>,
33 sc_core::sc_signal_in_if<SIG> {
34 using tlm_signal_type = SIG;
35 using protocol_types = TYPES;
36 using payload_type = typename TYPES::tlm_payload_type;
37 using phase_type = typename TYPES::tlm_phase_type;
38
39 SC_HAS_PROCESS(tlm_signal); // NOLINT
40
41 tlm_signal_opt_target_socket<tlm_signal_type, protocol_types, N> in;
42
43 tlm_signal_opt_initiator_socket<tlm_signal_type, protocol_types, N> out;
44
45 tlm_signal(sc_core::sc_module_name nm)
46 : sc_core::sc_module(nm)
47 , in(sc_core::sc_gen_unique_name("in"))
48 , out(sc_core::sc_gen_unique_name("out")) {
51 SC_METHOD(que_cb);
52 sensitive << que.event();
53 }
54
55 void trace(sc_core::sc_trace_file* tf) const override;
56
57 const char* kind() const override { return "tlm_signal"; }
58
59 tlm_sync_enum nb_transport_fw(payload_type&, phase_type&, sc_core::sc_time&) override;
60
61 tlm_sync_enum nb_transport_bw(payload_type&, phase_type&, sc_core::sc_time&) override;
62
63 // get the value changed event
64 const sc_core::sc_event& value_changed_event() const override { return value.value_changed_event(); }
65 // read the current value
66 const SIG& read() const override { return value.read(); }
67 // get a reference to the current value (for tracing)
68 const SIG& get_data_ref() const override { return value.get_data_ref(); }
69 // was there a value changed event?
70 bool event() const override { return false; }
71
72 const sc_core::sc_event& default_event() const override { return value.default_event(); }
73
74 const sc_core::sc_event& posedge_event() const override { return value.posedge_event(); }
75
76 const sc_core::sc_event& negedge_event() const override { return value.negedge_event(); }
77
78 bool posedge() const override { return value.posedge(); }
79
80 bool negedge() const override { return value.posedge(); };
81
82private:
83 void que_cb();
85 sc_core::sc_signal<tlm_signal_type> value;
86};
87
88template <typename SIG, typename TYPES, int N> void tlm_signal<SIG, TYPES, N>::trace(sc_core::sc_trace_file* tf) const {
89 sc_trace(tf, value, name());
90}
91
92template <typename SIG, typename TYPES, int N>
93tlm_sync_enum tlm_signal<SIG, TYPES, N>::nb_transport_fw(payload_type& gp, phase_type& phase, sc_core::sc_time& delay) {
94 que.notify(gp.get_value(), delay);
95 auto& p = out.get_base_port();
96 for(auto i = 0; i < p.size(); ++i) {
97 p.get_interface(i)->nb_transport_fw(gp, phase, delay);
98 }
99 return TLM_COMPLETED;
100}
101
102template <typename SIG, typename TYPES, int N>
103tlm_sync_enum tlm_signal<SIG, TYPES, N>::nb_transport_bw(payload_type& gp, phase_type& phase, sc_core::sc_time& delay) {
104 auto& p = in.get_base_port();
105 for(auto i = 0; i < p.size(); ++i) {
106 p.get_interface(i)->nb_transport_bw(gp, phase, delay);
107 }
108 return TLM_COMPLETED;
109}
110
111template <typename SIG, typename TYPES, int N> void tlm_signal<SIG, TYPES, N>::que_cb() {
112 while(auto oi = que.get_next())
113 value.write(oi.get());
114}
115} // namespace scc
116} // namespace tlm
117#endif /* _TLM_TLM_SIGNAL_H_ */
SCC TLM utilities.
Definition axis_tlm.h:56
SystemC TLM.
Definition dmi_mgr.h:19
priority event queue
Definition peq.h:41