|  | 196 | #ifndef __MY_INITIATOR_H__ | 
                          |  | 197 | #define __MY_INITIATOR_H__ | 
                          |  | 198 |  | 
                          |  | 199 | #include "tlm.h"                                // TLM headers | 
                          |  | 200 | #include "tlmt_transactions.h"                  // VCI headers | 
                          |  | 201 | #include "tlmt_simple_initiator_socket.h"       // VCI socket | 
                          |  | 202 | #include "mapping_table.h" | 
                          |  | 203 |  | 
                          |  | 204 | class my_initiator                              // my_initiator | 
                          |  | 205 | :         public sc_core::sc_module             // inherit from SC module base class | 
                          |  | 206 | { | 
                          |  | 207 | private: | 
                          |  | 208 | //Variables | 
                          |  | 209 | typedef soclib::tlmt::VciParams<uint32_t,uint32_t,4> vci_param; | 
                          |  | 210 | sc_core::sc_event m_rspEvent; | 
                          |  | 211 | sc_core::sc_time m_localTime; | 
                          |  | 212 | bool m_activity; | 
                          |  | 213 | uint32_t m_initid; | 
                          |  | 214 | uint32_t m_counter; | 
                          |  | 215 | uint32_t m_lookahead; | 
                          |  | 216 |  | 
                          |  | 217 | ///////////////////////////////////////////////////////////////////////////////////// | 
                          |  | 218 | // Functions | 
                          |  | 219 | ///////////////////////////////////////////////////////////////////////////////////// | 
                          |  | 220 | void execLoop(void);                              // initiator thread | 
                          |  | 221 | void addLocalTime(sc_core::sc_time t);            // add a value to the local time | 
                          |  | 222 | void setLocalTime(sc_core::sc_time& t);           // set the local time | 
                          |  | 223 | sc_core::sc_time getLocalTime(void);              // get the local time | 
                          |  | 224 | void setActivity(bool t);                         // set the activity status (true if the component is active) | 
                          |  | 225 | bool getActivity(void);                           // get the activity state | 
                          |  | 226 |  | 
                          |  | 227 | ///////////////////////////////////////////////////////////////////////////////////// | 
                          |  | 228 | // Virtual Fuctions  tlm::tlm_bw_transport_if (VCI INITIATOR SOCKET) | 
                          |  | 229 | ///////////////////////////////////////////////////////////////////////////////////// | 
                          |  | 230 |  | 
                          |  | 231 | /// Receive rsp from target | 
                          |  | 232 | tlm::tlm_sync_enum vci_rsp_received                // for resp messages | 
                          |  | 233 | ( soclib_vci_types::tlm_payload_type &payload,   // payload | 
                          |  | 234 | soclib_vci_types::tlm_phase_type   &phase,     // transaction phase | 
                          |  | 235 | sc_core::sc_time                   &time);     // resp time | 
                          |  | 236 |  | 
                          |  | 237 | protected: | 
                          |  | 238 | SC_HAS_PROCESS(my_initiator); | 
                          |  | 239 |  | 
                          |  | 240 | public: | 
                          |  | 241 | tlmt_simple_initiator_socket<my_initiator,32,soclib_vci_types> p_vci_init;   // VCI initiator port | 
                          |  | 242 |  | 
                          |  | 243 | //constructor | 
                          |  | 244 | my_initiator(                                              // constructor | 
                          |  | 245 | sc_core::sc_module_name name,                 // module name | 
                          |  | 246 | const soclib::common::IntTab &index,          // VCI initiator index | 
                          |  | 247 | const soclib::common::MappingTable &mt,       // mapping table | 
                          |  | 248 | uint32_t lookahead                            // lookahead | 
                          |  | 249 | ); | 
                          |  | 250 |  | 
                          |  | 251 | }; | 
                          |  | 252 | #endif /* __MY_INITIATOR_H__ */ | 
            
                  
                          |  | 255 | #include "my_initiator.h"                       // Our header | 
                          |  | 256 |  | 
                          |  | 257 | #ifndef MY_INITIATOR_DEBUG | 
                          |  | 258 | #define MY_INITIATOR_DEBUG 1 | 
                          |  | 259 | #endif | 
                          |  | 260 |  | 
                          |  | 261 | #define tmpl(x) x my_initiator | 
                          |  | 262 |  | 
                          |  | 263 | ///Constructor | 
                          |  | 264 | tmpl (/**/)::my_initiator | 
                          |  | 265 | ( sc_core::sc_module_name name,           // module name | 
                          |  | 266 | const soclib::common::IntTab &index,    // index of mapping table | 
                          |  | 267 | const soclib::common::MappingTable &mt, // mapping table | 
                          |  | 268 | uint32_t lookahead                      // lookahead | 
                          |  | 269 | ) | 
                          |  | 270 | : sc_module(name)                         // init module name | 
                          |  | 271 | , p_vci_init("p_vci_init")                 // vci initiator socket name | 
                          |  | 272 | { | 
                          |  | 273 | //register callback function | 
                          |  | 274 | p_vci_init.register_nb_transport_bw(this, &my_initiator::vci_rsp_received); | 
                          |  | 275 |  | 
                          |  | 276 | // initiator identification | 
                          |  | 277 | m_initid = mt.indexForId(index); | 
                          |  | 278 |  | 
                          |  | 279 | //lookahead control | 
                          |  | 280 | m_counter = 0; | 
                          |  | 281 | m_lookahead = lookahead; | 
                          |  | 282 |  | 
                          |  | 283 | //initialize the local time | 
                          |  | 284 | m_localTime= 0 * UNIT_TIME; | 
                          |  | 285 |  | 
                          |  | 286 | // initialize the activity variable | 
                          |  | 287 | setActivity(true); | 
                          |  | 288 |  | 
                          |  | 289 | // register thread process | 
                          |  | 290 | SC_THREAD(execLoop); | 
                          |  | 291 | } | 
                          |  | 292 |  | 
                          |  | 293 | ///////////////////////////////////////////////////////////////////////////////////// | 
                          |  | 294 | // Functions | 
                          |  | 295 | ///////////////////////////////////////////////////////////////////////////////////// | 
                          |  | 296 | tmpl (sc_core::sc_time)::getLocalTime() | 
                          |  | 297 | { | 
                          |  | 298 | return m_localTime; | 
                          |  | 299 | } | 
                          |  | 300 |  | 
                          |  | 301 | tmpl (bool)::getActivity() | 
                          |  | 302 | { | 
                          |  | 303 | return m_activity; | 
                          |  | 304 | } | 
                          |  | 305 |  | 
                          |  | 306 | tmpl (void)::setLocalTime(sc_core::sc_time &t) | 
                          |  | 307 | { | 
                          |  | 308 | m_localTime=t; | 
                          |  | 309 | } | 
                          |  | 310 |  | 
                          |  | 311 | tmpl (void)::addLocalTime(sc_core::sc_time t) | 
                          |  | 312 | { | 
                          |  | 313 | m_localTime= m_localTime + t; | 
                          |  | 314 | } | 
                          |  | 315 |  | 
                          |  | 316 | tmpl (void)::setActivity(bool t) | 
                          |  | 317 | { | 
                          |  | 318 | m_activity =t; | 
                          |  | 319 | } | 
                          |  | 320 |  | 
                          |  | 321 | tmpl (void)::execLoop(void)   // initiator thread | 
                          |  | 322 | { | 
                          |  | 323 | soclib_vci_types::tlm_payload_type payload; | 
                          |  | 324 | soclib_vci_types::tlm_phase_type phase; | 
                          |  | 325 | sc_core::sc_time sendTime; | 
                          |  | 326 | unsigned char data[32]; | 
                          |  | 327 | unsigned char byte_enable[32]; | 
                          |  | 328 | int pktid = 0; | 
                          |  | 329 | int nbytes = 4; // 1 word of 32 bits | 
                          |  | 330 |  | 
                          |  | 331 | uint32_t int_data = 12345678; | 
                          |  | 332 | std::ostringstream name; | 
                          |  | 333 | name << "" << int_data; | 
                          |  | 334 | std::cout << "NAME = " << std::dec << name << std::endl; | 
                          |  | 335 |  | 
                          |  | 336 | for(int i=0; i<nbytes; i++) | 
                          |  | 337 | byte_enable[i] = TLMT_BYTE_ENABLED; | 
                          |  | 338 |  | 
                          |  | 339 | for(int i=0; i<32; i++) | 
                          |  | 340 | data[i] = 0x0; | 
                          |  | 341 |  | 
                          |  | 342 | data[0]='a'; | 
                          |  | 343 | data[1]='b'; | 
                          |  | 344 | data[2]='c'; | 
                          |  | 345 | data[3]='d'; | 
                          |  | 346 | data[4]='\0'; | 
                          |  | 347 |  | 
                          |  | 348 | std ::cout<< "DATA = " << data << std::endl; | 
                          |  | 349 |  | 
                          |  | 350 | while ( 1 ){ | 
                          |  | 351 | addLocalTime(10 * UNIT_TIME); | 
                          |  | 352 |  | 
                          |  | 353 | payload.set_address(0x10000000);//ram 0 | 
                          |  | 354 | payload.set_byte_enable_ptr(byte_enable); | 
                          |  | 355 | payload.set_byte_enable_length(nbytes); | 
                          |  | 356 | payload.set_data_ptr(data); | 
                          |  | 357 | payload.set_data_length(nbytes); // 5 words of 32 bits | 
                          |  | 358 |  | 
                          |  | 359 | payload.set_write(); | 
                          |  | 360 | payload.set_src_id(m_initid); | 
                          |  | 361 | payload.set_trd_id(0); | 
                          |  | 362 | payload.set_pkt_id(pktid); | 
                          |  | 363 |  | 
                          |  | 364 | phase= soclib::tlmt::TLMT_CMD; | 
                          |  | 365 | sendTime = getLocalTime(); | 
                          |  | 366 |  | 
                          |  | 367 | #if MY_INITIATOR_DEBUG | 
                          |  | 368 | std::cout << "[INITIATOR " << m_initid << "] send cmd packet id = " << payload.get_pkt_id() << " time = " << getLocalTime().value() << std::endl; | 
                          |  | 369 | #endif | 
                          |  | 370 |  | 
                          |  | 371 | p_vci_init->nb_transport_fw(payload, phase, sendTime); | 
                          |  | 372 | wait(m_rspEvent); | 
                          |  | 373 |  | 
                          |  | 374 | #if MY_INITIATOR_DEBUG | 
                          |  | 375 | std::cout << "[INITIATOR " << m_initid << "] receive rsp packet id = " << payload.get_pkt_id() << " time = " << getLocalTime().value() << std::endl; | 
                          |  | 376 | #endif | 
                          |  | 377 |  | 
                          |  | 378 | pktid++; | 
                          |  | 379 |  | 
                          |  | 380 | addLocalTime(10 * UNIT_TIME); | 
                          |  | 381 |  | 
                          |  | 382 | payload.set_address(0x10000000);//ram 0 | 
                          |  | 383 | payload.set_byte_enable_ptr(byte_enable); | 
                          |  | 384 | payload.set_byte_enable_length(nbytes); | 
                          |  | 385 | payload.set_data_ptr(data); | 
                          |  | 386 | payload.set_data_length(nbytes); // 5 words of 32 bits | 
                          |  | 387 | payload.set_read(); | 
                          |  | 388 | payload.set_src_id(m_initid); | 
                          |  | 389 | payload.set_trd_id(0); | 
                          |  | 390 | payload.set_pkt_id(pktid); | 
                          |  | 391 |  | 
                          |  | 392 | phase= soclib::tlmt::TLMT_CMD; | 
                          |  | 393 | sendTime = getLocalTime(); | 
                          |  | 394 |  | 
                          |  | 395 | #if MY_INITIATOR_DEBUG | 
                          |  | 396 | std::cout << "[INITIATOR " << m_initid << "] send cmd packet id = " << payload.get_pkt_id() << " time = " << getLocalTime().value() << std::endl; | 
                          |  | 397 | #endif | 
                          |  | 398 |  | 
                          |  | 399 | p_vci_init->nb_transport_fw(payload, phase, sendTime); | 
                          |  | 400 | wait(m_rspEvent); | 
                          |  | 401 |  | 
                          |  | 402 | #if MY_INITIATOR_DEBUG | 
                          |  | 403 | std::cout << "[INITIATOR " << m_initid << "] receive rsp packet id = " << payload.get_pkt_id() << " time = " << getLocalTime().value() << std::endl; | 
                          |  | 404 |  | 
                          |  | 405 | #endif | 
                          |  | 406 |  | 
                          |  | 407 | pktid++; | 
                          |  | 408 |  | 
                          |  | 409 | // lookahead management | 
                          |  | 410 | m_counter++ ; | 
                          |  | 411 | if (m_counter >= m_lookahead) { | 
                          |  | 412 | m_counter = 0 ; | 
                          |  | 413 | wait(sc_core::SC_ZERO_TIME) ; | 
                          |  | 414 | } | 
                          |  | 415 |  | 
                          |  | 416 | } // end while true | 
                          |  | 417 | setActivity(false); | 
                          |  | 418 | } // end initiator_thread | 
                          |  | 419 |  | 
                          |  | 420 |  | 
                          |  | 421 | ///////////////////////////////////////////////////////////////////////////////////// | 
                          |  | 422 | // Virtual Functions  tlm::tlm_bw_transport_if (VCI SOCKET) | 
                          |  | 423 | ///////////////////////////////////////////////////////////////////////////////////// | 
                          |  | 424 | /// receive the response packet from target socket | 
                          |  | 425 |  | 
                          |  | 426 | tmpl (tlm::tlm_sync_enum)::vci_rsp_received          // | 
                          |  | 427 | ( soclib_vci_types::tlm_payload_type &payload,       // VCI payload | 
                          |  | 428 | soclib_vci_types::tlm_phase_type   &phase,         // tlm phase | 
                          |  | 429 | sc_core::sc_time                   &rspTime        // time | 
                          |  | 430 | ) | 
                          |  | 431 | { | 
                          |  | 432 | switch(phase){ | 
                          |  | 433 | case soclib::tlmt::TLMT_RSP : | 
                          |  | 434 | setLocalTime(rspTime); | 
                          |  | 435 | m_rspEvent.notify(0 * UNIT_TIME); | 
                          |  | 436 | break; | 
                          |  | 437 | case soclib::tlmt::TLMT_INFO : | 
                          |  | 438 | payload.set_local_time_ptr(&m_localTime); | 
                          |  | 439 | payload.set_activity_ptr(&m_activity); | 
                          |  | 440 | break; | 
                          |  | 441 | } | 
                          |  | 442 | return tlm::TLM_COMPLETED; | 
                          |  | 443 | } // end backward nb transport | 
                          |  | 444 |  |