scc  2022.4.0
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 
25 namespace tlm {
27 namespace scc {
28 
29 template <typename SIG = bool, typename TYPES = tlm_signal_baseprotocol_types<SIG>, int N = 32>
30 struct 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 
42 
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 
82 private:
83  void que_cb();
85  sc_core::sc_signal<tlm_signal_type> value;
86 };
87 
88 template <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 
92 template <typename SIG, typename TYPES, int N>
93 tlm_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(size_t i = 0; i < p.size(); ++i) {
97  p.get_interface(i)->nb_transport_fw(gp, phase, delay);
98  }
99  return TLM_COMPLETED;
100 }
101 
102 template <typename SIG, typename TYPES, int N>
103 tlm_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(size_t i = 0; i < p.size(); ++i) {
106  p.get_interface(i)->nb_transport_bw(gp, phase, delay);
107  }
108  return TLM_COMPLETED;
109 }
110 
111 template <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 SystemC utilities.
SystemC TLM.
sc_core::sc_event & event()
get the available event
Definition: peq.h:140