Changes between Version 123 and Version 124 of Writing Rules/Tlmt


Ignore:
Timestamp:
Mar 3, 2009, 11:02:21 AM (15 years ago)
Author:
alinevieiramello@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Writing Rules/Tlmt

    v123 v124  
    240240
    241241{{{
    242 #include "my_initiator.h"                       // Our header
    243 
    244 my_initiator::my_initiator(
    245                             sc_core::sc_module_name name,           // module name
    246                             const soclib::common::IntTab &index,    // index of mapping table
    247                             const soclib::common::MappingTable &mt, // mapping table
    248                             uint32_t time_quantum)                  // time quantum
    249                             : sc_module(name),                      // init module name
    250                             m_mt(mt),                               // mapping table
    251                             p_vci_init("socket")                    // vci initiator socket name
     242#include "my_initiator.h"                 // header
     243
     244my_initiator::my_initiator
     245( sc_core::sc_module_name name,           // module name
     246  const soclib::common::IntTab &index,    // index of mapping table
     247  const soclib::common::MappingTable &mt, // mapping table
     248  sc_core::sc_time time_quantum)          // time quantum
     249  : sc_module(name),                      // init module name
     250    m_mt(mt),                             // mapping table
     251    p_vci_init("socket")                  // vci initiator socket name
    252252{
    253253  //register callback function VCI INITIATOR SOCKET
    254254  p_vci_init.register_nb_transport_bw(this, &my_initiator::my_nb_transport_bw);
    255  
    256   //initiator identification
     255   //initiator identification
    257256  m_srcid = mt.indexForId(index);
    258 
    259   //Quantum keeper
    260   tlm_utils::tlm_quantumkeeper::set_global_quantum(time_quantum * UNIT_TIME);
    261   m_QuantumKeeper.reset();
    262 
    263   //initialize the local time
    264   m_local_time = sc_core::SC_ZERO_TIME;
    265  
    266   //initialize the activity variable
    267   setActivity(true);
    268  
     257  //PDES local time
     258  m_pdes_local_time = new pdes_local_time(time_quantum);
     259  //PDES activity status
     260  m_pdes_activity_status = new pdes_activity_status(true);
    269261  // register thread process
    270   SC_THREAD(behavior);   
    271 }
    272 
    273 /////////////////////////////////////////////////////////////////////////////////////
    274 // Fuctions
    275 /////////////////////////////////////////////////////////////////////////////////////
    276 bool my_initiator::getActivity()
    277 {
    278   return m_activity_status;
    279 }
    280 
    281 void my_initiator::setActivity(bool t)
    282 {
    283   m_activity_status =t;
    284 }
    285 
    286 //send a message to network to inform the current activity status
     262  SC_THREAD(execLoop);   
     263}
     264
     265// send to interconnect the initiator activity status
    287266void my_initiator::sendActivity()
    288267{
    289268  tlm::tlm_generic_payload *payload_ptr = new tlm::tlm_generic_payload();
     269  soclib_payload_extension *extension_ptr = new soclib_payload_extension();
    290270  tlm::tlm_phase            phase;
    291   sc_core::sc_time          send_time;
    292   soclib_payload_extension *extension_ptr = new soclib_payload_extension();
    293 
     271  sc_core::sc_time          time;
     272 
    294273  // set the active or inactive command
    295   if(m_activity_status) extension_ptr->set_active();
     274  if(m_pdes_activity_status->get()) extension_ptr->set_active();
    296275  else extension_ptr->set_inactive();
    297276  // set the extension to tlm payload
     
    300279  phase = tlm::BEGIN_REQ;
    301280  //set the local time to transaction time
    302   send_time = m_local_time;
    303   //send the message
    304   p_vci_init->nb_transport_fw(*payload_ptr, phase, send_time);
     281  time = m_pdes_local_time->get();
     282  //send a message with command equals to PDES_ACTIVE or PDES_INACTIVE
     283  p_vci_initiator->nb_transport_fw(*payload_ptr, phase, time);
    305284  //wait a response
    306285  wait(m_rspEvent);
    307286}
    308287
    309 sc_core::sc_time my_initiator::getLocalTime()
    310 {
    311   return m_local_time;
    312 }
    313 
    314 void my_initiator::setLocalTime(sc_core::sc_time &t)
    315 {
    316   m_local_time=t;
    317 }
    318 
    319 void my_initiator::addTime(sc_core::sc_time t)
    320 {
    321   m_local_time= m_local_time + t;
    322 }
    323 
    324 //send a null message to network to inform the current local time
     288// send to interconnect a null message with the initiator local time
    325289void my_initiator::sendNullMessage()
    326290{
    327291  tlm::tlm_generic_payload *payload_ptr = new tlm::tlm_generic_payload();
     292  soclib_payload_extension *extension_ptr = new soclib_payload_extension();
    328293  tlm::tlm_phase            phase;
    329   sc_core::sc_time          send_time;
    330   soclib_payload_extension *extension_ptr = new soclib_payload_extension();
    331 
     294  sc_core::sc_time          time;
     295 
    332296  // set the null message command
    333297  extension_ptr->set_null_message();
     
    337301  phase = tlm::BEGIN_REQ;
    338302  //set the local time to transaction time
    339   send_time = m_local_time;
    340   //send the null message
    341   p_vci_init->nb_transport_fw(*payload_ptr, phase, send_time);
    342   //deschedule
     303  time = m_pdes_local_time->get();
     304  //send a null message
     305  p_vci_initiator->nb_transport_fw(*payload_ptr, phase, time);
     306  //deschedule the initiator thread
    343307  wait(sc_core::SC_ZERO_TIME);
    344308}
    345 // initiator thread
    346 void my_initiator::behavior(void)
     309 
     310// initiator thread
     311void my_initiator::execLoop(void)
    347312{
    348313  tlm::tlm_generic_payload *payload_ptr = new tlm::tlm_generic_payload();
    349   tlm::tlm_phase            phase;
    350   sc_core::sc_time          send_time;
    351314  soclib_payload_extension *extension_ptr = new soclib_payload_extension();
    352  
    353   uint32_t nwords = 1;
    354   uint32_t nbytes= nwords * vci_param::nbytes;
     315  tlm::tlm_phase phase;
     316  sc_core::sc_time time;
     317  uint32_t nbytes = 4;
    355318  unsigned char data[nbytes];
    356319  unsigned char byte_enable[nbytes];
    357320 
    358   for(unsigned int i=0; i<nbytes; i++){
    359     byte_enable[i]=0xFF;
    360     data[i]=0xAA;
    361   }
    362 
    363321  while (true){
    364     //increment the local time
    365     addTime(100 * UNIT_TIME);
    366     m_QuantumKeeper.inc(100 * UNIT_TIME);
    367    
    368      // set the values in tlm payload
     322    //fill the byte_enable and data
     323    for(unsigned int i=0; i<nbytes; i++){
     324      byte_enable[i]=0xFF;
     325      data[i]=0xAA;
     326    }
     327
     328    // set the values in tlm payload
    369329    payload_ptr->set_command(tlm::TLM_IGNORE_COMMAND);
    370330    payload_ptr->set_address(0x10000000);
     
    379339    extension_ptr->set_pkt_id(0);
    380340    // set the extension to tlm payload
    381     payload_ptr->set_extension(extension_ptr);
     341    payload_ptr->set_extension (extension_ptr );
    382342    // set the tlm phase
    383343    phase = tlm::BEGIN_REQ;
    384344    // set the local time to transaction time
    385     send_time = m_local_time;
    386    
    387     // send the transaction
    388     p_vci_init->nb_transport_fw(*payload_ptr, phase, send_time);
    389     // wait the response
     345    time = m_pdes_local_time->get();
     346    // send the transaction and wait a response
     347    p_vci_initiator->nb_transport_fw(*payload_ptr, phase, time);
    390348    wait(m_rspEvent);
    391 
    392     // if the initiator needs synchronize then it sends a null message and resets the quantum keeper
    393     if (m_QuantumKeeper.need_sync()) {
     349 
     350    // increment the local time
     351    m_pdes_local_time->add(10 * UNIT_TIME);
     352    // if a synchronization is nexcessary then the initiator sends a null message
     353    if (m_pdes_local_time->need_sync()) {
    394354      sendNullMessage();
    395       m_QuantumKeeper.reset();
    396355    }
    397356  } // end while true
    398   setActivity(false);
     357
     358  //desactive the initiator and inform to interconnect
     359  m_pdes_activity_status->set(false);
    399360  sendActivity();
    400 } // end initiator_thread
    401 
    402 /////////////////////////////////////////////////////////////////////////////////////
    403 // Virtual Fuctions  tlm::tlm_bw_transport_if (VCI INITIATOR SOCKET)
    404 /////////////////////////////////////////////////////////////////////////////////////
    405 tlm::tlm_sync_enum my_initiator::my_nb_transport_bw  // inbound nb_transport_bw
    406 ( tlm::tlm_generic_payload &payload,                 // payload
    407   tlm::tlm_phase &phase,                             // phase
    408   sc_core::sc_time &time)                            // time
     361}
     362
     363// inbound nb_transport_bw (VCI INITIATOR SOCKET)
     364tlm::tlm_sync_enum my_initiator::my_nb_transport_bw
     365( tlm::tlm_base_protocol_types::tlm_payload_type &payload, // payload
     366  tlm::tlm_base_protocol_types::tlm_phase_type   &phase,   // phase
     367  sc_core::sc_time                               &time)    // time
    409368{
    410   //update the local time
    411   setLocalTime(time);
    412   //increment the quatum keeper using the difference between the sending time and response time
    413   m_QuantumKeeper.inc(time - send_time);
    414   //notify the initiator thread
     369  // update the local time
     370  m_pdes_local_time->set(time);
     371  // wake up the initiator thread
    415372  m_rspEvent.notify(sc_core::SC_ZERO_TIME);
    416373  return tlm::TLM_COMPLETED;
    417 } // end backward nb transport
     374}
    418375
    419376}}}