Deleted Added
sdiff udiff text old ( 13521:74fa3ac44057 ) new ( 13523:de27641700bb )
full compact
1/*****************************************************************************
2
3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4 more contributor license agreements. See the NOTICE file distributed
5 with this work for additional information regarding copyright ownership.
6 Accellera licenses this file to you under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with the
8 License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 implied. See the License for the specific language governing
16 permissions and limitations under the License.
17
18 *****************************************************************************/
19
20#ifndef __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_INITIATOR_SOCKET_HH__
21#define __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_INITIATOR_SOCKET_HH__
22
23#include "tlm_core/2/interfaces/fw_bw_ifs.hh"
24#include "tlm_core/2/sockets/base_socket_if.hh"
25
26namespace tlm
27{
28
29template <unsigned int BUSWIDTH=32,
30 typename FW_IF=tlm_fw_transport_if<>,
31 typename BW_IF=tlm_bw_transport_if<>>
32class tlm_base_initiator_socket_b
33{
34 public:
35 virtual ~tlm_base_initiator_socket_b() {}
36
37 virtual sc_core::sc_port_b<FW_IF> &get_base_port() = 0;
38 virtual sc_core::sc_port_b<FW_IF> const &get_base_port() const = 0;
39 virtual BW_IF &get_base_interface() = 0;
40 virtual BW_IF const &get_base_interface() const = 0;
41 virtual sc_core::sc_export<BW_IF> &get_base_export() = 0;
42 virtual sc_core::sc_export<BW_IF> const &get_base_export() const = 0;
43};
44
45template <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF>
46class tlm_base_target_socket_b;
47
48template <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N,
49 sc_core::sc_port_policy POL>
50class tlm_base_target_socket;
51
52template <unsigned int BUSWIDTH=32, typename FW_IF=tlm_fw_transport_if<>,
53 typename BW_IF=tlm_bw_transport_if<>, int N=1,
54 sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND>
55class tlm_base_initiator_socket :
56 public tlm_base_socket_if,
57 public tlm_base_initiator_socket_b<BUSWIDTH, FW_IF, BW_IF>,
58 public sc_core::sc_port<FW_IF, N, POL>
59{
60 public:
61 typedef FW_IF fw_interface_type;
62 typedef BW_IF bw_interface_type;
63 typedef sc_core::sc_port<fw_interface_type, N, POL> port_type;
64
65 typedef sc_core::sc_export<bw_interface_type> export_type;
66
67 typedef tlm_base_target_socket_b<
68 BUSWIDTH, fw_interface_type, bw_interface_type>
69 base_target_socket_type;
70 typedef tlm_base_initiator_socket_b<
71 BUSWIDTH, fw_interface_type, bw_interface_type> base_type;
72
73 template <unsigned int, typename, typename, int, sc_core::sc_port_policy>
74 friend class tlm_base_target_socket;
75
76 public:
77 tlm_base_initiator_socket() :
78 port_type(sc_core::sc_gen_unique_name("tlm_base_initiator_socket")),
79 m_export(sc_core::sc_gen_unique_name(
80 "tlm_base_initiator_socket_export"))
81 {}
82
83 explicit tlm_base_initiator_socket(const char *name) : port_type(name),
84 m_export(sc_core::sc_gen_unique_name(
85 (std::string(name) + "_export").c_str()))
86 {}
87
88 virtual const char* kind() const { return "tlm_base_initiator_socket"; }
89
90 //
91 // Bind initiator socket to target socket
92 // - Binds the port of the initiator socket to the export of the target
93 // socket
94 // - Binds the port of the target socket to the export of the initiator
95 // socket
96 //
97 virtual void
98 bind(base_target_socket_type &s)
99 {
100 // initiator.port -> target.export
101 (get_base_port())(s.get_base_interface());
102 // target.port -> initiator.export
103 (s.get_base_port())(get_base_interface());
104 }
105
106 void operator () (base_target_socket_type &s) { bind(s); }
107
108 //
109 // Bind initiator socket to initiator socket (hierarchical bind)
110 // - Binds both the export and the port
111 //
112 virtual void
113 bind(base_type &s)
114 {
115 // port
116 (get_base_port())(s.get_base_port());
117 // export
118 (s.get_base_export())(get_base_export());
119 }
120
121 void operator() (base_type &s) { bind(s); }
122
123 //
124 // Bind interface to socket
125 // - Binds the interface to the export of this socket
126 //
127 virtual void bind(bw_interface_type &ifs) { (get_base_export())(ifs); }
128 void operator() (bw_interface_type &s) { bind(s); }
129
130 // Implementation of tlm_base_socket_if functions
131 virtual sc_core::sc_port_base &get_port_base() { return *this; }
132 virtual sc_core::sc_port_base const &
133 get_port_base() const
134 {
135 return *this;
136 }
137 virtual sc_core::sc_export_base &get_export_base() { return m_export; }
138 virtual sc_core::sc_export_base const &
139 get_export_base() const
140 {
141 return m_export;
142 }
143 virtual unsigned int get_bus_width() const { return BUSWIDTH; }
144 virtual tlm_socket_category
145 get_socket_category() const
146 {
147 return TLM_INITIATOR_SOCKET;
148 }
149
150 // Implementation of tlm_base_target_socket_b functions
151 virtual sc_core::sc_port_b<FW_IF> &get_base_port() { return *this; }
152 virtual sc_core::sc_port_b<FW_IF> const &
153 get_base_port() const
154 {
155 return *this;
156 }
157
158 virtual BW_IF &get_base_interface() { return m_export; }
159 virtual BW_IF const &get_base_interface() const { return m_export; }
160
161 virtual sc_core::sc_export<BW_IF> &get_base_export() { return m_export; }
162 virtual sc_core::sc_export<BW_IF> const &
163 get_base_export() const
164 {
165 return m_export;
166 }
167
168 protected:
169 export_type m_export;
170};
171
172//
173// Convenience socket classes
174//
175
176template <unsigned int BUSWIDTH=32, typename TYPES=tlm_base_protocol_types,
177 int N=1, sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND>
178class tlm_initiator_socket : public tlm_base_initiator_socket<
179 BUSWIDTH, tlm_fw_transport_if<TYPES>,
180 tlm_bw_transport_if<TYPES>, N, POL>
181{
182 public:
183 tlm_initiator_socket() : tlm_base_initiator_socket<
184 BUSWIDTH, tlm_fw_transport_if<TYPES>,
185 tlm_bw_transport_if<TYPES>, N, POL>()
186 {}
187
188 explicit tlm_initiator_socket(const char *name) :
189 tlm_base_initiator_socket<BUSWIDTH, tlm_fw_transport_if<TYPES>,
190 tlm_bw_transport_if<TYPES>, N, POL>(name)
191 {}
192
193 virtual const char *kind() const { return "tlm_initiator_socket"; }
194
195 virtual sc_core::sc_type_index
196 get_protocol_types() const
197 {
198 return typeid(TYPES);
199 }
200};
201
202} // namespace tlm
203
204#endif /* __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_INITIATOR_SOCKET_HH__ */