Changes between Version 60 and Version 61 of Writing Rules/Tlmt


Ignore:
Timestamp:
Nov 15, 2008, 3:50:06 PM (15 years ago)
Author:
alain
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Writing Rules/Tlmt

    v60 v61  
    177177constrained, but the arguments must respect the following prototype:
    178178{{{
    179   tlm::tlm_sync_enum vci_rsp_received                // for resp messages
     179  tlm::tlm_sync_enum vci_rsp_received             
    180180    ( soclib_vci_types::tlm_payload_type &payload,     // payload
    181181      soclib_vci_types::tlm_phase_type   &phase,      // transaction phase
     
    187187In the general case, the actions executed by the call-back function depend on the response transaction type ('''m_command''' field), as well as
    188188the '''pktid''' and '''trdid''' fields.
    189 
    190 For sake of simplicity, in the proposed example the call-back function does not make any distinction between VCI transaction types :
     189For sake of simplicity, the call-back function proposed below does not make any distinction between VCI transaction types.
    191190
    192191== C.3) Initiator Constructor ==
    193192
    194193The constructor of the class '''my_initiator''' must initialize all the member variables, including
    195 the '''p_vci_init''' port. The '''my_nb_transport_bw()''' call-back function being executed in the context of the thread sending
    196 the response packet, a link between the '''p_vci_init''' port and the call-back function must be established.
    197 The TLMT_INFO transaction allows the target to
    198 get information on the initiator that actually sends VCI packets (the initiator local time, the initiator activity, etc).
     194the '''p_vci_init''' port. The '''vci_rsp_received()''' call-back function being executed in the context of the thread sending
     195the response packet, a link between the '''p_vci_init''' port and this call-back function must be established.
    199196
    200197The '''my_initiator''' constructor for the '''p_vci_init''' object must be called with the following arguments:
    201198{{{
    202   p_vci_init.register_nb_transport_bw(this, &my_initiator::my_nb_transport_bw);
    203 }}}
    204 
    205 where '''my_nb_transport_bw''' is the name of the callback function
     199  p_vci_init.register_nb_transport_bw(this, &my_initiator::vci_rsp_received);
     200}}}
    206201
    207202== C.4) Lookahead parameter ==
     
    223218
    224219////////////////////////// my_initiator.h ////////////////////////////////
    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
    282221
    283222////////////////////////// my_initiator.cpp ////////////////////////////////
    284223
    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
    475224
    476225}}}
     
    478227= D) VCI target modeling =
    479228
    480 In the proposed example, the target handles all VCI commands in the same way. To simplify the model, there is no real error management.
     229In the proposed example, the '''my_target''' component handles all VCI commands in the same way, and there is no error management.
    481230
    482231The class '''my_target''' inherits from the class '''sc_core::sc_module'''. The class '''my_target''' contains a member
     
    487236
    488237To receive a VCI command packet, a call-back function must be defined as a member function of the class '''my_target'''.
    489 This call-back function (named '''my_nb_transport_fw()''' in the example), will be executed each time a VCI command packet is received on
     238This call-back function (named '''vci_cmd_received()''' in the example), will be executed each time a VCI command packet is received on
    490239the '''p_vci_target''' port. The function name is not constrained, but the arguments must respect the following prototype:
    491240{{{
    492   tlm::tlm_sync_enum my_nb_transport_fw               /// sync status
    493   ( soclib_vci_types::vci_payload_type &payload,      ///< VCI payload pointer
    494     soclib_vci_types::tlmt_phase_type   &phase,       ///< transaction phase
    495     sc_core::sc_time                   &time);        ///< time
     241  tlm::tlm_sync_enum vci_cmd_received             
     242  ( soclib_vci_types::tlm_payload_type &payload,      // VCI payload pointer
     243    soclib_vci_types::tlm_phase_type   &phase,       // transaction phase
     244    sc_core::sc_time                   &time);        // time
    496245}}} 
    497246
    498 
    499247== D.2) Sending a VCI response packet ==
    500248
    501 To send a VCI response packet the '''my_nb_transport_fw()''' function must use the '''nb_transport_bw()''' method, that is a member function of
    502 the class '''tlmt_simple_target_socket''', and has the following prototype:
     249To send a VCI response packet the call-back function '''vci_cmd_received()''' must use the '''nb_transport_bw()''' method, that is a member function of
     250the class '''tlmt_simple_target_socket''', and has the same arguments as the '''nb_transport_fw()''' function.
     251Respecting the general TLM2.0 policy, the payload argument refers to the same '''tlmt_vci_transaction''' object for both the '''nb_transport_fw()''' and '''nb_transport_bw()''' functions,
     252and the associated call-back functions. The set_response_status field must be documented for all transaction types, but only two values are used in this implementation:
     253 * TLMT_OK_RESPONSE
     254 * TLMT_ERROR_RESPONSE
     255For a reactive target, the response packet time is computed as the command packet time plus the target intrinsic latency.
     256
    503257{{{
    504258        payload.set_response_status(soclib::tlmt::TLMT_OK_RESPONSE);
    505  
    506259        phase = soclib::tlmt::TLMT_VCI_RSP;
    507260        time = time + (nwords * UNIT_TIME);
    508  
    509261        p_vci_target->nb_transport_bw(payload, phase, time);
    510262}}}
    511 For a reactive target, the response packet time is computed as the command packet time plus the target intrinsic latency.
    512263
    513264== D.3) Target Constructor ==
    514265
    515266The constructor of the class '''my_target''' must initialize all the member variables, including
    516 the '''p_vci_target''' port. The '''my_nb_transport_fw()''' call-back function being executed in the context of the thread sending
     267the '''p_vci_target''' port. The '''vci_cmd_received()''' call-back function being executed in the context of the thread sending
    517268the command packet, a link between the '''p_vci_target''' port and the call-back function must be established.
    518269The '''my_target''' constructor must be called with the following arguments:
    519270{{{
    520   p_vci_target.register_nb_transport_fw(this, &my_target::my_nb_transport_fw);
    521 }}}
    522 
    523 where '''my_nb_transport_fw''' is the name of the forward callback function.
     271  p_vci_target.register_nb_transport_fw(this, &my_target::vci_cmd_received);
     272}}}
    524273
    525274== D.4) VCI target example ==
     
    528277////////////////////////// my_target.h ////////////////////////////////
    529278
    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
    572279
    573280////////////////////////// my_target.cpp ////////////////////////////////
    574281
    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 =
    657286
    658287The VCI interconnect used for the TLM-T simulation is a generic simulation model, named '''!VciVgmn'''.