23#include "tlm_core/2/interfaces/fw_bw_ifs.hh" 24#include "tlm_core/2/sockets/base_socket_if.hh" 25 26namespace tlm 27{ 28 29template <unsigned int BUSWIDTH=32, typename FW_IF=tlm_fw_transport_if<>, 30 typename BW_IF=tlm_bw_transport_if<>> 31class tlm_base_target_socket_b 32{ 33 public: 34 virtual ~tlm_base_target_socket_b() {} 35 36 virtual sc_core::sc_port_b<BW_IF> &get_base_port() = 0; 37 virtual sc_core::sc_export<FW_IF> &get_base_export() = 0; 38 virtual FW_IF &get_base_interface() = 0; 39}; 40 41template <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF> 42class tlm_base_initiator_socket_b; 43 44template <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N, 45 sc_core::sc_port_policy POL> 46class tlm_base_initiator_socket; 47 48template <unsigned int BUSWIDTH=32, typename FW_IF=tlm_fw_transport_if<>, 49 typename BW_IF=tlm_bw_transport_if<>, int N=1, 50 sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND> 51class tlm_base_target_socket : 52 public tlm_base_socket_if, 53 public tlm_base_target_socket_b<BUSWIDTH, FW_IF, BW_IF>, 54 public sc_core::sc_export<FW_IF> 55{ 56 public: 57 typedef FW_IF fw_interface_type; 58 typedef BW_IF bw_interface_type; 59 typedef sc_core::sc_port<bw_interface_type, N, POL> port_type; 60 61 typedef sc_core::sc_export<fw_interface_type> export_type; 62 typedef tlm_base_initiator_socket_b< 63 BUSWIDTH, fw_interface_type, bw_interface_type> 64 base_initiator_socket_type; 65 66 typedef tlm_base_target_socket_b< 67 BUSWIDTH, fw_interface_type, bw_interface_type> base_type; 68 69 template <unsigned int, typename, typename, int, sc_core::sc_port_policy> 70 friend class tlm_base_initiator_socket; 71 72 public: 73 tlm_base_target_socket() : 74 export_type(sc_core::sc_gen_unique_name("tlm_base_target_socket")), 75 m_port(sc_core::sc_gen_unique_name("tlm_base_target_socket_port")) 76 {} 77 78 explicit tlm_base_target_socket(const char *name) : 79 export_type(name), m_port(sc_core::sc_gen_unique_name( 80 (std::string(name) + "_port").c_str())) 81 {} 82 83 virtual const char *kind() const { return "tlm_base_target_socket"; } 84 85 // 86 // Bind target socket to initiator socket 87 // - Binds the port of the initiator socket to the export of the target 88 // socket 89 // - Binds the port of the target socket to the export of the initiator 90 // socket 91 // 92 virtual void 93 bind(base_initiator_socket_type &s) 94 { 95 // initiator.port -> target.export 96 (s.get_base_port())(get_base_interface()); 97 // target.port -> initiator.export 98 get_base_port()(s.get_base_interface()); 99 } 100 101 void operator () (base_initiator_socket_type &s) { bind(s); } 102 103 // 104 // Bind target socket to target socket (hierarchical bind) 105 // - Binds both the export and the port 106 // 107 virtual void 108 bind(base_type &s) 109 { 110 // export 111 (get_base_export())(s.get_base_export()); 112 // port 113 (s.get_base_port())(get_base_port()); 114 } 115 116 void operator () (base_type &s) { bind(s); } 117 118 // 119 // Bind interface to socket 120 // - Binds the interface to the export 121 // 122 virtual void 123 bind(fw_interface_type &ifs) 124 { 125 export_type *exp = &get_base_export(); 126 if (this == exp) { 127 export_type::bind(ifs); 128 } else { 129 exp->bind( ifs ); 130 } 131 } 132 133 void operator () (fw_interface_type &s) { bind(s); } 134 135 // 136 // Forward to 'size()' of port class. 137 // 138 int size() const { return m_port.size(); } 139 140 // 141 // Forward to 'operator->()' of port class. 142 // 143 bw_interface_type *operator->() { return m_port.operator->(); } 144 145 // 146 // Forward to 'operator[]()' of port class. 147 // 148 bw_interface_type *operator[](int i) { return m_port.operator[](i); } 149 150 // Implementation of tlm_base_socket_if functions. 151 virtual sc_core::sc_port_base &get_port_base() { return m_port; } 152 virtual sc_core::sc_port_base const & 153 get_port_base() const 154 { 155 return m_port; 156 } 157 virtual sc_core::sc_export_base &get_export_base() { return *this; } 158 virtual sc_core::sc_export_base const & 159 get_export_base() const 160 { 161 return *this; 162 } 163 virtual unsigned int get_bus_width() const { return BUSWIDTH; } 164 virtual tlm_socket_category 165 get_socket_category() const 166 { 167 return TLM_TARGET_SOCKET; 168 } 169 170 // Implementation of tlm_base_target_socket_b functions 171 virtual sc_core::sc_port_b<BW_IF> &get_base_port() { return m_port; } 172 virtual sc_core::sc_port_b<BW_IF> const & 173 get_base_port() const 174 { 175 return m_port; 176 } 177 178 virtual FW_IF &get_base_interface() { return *this; } 179 virtual FW_IF const &get_base_interface() const { return *this; } 180 181 virtual sc_core::sc_export<FW_IF> &get_base_export() { return *this; } 182 virtual sc_core::sc_export<FW_IF> const & 183 get_base_export() const 184 { 185 return *this; 186 } 187 188 protected: 189 port_type m_port; 190}; 191 192template <unsigned int BUSWIDTH=32, typename TYPES=tlm_base_protocol_types, 193 int N=1, sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND> 194class tlm_target_socket : 195 public tlm_base_target_socket< 196 BUSWIDTH, tlm_fw_transport_if<TYPES>, 197 tlm_bw_transport_if<TYPES>, N, POL> 198{ 199 public: 200 tlm_target_socket() : 201 tlm_base_target_socket< 202 BUSWIDTH, tlm_fw_transport_if<TYPES>, 203 tlm_bw_transport_if<TYPES>, N, POL>() 204 {} 205 206 explicit tlm_target_socket(const char *name) : 207 tlm_base_target_socket< 208 BUSWIDTH, tlm_fw_transport_if<TYPES>, 209 tlm_bw_transport_if<TYPES>, N, POL>(name) 210 {} 211 212 virtual const char* kind() const { return "tlm_target_socket"; } 213
| 25#include "tlm_core/2/interfaces/fw_bw_ifs.hh" 26#include "tlm_core/2/sockets/base_socket_if.hh" 27 28namespace tlm 29{ 30 31template <unsigned int BUSWIDTH=32, typename FW_IF=tlm_fw_transport_if<>, 32 typename BW_IF=tlm_bw_transport_if<>> 33class tlm_base_target_socket_b 34{ 35 public: 36 virtual ~tlm_base_target_socket_b() {} 37 38 virtual sc_core::sc_port_b<BW_IF> &get_base_port() = 0; 39 virtual sc_core::sc_export<FW_IF> &get_base_export() = 0; 40 virtual FW_IF &get_base_interface() = 0; 41}; 42 43template <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF> 44class tlm_base_initiator_socket_b; 45 46template <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N, 47 sc_core::sc_port_policy POL> 48class tlm_base_initiator_socket; 49 50template <unsigned int BUSWIDTH=32, typename FW_IF=tlm_fw_transport_if<>, 51 typename BW_IF=tlm_bw_transport_if<>, int N=1, 52 sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND> 53class tlm_base_target_socket : 54 public tlm_base_socket_if, 55 public tlm_base_target_socket_b<BUSWIDTH, FW_IF, BW_IF>, 56 public sc_core::sc_export<FW_IF> 57{ 58 public: 59 typedef FW_IF fw_interface_type; 60 typedef BW_IF bw_interface_type; 61 typedef sc_core::sc_port<bw_interface_type, N, POL> port_type; 62 63 typedef sc_core::sc_export<fw_interface_type> export_type; 64 typedef tlm_base_initiator_socket_b< 65 BUSWIDTH, fw_interface_type, bw_interface_type> 66 base_initiator_socket_type; 67 68 typedef tlm_base_target_socket_b< 69 BUSWIDTH, fw_interface_type, bw_interface_type> base_type; 70 71 template <unsigned int, typename, typename, int, sc_core::sc_port_policy> 72 friend class tlm_base_initiator_socket; 73 74 public: 75 tlm_base_target_socket() : 76 export_type(sc_core::sc_gen_unique_name("tlm_base_target_socket")), 77 m_port(sc_core::sc_gen_unique_name("tlm_base_target_socket_port")) 78 {} 79 80 explicit tlm_base_target_socket(const char *name) : 81 export_type(name), m_port(sc_core::sc_gen_unique_name( 82 (std::string(name) + "_port").c_str())) 83 {} 84 85 virtual const char *kind() const { return "tlm_base_target_socket"; } 86 87 // 88 // Bind target socket to initiator socket 89 // - Binds the port of the initiator socket to the export of the target 90 // socket 91 // - Binds the port of the target socket to the export of the initiator 92 // socket 93 // 94 virtual void 95 bind(base_initiator_socket_type &s) 96 { 97 // initiator.port -> target.export 98 (s.get_base_port())(get_base_interface()); 99 // target.port -> initiator.export 100 get_base_port()(s.get_base_interface()); 101 } 102 103 void operator () (base_initiator_socket_type &s) { bind(s); } 104 105 // 106 // Bind target socket to target socket (hierarchical bind) 107 // - Binds both the export and the port 108 // 109 virtual void 110 bind(base_type &s) 111 { 112 // export 113 (get_base_export())(s.get_base_export()); 114 // port 115 (s.get_base_port())(get_base_port()); 116 } 117 118 void operator () (base_type &s) { bind(s); } 119 120 // 121 // Bind interface to socket 122 // - Binds the interface to the export 123 // 124 virtual void 125 bind(fw_interface_type &ifs) 126 { 127 export_type *exp = &get_base_export(); 128 if (this == exp) { 129 export_type::bind(ifs); 130 } else { 131 exp->bind( ifs ); 132 } 133 } 134 135 void operator () (fw_interface_type &s) { bind(s); } 136 137 // 138 // Forward to 'size()' of port class. 139 // 140 int size() const { return m_port.size(); } 141 142 // 143 // Forward to 'operator->()' of port class. 144 // 145 bw_interface_type *operator->() { return m_port.operator->(); } 146 147 // 148 // Forward to 'operator[]()' of port class. 149 // 150 bw_interface_type *operator[](int i) { return m_port.operator[](i); } 151 152 // Implementation of tlm_base_socket_if functions. 153 virtual sc_core::sc_port_base &get_port_base() { return m_port; } 154 virtual sc_core::sc_port_base const & 155 get_port_base() const 156 { 157 return m_port; 158 } 159 virtual sc_core::sc_export_base &get_export_base() { return *this; } 160 virtual sc_core::sc_export_base const & 161 get_export_base() const 162 { 163 return *this; 164 } 165 virtual unsigned int get_bus_width() const { return BUSWIDTH; } 166 virtual tlm_socket_category 167 get_socket_category() const 168 { 169 return TLM_TARGET_SOCKET; 170 } 171 172 // Implementation of tlm_base_target_socket_b functions 173 virtual sc_core::sc_port_b<BW_IF> &get_base_port() { return m_port; } 174 virtual sc_core::sc_port_b<BW_IF> const & 175 get_base_port() const 176 { 177 return m_port; 178 } 179 180 virtual FW_IF &get_base_interface() { return *this; } 181 virtual FW_IF const &get_base_interface() const { return *this; } 182 183 virtual sc_core::sc_export<FW_IF> &get_base_export() { return *this; } 184 virtual sc_core::sc_export<FW_IF> const & 185 get_base_export() const 186 { 187 return *this; 188 } 189 190 protected: 191 port_type m_port; 192}; 193 194template <unsigned int BUSWIDTH=32, typename TYPES=tlm_base_protocol_types, 195 int N=1, sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND> 196class tlm_target_socket : 197 public tlm_base_target_socket< 198 BUSWIDTH, tlm_fw_transport_if<TYPES>, 199 tlm_bw_transport_if<TYPES>, N, POL> 200{ 201 public: 202 tlm_target_socket() : 203 tlm_base_target_socket< 204 BUSWIDTH, tlm_fw_transport_if<TYPES>, 205 tlm_bw_transport_if<TYPES>, N, POL>() 206 {} 207 208 explicit tlm_target_socket(const char *name) : 209 tlm_base_target_socket< 210 BUSWIDTH, tlm_fw_transport_if<TYPES>, 211 tlm_bw_transport_if<TYPES>, N, POL>(name) 212 {} 213 214 virtual const char* kind() const { return "tlm_target_socket"; } 215
|