TLM-2.0  2.0.3
Accellera TLM-2.0 proof-of-concept library
tlm_initiator_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_INITIATOR_SOCKET_H__
19 #define __TLM_INITIATOR_SOCKET_H__
20 
21 //#include <systemc>
23 
24 namespace tlm {
25 
26 
27 template <unsigned int BUSWIDTH = 32,
28  typename FW_IF = tlm_fw_transport_if<>,
29  typename BW_IF = tlm_bw_transport_if<> >
31 {
32 public:
34 
36  virtual sc_core::sc_port_b<FW_IF> const & get_base_port() const = 0;
37  virtual BW_IF & get_base_interface() = 0;
38  virtual BW_IF const & get_base_interface() const = 0;
40  virtual sc_core::sc_export<BW_IF> const & get_base_export() const = 0;
41 };
42 
43 
44 template <unsigned int BUSWIDTH,
45  typename FW_IF,
46  typename BW_IF> class tlm_base_target_socket_b;
47 
48 template <unsigned int BUSWIDTH,
49  typename FW_IF,
50  typename BW_IF,
51  int N
52 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
54 #endif
56 
57 template <unsigned int BUSWIDTH = 32,
58  typename FW_IF = tlm_fw_transport_if<>,
59  typename BW_IF = tlm_bw_transport_if<>,
60  int N = 1
61 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
63 #endif
64  >
65 class tlm_base_initiator_socket : public tlm_base_initiator_socket_b<BUSWIDTH, FW_IF, BW_IF>,
66  public sc_core::sc_port<FW_IF, N
67 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
68  , POL
69 #endif
70  >
71 
72 {
73 public:
74  typedef FW_IF fw_interface_type;
75  typedef BW_IF bw_interface_type;
76  typedef sc_core::sc_port<fw_interface_type, N
77 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
78  , POL
79 #endif
80  > port_type;
81 
82  typedef sc_core::sc_export<bw_interface_type> export_type;
83 
84  typedef tlm_base_target_socket_b<BUSWIDTH,
85  fw_interface_type,
86  bw_interface_type> base_target_socket_type;
87  typedef tlm_base_initiator_socket_b<BUSWIDTH,
88  fw_interface_type,
89  bw_interface_type> base_type;
90 
91  template <unsigned int, typename, typename, int
92 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
93  ,sc_core::sc_port_policy
94 #endif
95  >
96  friend class tlm_base_target_socket;
97 
98 public:
99  tlm_base_initiator_socket()
100  : port_type(sc_core::sc_gen_unique_name("tlm_base_initiator_socket"))
101  , m_export(sc_core::sc_gen_unique_name("tlm_base_initiator_socket_export"))
102  {
103  }
104 
105  explicit tlm_base_initiator_socket(const char* name)
106  : port_type(name)
107  , m_export(sc_core::sc_gen_unique_name((std::string(name) + "_export").c_str()))
108  {
109  }
110 
111  virtual const char* kind() const
112  {
113  return "tlm_base_initiator_socket";
114  }
115 
116  unsigned int get_bus_width() const
117  {
118  return BUSWIDTH;
119  }
120 
121  //
122  // Bind initiator socket to target socket
123  // - Binds the port of the initiator socket to the export of the target
124  // socket
125  // - Binds the port of the target socket to the export of the initiator
126  // socket
127  //
128  virtual void bind(base_target_socket_type& s)
129  {
130  // initiator.port -> target.export
131  (get_base_port())(s.get_base_interface());
132  // target.port -> initiator.export
133  (s.get_base_port())(get_base_interface());
134  }
135 
136  void operator() (base_target_socket_type& s)
137  {
138  bind(s);
139  }
140 
141  //
142  // Bind initiator socket to initiator socket (hierarchical bind)
143  // - Binds both the export and the port
144  //
145  virtual void bind(base_type& s)
146  {
147  // port
148  (get_base_port())(s.get_base_port());
149  // export
150  (s.get_base_export())(get_base_export());
151  }
152 
153  void operator() (base_type& s)
154  {
155  bind(s);
156  }
157 
158  //
159  // Bind interface to socket
160  // - Binds the interface to the export of this socket
161  //
162  virtual void bind(bw_interface_type& ifs)
163  {
164  (get_base_export())(ifs);
165  }
166 
167  void operator() (bw_interface_type& s)
168  {
169  bind(s);
170  }
171 
172  // Implementation of pure virtual functions of base class
173  virtual sc_core::sc_port_b<FW_IF> & get_base_port()
174  { return *this; }
175  virtual sc_core::sc_port_b<FW_IF> const & get_base_port() const
176  { return *this; }
177 
178  virtual BW_IF & get_base_interface()
179  { return m_export; }
180  virtual BW_IF const & get_base_interface() const
181 #if !( defined(IEEE_1666_SYSTEMC) && IEEE_1666_SYSTEMC >= 201101L )
182  { return const_cast<export_type &>(m_export); }
183 #else
184  { return m_export; }
185 #endif
186 
187  virtual sc_core::sc_export<BW_IF> & get_base_export()
188  { return m_export; }
189  virtual sc_core::sc_export<BW_IF> const & get_base_export() const
190  { return m_export; }
191 
192 protected:
193  export_type m_export;
194 };
195 
196 //
197 // Convenience socket classes
198 //
199 
200 template <unsigned int BUSWIDTH = 32,
201  typename TYPES = tlm_base_protocol_types,
202  int N = 1
203 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
204  ,sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND
205 #endif
206  >
207 class tlm_initiator_socket :
208  public tlm_base_initiator_socket <BUSWIDTH,
209  tlm_fw_transport_if<TYPES>,
210  tlm_bw_transport_if<TYPES>,
211  N
212 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
213  ,POL
214 #endif
215  >
216 {
217 public:
218  tlm_initiator_socket() :
219  tlm_base_initiator_socket<BUSWIDTH,
220  tlm_fw_transport_if<TYPES>,
221  tlm_bw_transport_if<TYPES>,
222  N
223 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
224  ,POL
225 #endif
226  >()
227  {
228  }
229 
230  explicit tlm_initiator_socket(const char* name) :
231  tlm_base_initiator_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  >(name)
239  {
240  }
241 
242  virtual const char* kind() const
243  {
244  return "tlm_initiator_socket";
245  }
246 };
247 
248 } // namespace tlm
249 
250 #endif
virtual BW_IF & get_base_interface()=0
virtual sc_core::sc_port_b< FW_IF > & get_base_port()=0
virtual sc_core::sc_export< BW_IF > & get_base_export()=0