TLM-2.0  2.0.4
Accellera TLM-2.0 proof-of-concept library
tlm_target_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_TARGET_SOCKET_H_INCLUDED_
21 #define TLM_CORE_TLM_TARGET_SOCKET_H_INCLUDED_
22 
25 
26 
27 namespace tlm {
28 
29 template <unsigned int BUSWIDTH = 32,
30  typename FW_IF = tlm_fw_transport_if<>,
31  typename BW_IF = tlm_bw_transport_if<> >
32 class tlm_base_target_socket_b
33 {
34 public:
36 
39  virtual FW_IF & get_base_interface() = 0;
40 };
41 
42 template <unsigned int BUSWIDTH,
43  typename FW_IF,
44  typename BW_IF> class tlm_base_initiator_socket_b;
45 
46 template <unsigned int BUSWIDTH,
47  typename FW_IF,
48  typename BW_IF,
49  int N,
51 
52 template <unsigned int BUSWIDTH = 32,
53  typename FW_IF = tlm_fw_transport_if<>,
54  typename BW_IF = tlm_bw_transport_if<>,
55  int N = 1,
58  public tlm_base_target_socket_b<BUSWIDTH, FW_IF, BW_IF>,
59  public sc_core::sc_export<FW_IF>
60 {
61 public:
62  typedef FW_IF fw_interface_type;
63  typedef BW_IF bw_interface_type;
65 
67  typedef tlm_base_initiator_socket_b<BUSWIDTH,
68  fw_interface_type,
69  bw_interface_type> base_initiator_socket_type;
70 
71  typedef tlm_base_target_socket_b<BUSWIDTH,
72  fw_interface_type,
73  bw_interface_type> base_type;
74 
75  template <unsigned int, typename, typename, int, sc_core::sc_port_policy>
77 
78 public:
80  : export_type(sc_core::sc_gen_unique_name("tlm_base_target_socket"))
81  , m_port(sc_core::sc_gen_unique_name("tlm_base_target_socket_port"))
82  {
83  }
84 
85  explicit tlm_base_target_socket(const char* name)
86  : export_type(name)
87  , m_port(sc_core::sc_gen_unique_name((std::string(name) + "_port").c_str()))
88  {
89  }
90 
91  virtual const char* kind() const
92  {
93  return "tlm_base_target_socket";
94  }
95 
96  //
97  // Bind target socket to initiator socket
98  // - Binds the port of the initiator socket to the export of the target
99  // socket
100  // - Binds the port of the target socket to the export of the initiator
101  // socket
102  //
103  virtual void bind(base_initiator_socket_type& s)
104  {
105  // initiator.port -> target.export
107  // target.port -> initiator.export
109  }
110 
111  void operator() (base_initiator_socket_type& s)
112  {
113  bind(s);
114  }
115 
116  //
117  // Bind target socket to target socket (hierarchical bind)
118  // - Binds both the export and the port
119  //
120  virtual void bind(base_type& s)
121  {
122  // export
124  // port
125  (s.get_base_port())(get_base_port());
126  }
127 
128  void operator() (base_type& s)
129  {
130  bind(s);
131  }
132 
133  //
134  // Bind interface to socket
135  // - Binds the interface to the export
136  //
137  virtual void bind(fw_interface_type& ifs)
138  {
139  export_type* exp = &get_base_export();
140  if( this == exp ) {
141  export_type::bind( ifs ); // non-virtual function call
142  } else {
143  exp->bind( ifs );
144  }
145  }
146 
147  void operator() (fw_interface_type& s)
148  {
149  bind(s);
150  }
151 
152  //
153  // Forward to 'size()' of port class
154  //
155  int size() const
156  {
157  return m_port.size();
158  }
159 
160  //
161  // Forward to 'operator->()' of port class
162  //
163  bw_interface_type* operator->()
164  {
165  return m_port.operator->();
166  }
167 
168  //
169  // Forward to 'operator[]()' of port class
170  //
171  bw_interface_type* operator[](int i)
172  {
173  return m_port.operator[](i);
174  }
175 
176  // Implementation of tlm_base_socket_if functions
178  { return m_port; }
179  virtual sc_core::sc_port_base const & get_port_base() const
180  { return m_port; }
182  { return *this; }
183  virtual sc_core::sc_export_base const & get_export_base() const
184  { return *this; }
185  virtual unsigned int get_bus_width() const
186  { return BUSWIDTH; }
188  { return TLM_TARGET_SOCKET; }
189 
190  // Implementation of tlm_base_target_socket_b functions
192  { return m_port; }
193  virtual sc_core::sc_port_b<BW_IF> const & get_base_port() const
194  { return m_port; }
195 
196  virtual FW_IF & get_base_interface()
197  { return *this; }
198  virtual FW_IF const & get_base_interface() const
199  { return *this; }
200 
202  { return *this; }
204  { return *this; }
205 
206 protected:
207  port_type m_port;
208 };
209 
210 
211 //
212 // Convenience blocking and non-blocking socket classes
213 //
214 
215 template <unsigned int BUSWIDTH = 32,
216  typename TYPES = tlm_base_protocol_types,
217  int N = 1,
220  public tlm_base_target_socket <BUSWIDTH,
221  tlm_fw_transport_if<TYPES>,
222  tlm_bw_transport_if<TYPES>,
223  N, POL>
224 {
225 public:
227  tlm_base_target_socket<BUSWIDTH,
228  tlm_fw_transport_if<TYPES>,
229  tlm_bw_transport_if<TYPES>,
230  N, POL>()
231  {
232  }
233 
234  explicit tlm_target_socket(const char* name) :
235  tlm_base_target_socket<BUSWIDTH,
236  tlm_fw_transport_if<TYPES>,
237  tlm_bw_transport_if<TYPES>,
238  N, POL>(name)
239  {
240  }
241 
242  virtual const char* kind() const
243  {
244  return "tlm_target_socket";
245  }
246 
248  {
249  return typeid(TYPES);
250  }
251 };
252 
253 } // namespace tlm
254 
255 #endif // TLM_CORE_TLM_TARGET_SOCKET_H_INCLUDED_
virtual sc_core::sc_port_b< BW_IF > const & get_base_port() const
virtual sc_core::sc_port_base & get_port_base()
virtual tlm_socket_category get_socket_category() const
virtual sc_core::sc_type_index get_protocol_types() const
sc_core::sc_export< fw_interface_type > export_type
STL namespace.
virtual FW_IF const & get_base_interface() const
tlm_base_target_socket(const char *name)
sc_core::sc_port< bw_interface_type, N, POL > port_type
virtual sc_core::sc_export< FW_IF > const & get_base_export() const
virtual sc_core::sc_export_base & get_export_base()
tlm_base_target_socket_b< BUSWIDTH, fw_interface_type, bw_interface_type > base_type
virtual FW_IF & get_base_interface()
SC_ONE_OR_MORE_BOUND
bw_interface_type * operator->()
virtual sc_core::sc_port_b< BW_IF > & get_base_port()=0
SC_VIRTUAL_ void bind(IF &interface_)
tlm_target_socket(const char *name)
virtual BW_IF & get_base_interface()=0
virtual sc_core::sc_export_base const & get_export_base() const
virtual void bind(base_type &s)
virtual void bind(fw_interface_type &ifs)
virtual sc_core::sc_export< FW_IF > & get_base_export()
virtual sc_core::sc_port_b< FW_IF > & get_base_port()=0
virtual sc_core::sc_port_base const & get_port_base() const
SC_API const char * sc_gen_unique_name(const char *, bool preserve_first)
tlm_base_initiator_socket_b< BUSWIDTH, fw_interface_type, bw_interface_type > base_initiator_socket_type
virtual FW_IF & get_base_interface()=0
bw_interface_type * operator[](int i)
virtual void bind(base_initiator_socket_type &s)
virtual unsigned int get_bus_width() const
virtual sc_core::sc_export< FW_IF > & get_base_export()=0
virtual const char * kind() const
virtual sc_core::sc_port_b< BW_IF > & get_base_port()
virtual const char * kind() const