00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __MULTI_SOCKET_BASES_H__
00019 #define __MULTI_SOCKET_BASES_H__
00020
00021 #include <systemc>
00022
00023 #if !(SYSTEMC_VERSION <= 20050714)
00024 # include "sysc/kernel/sc_boost.h"
00025 # include "sysc/kernel/sc_spawn.h"
00026 # include "sysc/kernel/sc_spawn_options.h"
00027 #endif
00028 #include "tlm.h"
00029
00030 #include "boost/function.hpp"
00031 #include "boost/mem_fn.hpp"
00032 #include <map>
00033
00034 namespace tlm_utils {
00035
00036
00037
00038
00039
00040
00041
00042
00043 template <typename TYPES>
00044 class callback_binder_fw: public tlm::tlm_fw_transport_if<TYPES>{
00045 public:
00046
00047 typedef typename TYPES::tlm_payload_type transaction_type;
00048 typedef typename TYPES::tlm_phase_type phase_type;
00049 typedef tlm::tlm_sync_enum sync_enum_type;
00050
00051
00052 typedef boost::function<sync_enum_type (int i, transaction_type& txn, phase_type& ph, sc_core::sc_time& t)> nb_func_type;
00053 typedef boost::function<void (int i, transaction_type& txn, sc_core::sc_time& t)> b_func_type;
00054 typedef boost::function<unsigned int (int i, transaction_type& txn)> debug_func_type;
00055 typedef boost::function<bool (int i, transaction_type& txn, tlm::tlm_dmi& dmi)> dmi_func_type;
00056
00057
00058 callback_binder_fw(int id): m_id(id){
00059 }
00060
00061
00062 sync_enum_type nb_transport_fw(transaction_type& txn,
00063 phase_type& p,
00064 sc_core::sc_time& t){
00065
00066 if (m_nb_f->empty()){
00067 std::cerr<<"No function registered"<<std::endl;
00068 exit(1);
00069 }
00070 else
00071 return (*m_nb_f)(m_id, txn, p, t);
00072 }
00073
00074
00075 void b_transport(transaction_type& trans,sc_core::sc_time& t){
00076
00077 if (m_b_f->empty()){
00078 std::cerr<<"No function registered"<<std::endl;
00079 exit(1);
00080 }
00081 else
00082 (*m_b_f)(m_id, trans,t);
00083 }
00084
00085
00086 bool get_direct_mem_ptr(transaction_type& trans, tlm::tlm_dmi& dmi_data){
00087
00088 if (m_dmi_f->empty()){
00089 std::cerr<<"No function registered"<<std::endl;
00090 exit(1);
00091 }
00092 else
00093 return (*m_dmi_f)(m_id, trans,dmi_data);
00094 }
00095
00096
00097 unsigned int transport_dbg(transaction_type& trans){
00098
00099 if (m_dbg_f->empty()){
00100 std::cerr<<"No function registered"<<std::endl;
00101 exit(1);
00102 }
00103 else
00104 return (*m_dbg_f)(m_id, trans);
00105 }
00106
00107
00108
00109
00110 void register_port(sc_core::sc_port_base& b, const char* name){
00111 m_caller_port=&b;
00112 }
00113
00114
00115 void set_callbacks(nb_func_type& cb1, b_func_type& cb2, dmi_func_type& cb3, debug_func_type& cb4){
00116 m_nb_f=&cb1;
00117 m_b_f=&cb2;
00118 m_dmi_f=&cb3;
00119 m_dbg_f=&cb4;
00120 }
00121
00122
00123
00124
00125 sc_core::sc_port_base* get_other_side(){return m_caller_port;}
00126
00127 private:
00128
00129 int m_id;
00130
00131
00132 nb_func_type* m_nb_f;
00133 b_func_type* m_b_f;
00134 debug_func_type* m_dbg_f;
00135 dmi_func_type* m_dmi_f;
00136
00137
00138 sc_core::sc_port_base* m_caller_port;
00139 };
00140
00141
00142
00143
00144
00145
00146
00147 template <typename TYPES>
00148 class callback_binder_bw: public tlm::tlm_bw_transport_if<TYPES>{
00149 public:
00150
00151 typedef typename TYPES::tlm_payload_type transaction_type;
00152 typedef typename TYPES::tlm_phase_type phase_type;
00153 typedef tlm::tlm_sync_enum sync_enum_type;
00154
00155
00156 typedef boost::function<sync_enum_type (int i, transaction_type& txn, phase_type& p, sc_core::sc_time& t)> nb_func_type;
00157 typedef boost::function<void (int i, sc_dt::uint64 l, sc_dt::uint64 u)> dmi_func_type;
00158
00159
00160 callback_binder_bw(int id): m_id(id){
00161 }
00162
00163
00164 sync_enum_type nb_transport_bw(transaction_type& txn,
00165 phase_type& p,
00166 sc_core::sc_time& t){
00167
00168 if (m_nb_f->empty()){
00169 std::cerr<<"No function registered"<<std::endl;
00170 exit(1);
00171 }
00172 else
00173 return (*m_nb_f)(m_id, txn, p, t);
00174 }
00175
00176
00177 void invalidate_direct_mem_ptr(sc_dt::uint64 l, sc_dt::uint64 u){
00178
00179 if (m_nb_f->empty()){
00180 std::cerr<<"No function registered"<<std::endl;
00181 exit(1);
00182 }
00183 else
00184 (*m_dmi_f)(m_id,l,u);
00185 }
00186
00187
00188 void set_callbacks(nb_func_type& cb1, dmi_func_type& cb2){
00189 m_nb_f=&cb1;
00190 m_dmi_f=&cb2;
00191 }
00192
00193 private:
00194
00195 int m_id;
00196
00197 nb_func_type* m_nb_f;
00198 dmi_func_type* m_dmi_f;
00199 };
00200
00201
00202
00203
00204
00205
00206
00207 template <unsigned int BUSWIDTH = 32,
00208 typename TYPES = tlm::tlm_base_protocol_types,
00209 unsigned int N=0
00210 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
00211 ,sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND
00212 #endif
00213 >
00214 class multi_init_base: public tlm::tlm_initiator_socket<BUSWIDTH,
00215 TYPES,
00216 N
00217 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
00218 ,POL
00219 #endif
00220 >{
00221 public:
00222
00223 typedef tlm::tlm_initiator_socket<BUSWIDTH,
00224 TYPES,
00225 N
00226 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
00227 ,POL
00228 #endif
00229 > base_type;
00230
00231
00232
00233 virtual void disable_cb_bind()=0;
00234
00235
00236
00237
00238 virtual multi_init_base* get_hierarch_bind()=0;
00239
00240
00241 virtual std::vector<callback_binder_bw<TYPES>* >& get_binders()=0;
00242
00243
00244 virtual std::vector<tlm::tlm_fw_transport_if<TYPES>*>& get_sockets()=0;
00245
00246
00247 virtual ‾multi_init_base(){}
00248 multi_init_base(const char* name):base_type(name){}
00249 };
00250
00251
00252
00253
00254
00255
00256 template <unsigned int BUSWIDTH = 32,
00257 typename TYPES = tlm::tlm_base_protocol_types,
00258 unsigned int N=0
00259 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
00260 ,sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND
00261 #endif
00262 >
00263 class multi_target_base: public tlm::tlm_target_socket<BUSWIDTH,
00264 TYPES,
00265 N
00266 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
00267 ,POL
00268 #endif
00269 >{
00270 public:
00271
00272 typedef tlm::tlm_target_socket<BUSWIDTH,
00273 TYPES,
00274 N
00275 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
00276 ,POL
00277 #endif
00278 > base_type;
00279
00280
00281
00282
00283 virtual multi_target_base* get_hierarch_bind()=0;
00284
00285
00286
00287 virtual void set_hierarch_bind(multi_target_base*)=0;
00288
00289
00290 virtual std::vector<callback_binder_fw<TYPES>* >& get_binders()=0;
00291
00292
00293
00294
00295 virtual std::map<unsigned int, tlm::tlm_bw_transport_if<TYPES>*>& get_multi_binds()=0;
00296
00297
00298 virtual ‾multi_target_base(){}
00299 multi_target_base(const char* name):base_type(name){}
00300 };
00301
00302
00303
00304
00305
00306
00307 template <typename TYPES>
00308 class multi_to_multi_bind_base{
00309 public:
00310 virtual ‾multi_to_multi_bind_base(){}
00311 virtual tlm::tlm_fw_transport_if<TYPES>* get_last_binder(tlm::tlm_bw_transport_if<TYPES>*)=0;
00312 };
00313
00314 }
00315
00316 #endif