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


Ignore:
Timestamp:
Nov 17, 2008, 11:43:35 AM (15 years ago)
Author:
fpecheux
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Writing Rules/Tlmt

    v83 v84  
    508508////////////////////////// my_target.h ////////////////////////////////
    509509
     510#ifndef __MY_TARGET_H__
     511#define __MY_TARGET_H__
     512
     513#include "tlm.h"                        // TLM headers
     514#include "tlmt_transactions.h"          // VCI headers
     515#include "tlmt_simple_target_socket.h"  // VCI SOCKET
     516#include "mapping_table.h"
     517#include "soclib_endian.h"
     518
     519class my_target
     520  : public sc_core::sc_module
     521{
     522 private:
     523  typedef soclib::tlmt::VciParams<uint32_t,uint32_t,4> vci_param;
     524
     525  uint32_t m_targetid;
     526  soclib::common::MappingTable m_mt;
     527
     528
     529  /////////////////////////////////////////////////////////////////////////////////////
     530  // Virtual Fuctions  tlm::tlm_fw_transport_if (VCI SOCKET)
     531  /////////////////////////////////////////////////////////////////////////////////////
     532
     533  // receive command from initiator
     534  tlm::tlm_sync_enum vci_cmd_received                 ///
     535  ( soclib_vci_types::tlm_payload_type &payload,      /// VCI payload pointer
     536    soclib_vci_types::tlm_phase_type   &phase,        /// transaction phase
     537    sc_core::sc_time                   &time);        /// time
     538
     539 protected:
     540  SC_HAS_PROCESS(my_target);
     541 public:
     542  tlmt_simple_target_socket<my_target,32,soclib_vci_types> p_vci_target;        ///<  VCI target socket
     543
     544  my_target(sc_core::sc_module_name            name,
     545         const soclib::common::IntTab       &index,
     546         const soclib::common::MappingTable &mt);
     547
     548  ~my_target();
     549};
     550
     551#endif
    510552
    511553////////////////////////// my_target.cpp ////////////////////////////////
    512554
     555#include "my_target.h"
     556
     557#ifndef MY_TARGET_DEBUG
     558#define MY_TARGET_DEBUG 1
     559#endif
     560
     561#define tmpl(x) x my_target
     562
     563//////////////////////////////////////////////////////////////////////////////////////////
     564// CONSTRUCTOR
     565//////////////////////////////////////////////////////////////////////////////////////////
     566tmpl(/**/)::my_target
     567           ( sc_core::sc_module_name name,
     568             const soclib::common::IntTab &index,
     569             const soclib::common::MappingTable &mt)
     570           : sc_module(name),
     571           m_mt(mt),
     572           p_vci_target("p_vci_target")
     573{
     574  //register callback fuction
     575  p_vci_target.register_nb_transport_fw(this, &my_target::vci_cmd_received);
     576
     577  m_targetid = m_mt.indexForId(index);
     578}
     579
     580tmpl(/**/)::~my_target(){}
     581
     582/////////////////////////////////////////////////////////////////////////////////////
     583// Virtual Fuctions  tlm::tlm_fw_transport_if VCI SOCKET
     584/////////////////////////////////////////////////////////////////////////////////////
     585
     586//nb_transport_fw implementation calls from initiators
     587tmpl(tlm::tlm_sync_enum)::vci_cmd_received                              //
     588                         ( soclib_vci_types::tlm_payload_type &payload, // VCI payload pointer
     589                           soclib_vci_types::tlm_phase_type   &phase,   // transaction phase
     590                           sc_core::sc_time                   &time)    // time
     591{
     592  int nwords = payload.get_data_length() / vci_param::nbytes;
     593  switch(payload.get_command()){
     594  case soclib::tlmt::VCI_READ_COMMAND:
     595  case soclib::tlmt::VCI_WRITE_COMMAND:
     596  case soclib::tlmt::VCI_LOCKED_READ_COMMAND:
     597  case soclib::tlmt::VCI_STORE_COND_COMMAND:
     598      {
     599#if MY_TARGET_DEBUG
     600        std::cout << "[RAM " << m_targetid << "] Receive from source " << payload.get_src_id() <<" a packet "<< payload.get_pkt_id() << " Time = "  << time.value() << std::endl;
     601#endif
     602
     603        payload.set_response_status(soclib::tlmt::TLMT_OK_RESPONSE);
     604        phase = soclib::tlmt::TLMT_RSP;
     605        time = time + (nwords * UNIT_TIME);
     606
     607#if MY_TARGET_DEBUG
     608        std::cout << "[RAM " << m_targetid << "] Send to source "<< payload.get_src_id() << " a anwser packet " << payload.get_pkt_id() << " Time = "  << time.value() << std::endl;
     609#endif
     610
     611        p_vci_target->nb_transport_bw(payload, phase, time);
     612        return tlm::TLM_COMPLETED;
     613      }
     614      break;
     615    default:
     616      break;
     617  }
     618
     619  //send error message
     620  payload.set_response_status(soclib::tlmt::TLMT_ERROR_RESPONSE);
     621
     622  phase = soclib::tlmt::TLMT_RSP;
     623  time = time + nwords * UNIT_TIME;
     624
     625#if MY_TARGET_DEBUG
     626  std::cout << "[RAM " << m_targetid << "] Address " << payload.get_address() << " does not match any segment " << std::endl;
     627  std::cout << "[RAM " << m_targetid << "] Send to source "<< payload.get_src_id() << " a error packet with time = "  << time.value() << std::endl;
     628#endif
     629  p_vci_target->nb_transport_bw(payload, phase, time);
     630  return tlm::TLM_COMPLETED;
     631}
    513632
    514633}}}