Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

TLM implementation and use of b_transport

Status
Not open for further replies.

qwerty_asdf

Member level 4
Joined
Mar 26, 2012
Messages
73
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,781
Hello,

I am trying some things with TLM 2.0 and I am having some problems. I do have an initiator and I want to pass 4 values in my target device.

here is my code:

Initiator:

Code:
struct Initiator: sc_module
{
  // TLM-2 socket, defaults to 32-bits wide, base protocol
  tlm_utils::simple_initiator_socket<Initiator> socket;

  SC_CTOR(Initiator)
  : socket("socket")  // Construct and name socket
  {
    SC_THREAD(sending_data_to_device);
  }

 void sending_data_to_device()
  {
    // TLM-2 generic payload transaction, reused across calls to b_transport
    tlm::tlm_generic_payload* trans = new tlm::tlm_generic_payload;
    sc_time delay = sc_time(10, SC_NS);

		int data;
  	enum { WORDS = 4 };

    // Generate sequence of writes
    for (int i = 0; i < WORDS; i++)
    {
			data=12345678;
			

      // Initialize 8 out of the 10 attributes, byte_enable_length and extensions being unused
			trans->set_command(tlm::TLM_WRITE_COMMAND);
      trans->set_address( i ); 
      trans->set_data_ptr( reinterpret_cast<unsigned char*>(&data) );
      trans->set_data_length( 4 );
      trans->set_streaming_width( 4 ); // = data_length to indicate no streaming
      trans->set_byte_enable_ptr( 0 ); // 0 indicates unused
      trans->set_dmi_allowed( false ); // Mandatory initial value
      trans->set_response_status( tlm::TLM_INCOMPLETE_RESPONSE ); // Mandatory initial value

      socket->b_transport( *trans, delay );  // Blocking transport call

      // Initiator obliged to check response status and delay
      if ( trans->is_response_error() )
        SC_REPORT_ERROR("TLM-2", "Response error from b_transport");

      cout << "trans = { W" << ", " << hex << i
           << " } , data = " << hex << data << " at time " << sc_time_stamp()
           << " delay = " << delay << endl;

      // Realize the delay annotated onto the transport call
      wait(delay);
    }
  }


};

So I want to send in the device 4 times the number 12345678.

My target code:

Code:
struct Device: sc_module
{
  // TLM-2 socket, defaults to 32-bits wide, base protocol
  tlm_utils::simple_target_socket<Device> socket;

	enum { SIZE = 4 };
  
	int mem[SIZE];	
	//internal variables

 SC_CTOR(Device)
  : socket("socket")
  {
    // Register callback for incoming b_transport interface method call
    socket.register_b_transport(this, &Device::b_transport);

    // Initialize memory with zeros
    for (int i = 0; i < SIZE; i++)
      mem[i] = 0x00000000 ;
  }

 // TLM-2 blocking transport method --DATA MANIPULATION GOES IN HERE
  virtual void b_transport( tlm::tlm_generic_payload& trans, sc_time& delay )
  {
    tlm::tlm_command cmd = trans.get_command();
    sc_dt::uint64    adr = trans.get_address();
    unsigned char*   ptr = trans.get_data_ptr();
    unsigned int     len = trans.get_data_length();
    unsigned char*   byt = trans.get_byte_enable_ptr();
    unsigned int     wid = trans.get_streaming_width();

	cout << " READING DATA IN TARGET " << *ptr << "  ADDRESS: " << adr  << "\n";

    if (adr >= sc_dt::uint64(SIZE) || byt != 0 || len > 4 || wid < len)
      SC_REPORT_ERROR("TLM-2", "Target does not support given generic payload transaction");



    // Obliged to set response status to indicate successful completion
    trans.set_response_status( tlm::TLM_OK_RESPONSE );
  }

};

My problem is that i do not see data being printed out.

here is my output:
Code:
 READING DATA IN TARGET N  ADDRESS: 0
trans = { W, 0 } , data = bc614e at time 0 s delay = 10 ns
 READING DATA IN TARGET N  ADDRESS: 1
trans = { W, 1 } , data = bc614e at time 10 ns delay = 10 ns
 READING DATA IN TARGET N  ADDRESS: 2
trans = { W, 2 } , data = bc614e at time 20 ns delay = 10 ns
 READING DATA IN TARGET N  ADDRESS: 3
trans = { W, 3 } , data = bc614e at time 30 ns delay = 10 ns
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top