Changes between Version 84 and Version 85 of Writing Rules/Tlmt


Ignore:
Timestamp:
Nov 17, 2008, 12:06:04 PM (15 years ago)
Author:
alain
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Writing Rules/Tlmt

    v84 v85  
    8484Dedicated VCI accessors are used to define the VCI transaction type, that can either be '''set_read()''' (for VCI read command),
    8585'''set_write()''' (for VCI write command),'''set_locked_read()''' (for VCI atomic locked read),
    86 and '''set_store_cond()''' (for VCI atomic store conditional). The '''set_src_id()''', '''set_trd_id()''' and '''set_pkt_id()''' functions
     86and '''set_store_cond()''' (for VCI atomic store conditional). The '''set_srcid()''', '''set_trdid()''' and '''set_pktid()''' functions
    8787respectively set the VCI source, thread and packet identifiers.
    8888
     
    100100This class inherits from the standard SystemC '''sc_core::sc_module''' class, that acts as the root class for all TLM-T modules.
    101101
    102 The initiator local time is contained in a member variable named '''m_localTime''', of type '''sc_core::sc_time'''. The
     102The initiator local time is contained in a member variable named '''m_local_time''', of type '''sc_core::sc_time'''. The
    103103local time can be accessed with the following accessors: '''addLocalTime()''', '''setLocalTime()'''
    104104and '''getLocalTime()'''.
     
    194194////////////////////////// my_initiator.h ////////////////////////////////
    195195
    196 #ifndef __MY_INITIATOR_H__
    197 #define __MY_INITIATOR_H__
    198 
    199196#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
     197#include "tlmt_transactions.h"                  // TLM-T headers
     198#include "tlmt_simple_initiator_socket.h"       // TLM-T initiator socket
     199#include "mapping_table.h"            // mapping Table
     200
     201class my_initiator                              // my_initiator 
     202:         public sc_core::sc_module             // inherit from SC module base clase
    206203{
    207204private:
    208   //Variables
     205 
    209206  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   /////////////////////////////////////////////////////////////////////////////////////
     207
     208//////////////////////
     209// Member Variables
     210//////////////////////
     211  uint32_t                           m_srcid;
     212  soclib::common::MappingTable       m_mt;
     213  uint32_t                           m_counter;
     214  uint32_t                           m_lookahead;
     215  sc_core::sc_time                   m_local_time;
     216  bool                               m_activity_status;
     217  sc_core::sc_event                  m_rsp_event;
     218
     219  soclib_vci_types::tlm_payload_type m_payload;
     220  soclib_vci_types::tlm_phase_type   m_phase;
     221
     222  ///////////////////////
     223  // Member Functions
     224  ///////////////////////
    220225  void execLoop(void);                              // initiator thread
     226  bool getActivity(void);                           // get the activity state
     227  void setActivity(bool t);                         // set the activity status (true if the component is active)
     228  sc_core::sc_time getLocalTime(void);              // get the local time
     229  void setLocalTime(sc_core::sc_time& t);           // set the local time
    221230  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
     231  tlm::tlm_sync_enum vci_rsp_received  // interface function to receive VCI response
     232    ( soclib_vci_types::tlm_payload_type &payload,     // payload
     233      soclib_vci_types::tlm_phase_type   &phase,       // phase
     234      sc_core::sc_time                   &time);       // time
    236235
    237236protected:
     237
    238238  SC_HAS_PROCESS(my_initiator);
    239 
     239 
    240240public:
    241   tlmt_simple_initiator_socket<my_initiator,32,soclib_vci_types> p_vci_init;   // VCI initiator port
     241
     242  /////////////////
     243  //  ports
     244  /////////////////
     245  tlmt_simple_initiator_socket<my_initiator,32,soclib_vci_types> p_vci_init;   // VCI initiator port
    242246
    243247  //constructor
    244248  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__ */
     249               sc_core::sc_module_name name,                 // module name
     250               const soclib::common::IntTab &index,          // index of mapping table
     251               const soclib::common::MappingTable &mt,       // mapping table
     252               uint32_t lookahead);                          // lookahead
     253};
    253254
    254255////////////////////////// my_initiator.cpp ////////////////////////////////
    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
     256
     257/////////////////
     258// Constructor
     259/////////////////
     260my_initiator::my_initiator
     261            ( sc_core::sc_module_name name,           // module name
     262              const soclib::common::IntTab &index,    // index of mapping table
     263              const soclib::common::MappingTable &mt, // mapping table
     264              uint32_t lookahead)                     // lookahead
     265            : sc_module(name),                        // init module name
     266            m_mt(mt),                                 // mapping table
     267            p_vci_init("socket")                 // vci initiator socket name
     268{
     269  // link the interface function the TLM-T INITIATOR SOCKET
    274270  p_vci_init.register_nb_transport_bw(this, &my_initiator::vci_rsp_received);
    275271
    276272  // initiator identification
    277   m_initid = mt.indexForId(index);
     273  m_srcid = mt.indexForId(index);
    278274
    279275  //lookahead control
     
    282278
    283279  //initialize the local time
    284   m_localTime= 0 * UNIT_TIME;
    285 
     280  m_local_time = 0 * UNIT_TIME;
     281 
    286282  // initialize the activity variable
    287283  setActivity(true);
    288 
     284 
    289285  // register thread process
    290   SC_THREAD(execLoop);
     286  SC_THREAD(execLoop);   
    291287}
    292288
    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 ){
     289//////////////////////
     290//  Access Functions
     291//////////////////////
     292bool my_initiator::getActivity() { return m_activity; }
     293my_initiator::setActivity(bool t) { m_activity = t; }
     294sc_core::sc_time my_initiator::getLocalTime() { return m_local_time; }
     295my_initiator::setLocalTime(sc_core::sc_time t) { m_local_time = t; }
     296my_initiator::addLocalTime(sc_core::sc_time t) { m_local_time += t; }
     297
     298///////////////////////
     299//  thread
     300///////////////////////
     301my_initiator::execLoop(void) 
     302
     303  uint32_t address =  0x10000000;
     304  uint32_t data_int = 0xAABBCCDD;
     305  unsigned char data[4];
     306  unsigned char byte_enable[4];
     307  int nbytes = 4;
     308
     309  for(int i=0; i<nbytes; i++) byte_enable[i] = TLM_BYTE_ENABLED;
     310
     311  while ( true ) {
     312    // increase local time
    351313    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 
     314    // prepare payload (including int to char translation)
     315    m_payload.itoa(data_int, data, 0);
     316    m_payload.set_write();
     317    m_payload.set_address(address);
     318    m_payload.set_byte_enable_ptr(byte_enable);
     319    m_payload.set_data_ptr(data);
     320    m_payload.set_data_length(nbytes);
     321    m_payload.set_srcid(m_srcid);
     322    m_payload.set_trdid(0);
     323    m_payload.set_pktid(0);
     324    // set the phase
     325    m_phase= soclib::tlmt::TLMT_CMD;
     326    // send the VCI command packet...
     327    p_vci_initiator->nb_transport_fw(m_payload, m_phase, m_local_time);
     328    // thread is descheduled, waiting for the response
     329    wait(m_rsp_event);
    409330    // lookahead management
    410331    m_counter++ ;
     
    413334      wait(sc_core::SC_ZERO_TIME) ;
    414335    }
    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
     336  } // end while
     337
     338} // end execLoop()
     339
     340///////////////////////////////////////////////////////////////
     341// Interface Function to  receive the response packet
     342///////////////////////////////////////////////////////////////
     343 tlm::tlm_sync_enum my_initiator::vci_rsp_received
     344( soclib_vci_types::tlm_payload_type &payload, // payload
     345  soclib_vci_types::tlm_phase_type   &phase,   // phase
     346  sc_core::sc_time                   &time     // time
    430347 )
    431348{
    432349  switch(phase){
    433350  case soclib::tlmt::TLMT_RSP :
    434     setLocalTime(rspTime);
    435     m_rspEvent.notify(0 * UNIT_TIME);
     351    setLocalTime(time);
     352    m_rsp_event.notify(0 * UNIT_TIME);
    436353    break;
    437   case soclib::tlmt::TLMT_INFO :
     354  case soclib::tlmt::TLMT_INFO : 
    438355    payload.set_local_time_ptr(&m_localTime);
    439356    payload.set_activity_ptr(&m_activity);
     
    441358  }
    442359  return tlm::TLM_COMPLETED;
    443 } // end backward nb transport
    444 
    445 
     360} // end vci_rsp_received()
    446361
    447362}}}
     
    512427
    513428#include "tlm.h"                        // TLM headers
    514 #include "tlmt_transactions.h"          // VCI headers
    515 #include "tlmt_simple_target_socket.h"  // VCI SOCKET
     429#include "tlmt_transactions.h"          // TLM-T headers
     430#include "tlmt_simple_target_socket.h"  // TLM-T SOCKET
    516431#include "mapping_table.h"
    517432#include "soclib_endian.h"
     
    528443
    529444  /////////////////////////////////////////////////////////////////////////////////////
    530   // Virtual Fuctions  tlm::tlm_fw_transport_if (VCI SOCKET)
     445  // Interface Fuction  tlm::tlm_fw_transport_if (VCI SOCKET)
    531446  /////////////////////////////////////////////////////////////////////////////////////
    532447
     
    631546}
    632547
     548////////////////////////// my_target.h ////////////////////////////////
     549
     550
     551////////////////////////// my_target.cpp ////////////////////////////////
     552
     553
    633554}}}
    634555
     
    689610provides an utility function '''fill_time_activity_arrays()''' that must be called in the SystemC top-cell, before starting the simulation.
    690611
     612