tlm_target_socket.h revision 12027:1eb7dc7aa10b
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_TARGET_SOCKET_H__ 21#define __TLM_TARGET_SOCKET_H__ 22 23//#include <systemc> 24#include "tlm_core/tlm_2/tlm_2_interfaces/tlm_fw_bw_ifs.h" 25 26 27namespace tlm { 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_target_socket_b 33{ 34public: 35 virtual ~tlm_base_target_socket_b() {} 36 37 virtual sc_core::sc_port_b<BW_IF> & get_base_port() = 0; 38 virtual sc_core::sc_export<FW_IF> & get_base_export() = 0; 39 virtual FW_IF & get_base_interface() = 0; 40}; 41 42template <unsigned int BUSWIDTH, 43 typename FW_IF, 44 typename BW_IF> class tlm_base_initiator_socket_b; 45 46template <unsigned int BUSWIDTH, 47 typename FW_IF, 48 typename BW_IF, 49 int N 50#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 51 ,sc_core::sc_port_policy POL 52#endif 53 > class tlm_base_initiator_socket; 54 55template <unsigned int BUSWIDTH = 32, 56 typename FW_IF = tlm_fw_transport_if<>, 57 typename BW_IF = tlm_bw_transport_if<>, 58 int N = 1 59#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 60 ,sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND 61#endif 62 > 63class tlm_base_target_socket : public tlm_base_target_socket_b<BUSWIDTH, FW_IF, BW_IF>, 64 public sc_core::sc_export<FW_IF> 65{ 66public: 67 typedef FW_IF fw_interface_type; 68 typedef BW_IF bw_interface_type; 69 typedef sc_core::sc_port<bw_interface_type, N 70#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 71 , POL 72#endif 73 > port_type; 74 75 typedef sc_core::sc_export<fw_interface_type> export_type; 76 typedef tlm_base_initiator_socket_b<BUSWIDTH, 77 fw_interface_type, 78 bw_interface_type> base_initiator_socket_type; 79 80 typedef tlm_base_target_socket_b<BUSWIDTH, 81 fw_interface_type, 82 bw_interface_type> base_type; 83 84 template <unsigned int, typename, typename, int 85#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 86 ,sc_core::sc_port_policy 87#endif 88 89 > 90 friend class tlm_base_initiator_socket; 91 92public: 93 tlm_base_target_socket() 94 : export_type(sc_core::sc_gen_unique_name("tlm_base_target_socket")) 95 , m_port(sc_core::sc_gen_unique_name("tlm_base_target_socket_port")) 96 { 97 } 98 99 explicit tlm_base_target_socket(const char* name) 100 : export_type(name) 101 , m_port(sc_core::sc_gen_unique_name((std::string(name) + "_port").c_str())) 102 { 103 } 104 105 virtual const char* kind() const 106 { 107 return "tlm_base_target_socket"; 108 } 109 110 unsigned int get_bus_width() const 111 { 112 return BUSWIDTH; 113 } 114 115 // 116 // Bind target socket to initiator socket 117 // - Binds the port of the initiator socket to the export of the target 118 // socket 119 // - Binds the port of the target socket to the export of the initiator 120 // socket 121 // 122 virtual void bind(base_initiator_socket_type& s) 123 { 124 // initiator.port -> target.export 125 (s.get_base_port())(get_base_interface()); 126 // target.port -> initiator.export 127 get_base_port()(s.get_base_interface()); 128 } 129 130 void operator() (base_initiator_socket_type& s) 131 { 132 bind(s); 133 } 134 135 // 136 // Bind target socket to target socket (hierarchical bind) 137 // - Binds both the export and the port 138 // 139 virtual void bind(base_type& s) 140 { 141 // export 142 (get_base_export())(s.get_base_export()); 143 // port 144 (s.get_base_port())(get_base_port()); 145 } 146 147 void operator() (base_type& s) 148 { 149 bind(s); 150 } 151 152 // 153 // Bind interface to socket 154 // - Binds the interface to the export 155 // 156 virtual void bind(fw_interface_type& ifs) 157 { 158 export_type* exp = &get_base_export(); 159 if( this == exp ) { 160 export_type::bind( ifs ); // non-virtual function call 161 } else { 162 exp->bind( ifs ); 163 } 164 } 165 166 void operator() (fw_interface_type& s) 167 { 168 bind(s); 169 } 170 171 // 172 // Forward to 'size()' of port class 173 // 174 int size() const 175 { 176 return m_port.size(); 177 } 178 179 // 180 // Forward to 'operator->()' of port class 181 // 182 bw_interface_type* operator->() 183 { 184 return m_port.operator->(); 185 } 186 187 // 188 // Forward to 'operator[]()' of port class 189 // 190 bw_interface_type* operator[](int i) 191 { 192 return m_port.operator[](i); 193 } 194 195 // Implementation of pure virtual functions of base class 196 197 virtual sc_core::sc_port_b<BW_IF> & get_base_port() 198 { return m_port; } 199 virtual sc_core::sc_port_b<BW_IF> const & get_base_port() const 200 { return m_port; } 201 202 virtual FW_IF & get_base_interface() 203 { return *this; } 204 virtual FW_IF const & get_base_interface() const 205#if !( defined(IEEE_1666_SYSTEMC) && IEEE_1666_SYSTEMC >= 201101L ) 206 { return *const_cast<export_type*>(static_cast<export_type const*>(this)); } 207#else 208 { return *this; } 209#endif 210 211 virtual sc_core::sc_export<FW_IF> & get_base_export() 212 { return *this; } 213 virtual sc_core::sc_export<FW_IF> const & get_base_export() const 214 { return *this; } 215 216protected: 217 port_type m_port; 218}; 219 220 221// 222// Convenience blocking and non-blocking socket classes 223// 224 225template <unsigned int BUSWIDTH = 32, 226 typename TYPES = tlm_base_protocol_types, 227 int N = 1 228#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 229 ,sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND 230#endif 231 > 232class tlm_target_socket : 233 public tlm_base_target_socket <BUSWIDTH, 234 tlm_fw_transport_if<TYPES>, 235 tlm_bw_transport_if<TYPES>, 236 N 237#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 238 ,POL 239#endif 240 > 241{ 242public: 243 tlm_target_socket() : 244 tlm_base_target_socket<BUSWIDTH, 245 tlm_fw_transport_if<TYPES>, 246 tlm_bw_transport_if<TYPES>, 247 N 248#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 249 ,POL 250#endif 251 >() 252 { 253 } 254 255 explicit tlm_target_socket(const char* name) : 256 tlm_base_target_socket<BUSWIDTH, 257 tlm_fw_transport_if<TYPES>, 258 tlm_bw_transport_if<TYPES>, 259 N 260#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 261 ,POL 262#endif 263 >(name) 264 { 265 } 266 267 virtual const char* kind() const 268 { 269 return "tlm_target_socket"; 270 } 271}; 272 273} // namespace tlm 274 275#endif 276