225 | | #ifndef __MY_INITIATOR_H__ |
226 | | #define __MY_INITIATOR_H__ |
227 | | |
228 | | #include "tlm.h" // TLM headers |
229 | | #include "tlmt_transactions.h" // VCI headers |
230 | | #include "tlmt_simple_initiator_socket.h" // VCI socket |
231 | | #include "mapping_table.h" |
232 | | |
233 | | class my_initiator // my_initiator |
234 | | : public sc_core::sc_module // inherit from SC module base class |
235 | | { |
236 | | private: |
237 | | //Variables |
238 | | typedef soclib::tlmt::VciParams<uint32_t,uint32_t,4> vci_param; |
239 | | sc_core::sc_event m_rspEvent; |
240 | | sc_core::sc_time m_localTime; |
241 | | bool m_activity; |
242 | | uint32_t m_initid; |
243 | | uint32_t m_counter; |
244 | | uint32_t m_lookahead; |
245 | | |
246 | | ///////////////////////////////////////////////////////////////////////////////////// |
247 | | // Fuctions |
248 | | ///////////////////////////////////////////////////////////////////////////////////// |
249 | | void execLoop(void); // initiator thread |
250 | | void addLocalTime(sc_core::sc_time t); // add a value to the local time |
251 | | void setLocalTime(sc_core::sc_time& t); // set the local time |
252 | | sc_core::sc_time getLocalTime(void); // get the local time |
253 | | void setActivity(bool t); // set the activity status (true if the component is active) |
254 | | bool getActivity(void); // get the activity state |
255 | | |
256 | | ///////////////////////////////////////////////////////////////////////////////////// |
257 | | // Virtual Fuctions tlm::tlm_bw_transport_if (VCI INITIATOR SOCKET) |
258 | | ///////////////////////////////////////////////////////////////////////////////////// |
259 | | |
260 | | /// Receive rsp from target |
261 | | tlm::tlm_sync_enum my_nb_transport_bw // for resp messages |
262 | | ( soclib_vci_types::vci_payload_type &payload, // payload |
263 | | soclib_vci_types::tlmt_phase_type &phase, // transaction phase |
264 | | sc_core::sc_time &time); // resp time |
265 | | |
266 | | protected: |
267 | | SC_HAS_PROCESS(my_initiator); |
268 | | |
269 | | public: |
270 | | tlmt_simple_initiator_socket<my_initiator,32,soclib_vci_types> p_vci_init; // VCI initiator port |
271 | | |
272 | | //constructor |
273 | | my_initiator( // constructor |
274 | | sc_core::sc_module_name name, // module name |
275 | | const soclib::common::IntTab &index, // VCI initiator index |
276 | | const soclib::common::MappingTable &mt, // mapping table |
277 | | uint32_t lookahead // lookahead |
278 | | ); |
279 | | |
280 | | }; |
281 | | #endif /* __MY_INITIATOR_H__ */ |
| 220 | |
285 | | #include "my_initiator.h" // Our header |
286 | | |
287 | | #ifndef MY_INITIATOR_DEBUG |
288 | | #define MY_INITIATOR_DEBUG 1 |
289 | | #endif |
290 | | |
291 | | #define tmpl(x) x my_initiator |
292 | | |
293 | | ///Constructor |
294 | | tmpl (/**/)::my_initiator |
295 | | ( sc_core::sc_module_name name, // module name |
296 | | const soclib::common::IntTab &index, // index of mapping table |
297 | | const soclib::common::MappingTable &mt, // mapping table |
298 | | uint32_t lookahead // lookahead |
299 | | ) |
300 | | : sc_module(name) // init module name |
301 | | , p_vci_init("p_vci_init") // vci initiator socket name |
302 | | { |
303 | | //register callback function |
304 | | p_vci_init.register_nb_transport_bw(this, &my_initiator::my_nb_transport_bw); |
305 | | |
306 | | // initiator identification |
307 | | m_initid = mt.indexForId(index); |
308 | | |
309 | | //lookahead control |
310 | | m_counter = 0; |
311 | | m_lookahead = lookahead; |
312 | | |
313 | | //initialize the local time |
314 | | m_localTime= 0 * UNIT_TIME; |
315 | | |
316 | | // initialize the activity variable |
317 | | setActivity(true); |
318 | | |
319 | | // register thread process |
320 | | SC_THREAD(execLoop); |
321 | | } |
322 | | |
323 | | ///////////////////////////////////////////////////////////////////////////////////// |
324 | | // Fuctions |
325 | | ///////////////////////////////////////////////////////////////////////////////////// |
326 | | tmpl (sc_core::sc_time)::getLocalTime() |
327 | | { |
328 | | return m_localTime; |
329 | | } |
330 | | |
331 | | tmpl (bool)::getActivity() |
332 | | { |
333 | | return m_activity; |
334 | | } |
335 | | |
336 | | tmpl (void)::setLocalTime(sc_core::sc_time &t) |
337 | | { |
338 | | m_localTime=t; |
339 | | } |
340 | | |
341 | | tmpl (void)::addLocalTime(sc_core::sc_time t) |
342 | | { |
343 | | m_localTime= m_localTime + t; |
344 | | } |
345 | | |
346 | | tmpl (void)::setActivity(bool t) |
347 | | { |
348 | | m_activity =t; |
349 | | } |
350 | | |
351 | | tmpl (void)::execLoop(void) // initiator thread |
352 | | { |
353 | | soclib_vci_types::vci_payload_type payload; |
354 | | soclib_vci_types::tlmt_phase_type phase; |
355 | | sc_core::sc_time sendTime; |
356 | | unsigned char data[32]; |
357 | | unsigned char byte_enable[32]; |
358 | | int pktid = 0; |
359 | | int nbytes = 4; // 1 word of 32 bits |
360 | | |
361 | | uint32_t int_data = 12345678; |
362 | | std::ostringstream name; |
363 | | name << "" << int_data; |
364 | | std::cout << "NAME = " << std::dec << name << std::endl; |
365 | | |
366 | | for(int i=0; i<nbytes; i++) |
367 | | byte_enable[i] = TLMT_BYTE_ENABLED; |
368 | | |
369 | | for(int i=0; i<32; i++) |
370 | | data[i] = 0x0; |
371 | | |
372 | | data[0]='a'; |
373 | | data[1]='b'; |
374 | | data[2]='c'; |
375 | | data[3]='d'; |
376 | | data[4]='\0'; |
377 | | |
378 | | std ::cout<< "DATA = " << data << std::endl; |
379 | | |
380 | | while ( 1 ){ |
381 | | addTime(10 * UNIT_TIME); |
382 | | |
383 | | payload.set_address(0x10000000);//ram 0 |
384 | | payload.set_byte_enable_ptr(byte_enable); |
385 | | payload.set_byte_enable_length(nbytes); |
386 | | payload.set_data_ptr(data); |
387 | | payload.set_data_length(nbytes); // 5 words of 32 bits |
388 | | |
389 | | payload.set_write(); |
390 | | payload.set_src_id(m_id); |
391 | | payload.set_trd_id(0); |
392 | | payload.set_pkt_id(pktid); |
393 | | |
394 | | phase= soclib::tlmt::TLMT_CMD; |
395 | | sendTime = getLocalTime(); |
396 | | |
397 | | #if MY_INITIATOR_DEBUG |
398 | | std::cout << "[INITIATOR " << m_id << "] send cmd packet id = " << payload.get_pkt_id() << " time = " << getLocalTime().value() << std::endl; |
399 | | #endif |
400 | | |
401 | | p_vci_init->nb_transport_fw(payload, phase, sendTime); |
402 | | wait(m_rspEvent); |
403 | | |
404 | | #if MY_INITIATOR_DEBUG |
405 | | std::cout << "[INITIATOR " << m_id << "] receive rsp packet id = " << payload.get_pkt_id() << " time = " << getLocalTime().value() << std::endl; |
406 | | #endif |
407 | | |
408 | | pktid++; |
409 | | |
410 | | addTime(10 * UNIT_TIME); |
411 | | |
412 | | payload.set_address(0x10000000);//ram 0 |
413 | | payload.set_byte_enable_ptr(byte_enable); |
414 | | payload.set_byte_enable_length(nbytes); |
415 | | payload.set_data_ptr(data); |
416 | | payload.set_data_length(nbytes); // 5 words of 32 bits |
417 | | |
418 | | payload.set_read(); |
419 | | payload.set_src_id(m_id); |
420 | | payload.set_trd_id(0); |
421 | | payload.set_pkt_id(pktid); |
422 | | |
423 | | phase= soclib::tlmt::TLMT_CMD; |
424 | | sendTime = getLocalTime(); |
425 | | |
426 | | #if MY_INITIATOR_DEBUG |
427 | | std::cout << "[INITIATOR " << m_id << "] send cmd packet id = " << payload.get_pkt_id() << " time = " << getLocalTime().value() << std::endl; |
428 | | #endif |
429 | | |
430 | | p_vci_init->nb_transport_fw(payload, phase, sendTime); |
431 | | wait(m_rspEvent); |
432 | | |
433 | | #if MY_INITIATOR_DEBUG |
434 | | std::cout << "[INITIATOR " << m_id << "] receive rsp packet id = " << payload.get_pkt_id() << " time = " << getLocalTime().value() << std::endl; |
435 | | |
436 | | #endif |
437 | | |
438 | | pktid++; |
439 | | |
440 | | // lookahead management |
441 | | m_counter++ ; |
442 | | if (m_counter >= m_lookahead) { |
443 | | m_counter = 0 ; |
444 | | wait(sc_core::SC_ZERO_TIME) ; |
445 | | } |
446 | | |
447 | | } // end while true |
448 | | setActivity(false); |
449 | | } // end initiator_thread |
450 | | |
451 | | |
452 | | ///////////////////////////////////////////////////////////////////////////////////// |
453 | | // Virtual Fuctions tlm::tlm_bw_transport_if (VCI SOCKET) |
454 | | ///////////////////////////////////////////////////////////////////////////////////// |
455 | | |
456 | | /// receive the response packet from target socket |
457 | | tmpl (tlm::tlm_sync_enum)::my_nb_transport_bw // inbound nb_transport_bw |
458 | | ( soclib_vci_types::vci_payload_type &payload, // VCI payload |
459 | | soclib_vci_types::tlmt_phase_type &phase, // tlm phase |
460 | | sc_core::sc_time &rspTime // the response timestamp |
461 | | ) |
462 | | { |
463 | | switch(phase){ |
464 | | case soclib::tlmt::TLMT_RSP : |
465 | | setLocalTime(rspTime); |
466 | | m_rspEvent.notify(0 * UNIT_TIME); |
467 | | break; |
468 | | case soclib::tlmt::TLMT_INFO : |
469 | | payload.set_local_time_ptr(&m_localTime); |
470 | | payload.set_activity_ptr(&m_activity); |
471 | | break; |
472 | | } |
473 | | return tlm::TLM_COMPLETED; |
474 | | } // end backward nb transport |
530 | | #ifndef __MY_TARGET_H__ |
531 | | #define __MY_TARGET_H__ |
532 | | |
533 | | #include "tlm.h" // TLM headers |
534 | | #include "tlmt_transactions.h" // VCI headers |
535 | | #include "tlmt_simple_target_socket.h" // VCI SOCKET |
536 | | #include "mapping_table.h" |
537 | | #include "soclib_endian.h" |
538 | | |
539 | | class my_target |
540 | | : public sc_core::sc_module |
541 | | { |
542 | | private: |
543 | | typedef soclib::tlmt::VciParams<uint32_t,uint32_t,4> vci_param; |
544 | | |
545 | | uint32_t m_targetid; |
546 | | soclib::common::MappingTable m_mt; |
547 | | |
548 | | |
549 | | ///////////////////////////////////////////////////////////////////////////////////// |
550 | | // Virtual Fuctions tlm::tlm_fw_transport_if (VCI SOCKET) |
551 | | ///////////////////////////////////////////////////////////////////////////////////// |
552 | | |
553 | | // receive command from initiator |
554 | | tlm::tlm_sync_enum my_nb_transport_fw /// sync status |
555 | | ( soclib_vci_types::vci_payload_type &payload, ///< VCI payload pointer |
556 | | soclib_vci_types::tlmt_phase_type &phase, ///< transaction phase |
557 | | sc_core::sc_time &time); ///< time |
558 | | |
559 | | protected: |
560 | | SC_HAS_PROCESS(my_target); |
561 | | public: |
562 | | tlmt_simple_target_socket<my_target,32,soclib_vci_types> p_vci_target; ///< VCI target socket |
563 | | |
564 | | my_target(sc_core::sc_module_name name, |
565 | | const soclib::common::IntTab &index, |
566 | | const soclib::common::MappingTable &mt); |
567 | | |
568 | | ~my_target(); |
569 | | }; |
570 | | |
571 | | #endif |
575 | | #include "my_target.h" |
576 | | |
577 | | #ifndef MY_TARGET_DEBUG |
578 | | #define MY_TARGET_DEBUG 1 |
579 | | #endif |
580 | | |
581 | | #define tmpl(x) x my_target |
582 | | |
583 | | ////////////////////////////////////////////////////////////////////////////////////////// |
584 | | // CONSTRUCTOR |
585 | | ////////////////////////////////////////////////////////////////////////////////////////// |
586 | | tmpl(/**/)::my_target |
587 | | ( sc_core::sc_module_name name, |
588 | | const soclib::common::IntTab &index, |
589 | | const soclib::common::MappingTable &mt) |
590 | | : sc_module(name), |
591 | | m_mt(mt), |
592 | | p_vci_target("p_vci_target") |
593 | | { |
594 | | //register callback fuction |
595 | | p_vci_target.register_nb_transport_fw(this, &my_target::my_nb_transport_fw); |
596 | | |
597 | | m_id = m_mt.indexForId(index); |
598 | | } |
599 | | |
600 | | tmpl(/**/)::~my_target(){} |
601 | | |
602 | | ///////////////////////////////////////////////////////////////////////////////////// |
603 | | // Virtual Fuctions tlm::tlm_fw_transport_if VCI SOCKET |
604 | | ///////////////////////////////////////////////////////////////////////////////////// |
605 | | |
606 | | //nb_transport_fw implementation calls from initiators |
607 | | tmpl(tlm::tlm_sync_enum)::my_nb_transport_fw // non-blocking transport call through Bus |
608 | | ( soclib_vci_types::vci_payload_type &payload, // VCI payload pointer |
609 | | soclib_vci_types::tlmt_phase_type &phase, // transaction phase |
610 | | sc_core::sc_time &time) // time |
611 | | { |
612 | | int nwords = payload.get_data_length() / vci_param::nbytes; |
613 | | switch(payload.get_command()){ |
614 | | case soclib::tlmt::VCI_READ_COMMAND: |
615 | | case soclib::tlmt::VCI_WRITE_COMMAND: |
616 | | case soclib::tlmt::VCI_LOCKED_READ_COMMAND: |
617 | | case soclib::tlmt::VCI_STORE_COND_COMMAND: |
618 | | { |
619 | | #if MY_TARGET_DEBUG |
620 | | std::cout << "[RAM " << m_id << "] Receive from source " << payload.get_src_id() <<" a packet "<< payload.get_pkt_id() << " Time = " << time.value() << std::endl; |
621 | | #endif |
622 | | |
623 | | payload.set_response_status(soclib::tlmt::TLMT_OK_RESPONSE); |
624 | | |
625 | | phase = soclib::tlmt::TLMT_VCI_RSP; |
626 | | time = time + (nwords * UNIT_TIME); |
627 | | |
628 | | #if MY_TARGET_DEBUG |
629 | | std::cout << "[RAM " << m_id << "] Send to source "<< payload.get_src_id() << " a anwser packet " << payload.get_pkt_id() << " Time = " << time.value() << std::endl; |
630 | | #endif |
631 | | |
632 | | p_vci_target->nb_transport_bw(payload, phase, time); |
633 | | return tlm::TLM_COMPLETED; |
634 | | } |
635 | | break; |
636 | | default: |
637 | | break; |
638 | | } |
639 | | |
640 | | //send error message |
641 | | payload.set_response_status(soclib::tlmt::TLMT_ERROR_RESPONSE); |
642 | | |
643 | | phase = soclib::tlmt::TLMT_VCI_RSP; |
644 | | time = time + nwords * UNIT_TIME; |
645 | | |
646 | | #if MY_TARGET_DEBUG |
647 | | std::cout << "[RAM " << m_id << "] Address " << payload.get_address() << " does not match any segment " << std::endl; |
648 | | std::cout << "[RAM " << m_id << "] Send to source "<< payload.get_src_id() << " a error packet with time = " << time.value() << std::endl; |
649 | | #endif |
650 | | p_vci_target->nb_transport_bw(payload, phase, time); |
651 | | return tlm::TLM_COMPLETED; |
652 | | } |
653 | | |
654 | | }}} |
655 | | |
656 | | = E) VCI Interconnect = |
| 282 | |
| 283 | }}} |
| 284 | |
| 285 | = E) VCI Interconnect modelling = |