TLM-2.0  2.0.3
Accellera TLM-2.0 proof-of-concept library
tlm_target_socket.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 #ifndef __TLM_TARGET_SOCKET_H__
19 #define __TLM_TARGET_SOCKET_H__
20 
21 //#include <systemc>
23 
24 
25 namespace tlm {
26 
27 template <unsigned int BUSWIDTH = 32,
28  typename FW_IF = tlm_fw_transport_if<>,
29  typename BW_IF = tlm_bw_transport_if<> >
30 class tlm_base_target_socket_b
31 {
32 public:
34 
37  virtual FW_IF & get_base_interface() = 0;
38 };
39 
40 template <unsigned int BUSWIDTH,
41  typename FW_IF,
42  typename BW_IF> class tlm_base_initiator_socket_b;
43 
44 template <unsigned int BUSWIDTH,
45  typename FW_IF,
46  typename BW_IF,
47  int N
48 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
50 #endif
51  > class tlm_base_initiator_socket;
52 
53 template <unsigned int BUSWIDTH = 32,
54  typename FW_IF = tlm_fw_transport_if<>,
55  typename BW_IF = tlm_bw_transport_if<>,
56  int N = 1
57 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
59 #endif
60  >
61 class tlm_base_target_socket : public tlm_base_target_socket_b<BUSWIDTH, FW_IF, BW_IF>,
62  public sc_core::sc_export<FW_IF>
63 {
64 public:
65  typedef FW_IF fw_interface_type;
66  typedef BW_IF bw_interface_type;
68 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
69  , POL
70 #endif
72 
74  typedef tlm_base_initiator_socket_b<BUSWIDTH,
77 
78  typedef tlm_base_target_socket_b<BUSWIDTH,
81 
82  template <unsigned int, typename, typename, int
83 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
85 #endif
86 
87  >
89 
90 public:
92  : export_type(sc_core::sc_gen_unique_name("tlm_base_target_socket"))
93  , m_port(sc_core::sc_gen_unique_name("tlm_base_target_socket_port"))
94  {
95  }
96 
97  explicit tlm_base_target_socket(const char* name)
98  : export_type(name)
99  , m_port(sc_core::sc_gen_unique_name((std::string(name) + "_port").c_str()))
100  {
101  }
102 
103  virtual const char* kind() const
104  {
105  return "tlm_base_target_socket";
106  }
107 
108  unsigned int get_bus_width() const
109  {
110  return BUSWIDTH;
111  }
112 
113  //
114  // Bind target socket to initiator socket
115  // - Binds the port of the initiator socket to the export of the target
116  // socket
117  // - Binds the port of the target socket to the export of the initiator
118  // socket
119  //
121  {
122  // initiator.port -> target.export
124  // target.port -> initiator.export
126  }
127 
129  {
130  bind(s);
131  }
132 
133  //
134  // Bind target socket to target socket (hierarchical bind)
135  // - Binds both the export and the port
136  //
137  virtual void bind(base_type& s)
138  {
139  // export
141  // port
142  (s.get_base_port())(get_base_port());
143  }
144 
146  {
147  bind(s);
148  }
149 
150  //
151  // Bind interface to socket
152  // - Binds the interface to the export
153  //
154  virtual void bind(fw_interface_type& ifs)
155  {
156  export_type* exp = &get_base_export();
157  if( this == exp ) {
158  export_type::bind( ifs ); // non-virtual function call
159  } else {
160  exp->bind( ifs );
161  }
162  }
163 
165  {
166  bind(s);
167  }
168 
169  //
170  // Forward to 'size()' of port class
171  //
172  int size() const
173  {
174  return m_port.size();
175  }
176 
177  //
178  // Forward to 'operator->()' of port class
179  //
181  {
182  return m_port.operator->();
183  }
184 
185  //
186  // Forward to 'operator[]()' of port class
187  //
189  {
190  return m_port.operator[](i);
191  }
192 
193  // Implementation of pure virtual functions of base class
194 
196  { return m_port; }
197  virtual sc_core::sc_port_b<BW_IF> const & get_base_port() const
198  { return m_port; }
199 
200  virtual FW_IF & get_base_interface()
201  { return *this; }
202  virtual FW_IF const & get_base_interface() const
203 #if !( defined(IEEE_1666_SYSTEMC) && IEEE_1666_SYSTEMC >= 201101L )
204  { return *const_cast<export_type*>(static_cast<export_type const*>(this)); }
205 #else
206  { return *this; }
207 #endif
208 
210  { return *this; }
212  { return *this; }
213 
214 protected:
216 };
217 
218 
219 //
220 // Convenience blocking and non-blocking socket classes
221 //
222 
223 template <unsigned int BUSWIDTH = 32,
224  typename TYPES = tlm_base_protocol_types,
225  int N = 1
226 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
228 #endif
229  >
231  public tlm_base_target_socket <BUSWIDTH,
232  tlm_fw_transport_if<TYPES>,
233  tlm_bw_transport_if<TYPES>,
234  N
235 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
236  ,POL
237 #endif
238  >
239 {
240 public:
241  tlm_target_socket() :
242  tlm_base_target_socket<BUSWIDTH,
243  tlm_fw_transport_if<TYPES>,
244  tlm_bw_transport_if<TYPES>,
245  N
246 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
247  ,POL
248 #endif
249  >()
250  {
251  }
252 
253  explicit tlm_target_socket(const char* name) :
254  tlm_base_target_socket<BUSWIDTH,
255  tlm_fw_transport_if<TYPES>,
256  tlm_bw_transport_if<TYPES>,
257  N
258 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
259  ,POL
260 #endif
261  >(name)
262  {
263  }
264 
265  virtual const char* kind() const
266  {
267  return "tlm_target_socket";
268  }
269 };
270 
271 } // namespace tlm
272 
273 #endif
void operator()(base_initiator_socket_type &s)
virtual sc_core::sc_port_b< BW_IF > & get_base_port()
virtual FW_IF const & get_base_interface() const
virtual sc_core::sc_export< FW_IF > & get_base_export()
virtual sc_core::sc_port_b< BW_IF > const & get_base_port() const
int size() const
bw_interface_type * operator[](int i)
tlm_base_initiator_socket_b< BUSWIDTH, fw_interface_type, bw_interface_type > base_initiator_socket_type
tlm_base_target_socket_b< BUSWIDTH, fw_interface_type, bw_interface_type > base_type
sc_core::sc_port< bw_interface_type, N, POL > port_type
unsigned int get_bus_width() const
virtual sc_core::sc_export< FW_IF > & get_base_export()=0
bw_interface_type * operator->()
virtual FW_IF & get_base_interface()=0
virtual sc_core::sc_export< FW_IF > const & get_base_export() const
sc_core::sc_export< fw_interface_type > export_type
const char * sc_gen_unique_name(const char *, bool preserve_first)
tlm_base_target_socket(const char *name)
virtual const char * kind() const
virtual sc_core::sc_port_b< BW_IF > & get_base_port()=0
virtual void bind(base_type &s)
virtual void bind(base_initiator_socket_type &s)
virtual BW_IF & get_base_interface()=0
virtual sc_core::sc_port_b< FW_IF > & get_base_port()=0
virtual FW_IF & get_base_interface()
SC_VIRTUAL_ void bind(IF &interface_)
virtual void bind(fw_interface_type &ifs)