TLM-2.0  2.0.4
Accellera TLM-2.0 proof-of-concept library
tlm_initiator_socket.h
Go to the documentation of this file.
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 TLM_CORE_TLM_INITIATOR_SOCKET_H_INCLUDED_
21 #define TLM_CORE_TLM_INITIATOR_SOCKET_H_INCLUDED_
22 
25 
26 #if defined(__clang__) || \
27  (defined(__GNUC__) && ((__GNUC__ * 1000 + __GNUC_MINOR__) >= 4006))
28 // ignore warning about deliberately hidden "bind()" overloads
29 #pragma GCC diagnostic push
30 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
31 #endif
32 
33 namespace tlm {
34 
35 template <unsigned int BUSWIDTH = 32,
36  typename FW_IF = tlm_fw_transport_if<>,
37  typename BW_IF = tlm_bw_transport_if<> >
39 {
40 public:
42 
44  virtual sc_core::sc_port_b<FW_IF> const & get_base_port() const = 0;
45  virtual BW_IF & get_base_interface() = 0;
46  virtual BW_IF const & get_base_interface() const = 0;
48  virtual sc_core::sc_export<BW_IF> const & get_base_export() const = 0;
49 };
50 
51 
52 template <unsigned int BUSWIDTH,
53  typename FW_IF,
54  typename BW_IF> class tlm_base_target_socket_b;
55 
56 template <unsigned int BUSWIDTH,
57  typename FW_IF,
58  typename BW_IF,
59  int N,
61 
62 template <unsigned int BUSWIDTH = 32,
63  typename FW_IF = tlm_fw_transport_if<>,
64  typename BW_IF = tlm_bw_transport_if<>,
65  int N = 1,
68  public tlm_base_initiator_socket_b<BUSWIDTH, FW_IF, BW_IF>,
69  public sc_core::sc_port<FW_IF, N, POL>
70 {
71 public:
72  typedef FW_IF fw_interface_type;
73  typedef BW_IF bw_interface_type;
75 
77 
78  typedef tlm_base_target_socket_b<BUSWIDTH,
79  fw_interface_type,
80  bw_interface_type> base_target_socket_type;
81  typedef tlm_base_initiator_socket_b<BUSWIDTH,
82  fw_interface_type,
83  bw_interface_type> base_type;
84 
85  template <unsigned int, typename, typename, int, sc_core::sc_port_policy>
86  friend class tlm_base_target_socket;
87 
88 public:
90  : port_type(sc_core::sc_gen_unique_name("tlm_base_initiator_socket"))
91  , m_export(sc_core::sc_gen_unique_name("tlm_base_initiator_socket_export"))
92  {
93  }
94 
95  explicit tlm_base_initiator_socket(const char* name)
96  : port_type(name)
97  , m_export(sc_core::sc_gen_unique_name((std::string(name) + "_export").c_str()))
98  {
99  }
100 
101  virtual const char* kind() const
102  {
103  return "tlm_base_initiator_socket";
104  }
105 
106  //
107  // Bind initiator socket to target socket
108  // - Binds the port of the initiator socket to the export of the target
109  // socket
110  // - Binds the port of the target socket to the export of the initiator
111  // socket
112  //
113  virtual void bind(base_target_socket_type& s)
114  {
115  // initiator.port -> target.export
117  // target.port -> initiator.export
119  }
120 
121  void operator() (base_target_socket_type& s)
122  {
123  bind(s);
124  }
125 
126  //
127  // Bind initiator socket to initiator socket (hierarchical bind)
128  // - Binds both the export and the port
129  //
130  virtual void bind(base_type& s)
131  {
132  // port
133  (get_base_port())(s.get_base_port());
134  // export
135  (s.get_base_export())(get_base_export());
136  }
137 
138  void operator() (base_type& s)
139  {
140  bind(s);
141  }
142 
143  //
144  // Bind interface to socket
145  // - Binds the interface to the export of this socket
146  //
147  virtual void bind(bw_interface_type& ifs)
148  {
149  (get_base_export())(ifs);
150  }
151 
152  void operator() (bw_interface_type& s)
153  {
154  bind(s);
155  }
156 
157  // Implementation of tlm_base_socket_if functions
159  { return *this; }
160  virtual sc_core::sc_port_base const & get_port_base() const
161  { return *this; }
163  { return m_export; }
164  virtual sc_core::sc_export_base const & get_export_base() const
165  { return m_export; }
166  virtual unsigned int get_bus_width() const
167  { return BUSWIDTH; }
169  { return TLM_INITIATOR_SOCKET; }
170 
171  // Implementation of tlm_base_target_socket_b functions
173  { return *this; }
174  virtual sc_core::sc_port_b<FW_IF> const & get_base_port() const
175  { return *this; }
176 
177  virtual BW_IF & get_base_interface()
178  { return m_export; }
179  virtual BW_IF const & get_base_interface() const
180  { return m_export; }
181 
183  { return m_export; }
185  { return m_export; }
186 
187 protected:
188  export_type m_export;
189 };
190 
191 //
192 // Convenience socket classes
193 //
194 
195 template <unsigned int BUSWIDTH = 32,
196  typename TYPES = tlm_base_protocol_types,
197  int N = 1,
200  public tlm_base_initiator_socket<BUSWIDTH,
201  tlm_fw_transport_if<TYPES>,
202  tlm_bw_transport_if<TYPES>,
203  N, POL>
204 {
205 public:
207  tlm_base_initiator_socket<BUSWIDTH,
208  tlm_fw_transport_if<TYPES>,
209  tlm_bw_transport_if<TYPES>,
210  N, POL>()
211  {
212  }
213 
214  explicit tlm_initiator_socket(const char* name) :
215  tlm_base_initiator_socket<BUSWIDTH,
216  tlm_fw_transport_if<TYPES>,
217  tlm_bw_transport_if<TYPES>,
218  N, POL>(name)
219  {
220  }
221 
222  virtual const char* kind() const
223  {
224  return "tlm_initiator_socket";
225  }
226 
228  {
229  return typeid(TYPES);
230  }
231 };
232 
233 } // namespace tlm
234 
235 #if defined(__clang__) || \
236  (defined(__GNUC__) && ((__GNUC__ * 1000 + __GNUC_MINOR__) >= 4006))
237 #pragma GCC diagnostic pop
238 #endif
239 
240 #endif // TLM_CORE_TLM_INITIATOR_SOCKET_H_INCLUDED_
virtual void bind(base_type &s)
sc_core::sc_port< fw_interface_type, N, POL > port_type
virtual sc_core::sc_export< BW_IF > & get_base_export()=0
tlm_base_target_socket_b< BUSWIDTH, fw_interface_type, bw_interface_type > base_target_socket_type
virtual void bind(bw_interface_type &ifs)
STL namespace.
sc_core::sc_export< bw_interface_type > export_type
virtual const char * kind() const
virtual sc_core::sc_port_b< FW_IF > const & get_base_port() const
virtual BW_IF const & get_base_interface() const
virtual sc_core::sc_export_base const & get_export_base() const
SC_ONE_OR_MORE_BOUND
virtual sc_core::sc_type_index get_protocol_types() const
virtual sc_core::sc_port_b< BW_IF > & get_base_port()=0
virtual sc_core::sc_export< BW_IF > & get_base_export()
virtual tlm_socket_category get_socket_category() const
virtual BW_IF & get_base_interface()=0
virtual sc_core::sc_port_b< FW_IF > & get_base_port()=0
virtual sc_core::sc_export_base & get_export_base()
SC_API const char * sc_gen_unique_name(const char *, bool preserve_first)
virtual unsigned int get_bus_width() const
virtual sc_core::sc_port_base & get_port_base()
virtual FW_IF & get_base_interface()=0
virtual sc_core::sc_export< BW_IF > const & get_base_export() const
virtual void bind(base_target_socket_type &s)
tlm_initiator_socket(const char *name)
tlm_base_initiator_socket(const char *name)
virtual sc_core::sc_port_b< FW_IF > & get_base_port()
virtual const char * kind() const
virtual sc_core::sc_port_base const & get_port_base() const
tlm_base_initiator_socket_b< BUSWIDTH, fw_interface_type, bw_interface_type > base_type