Services and Modeling for Embedded Software Development
Embecosm divider strip
Prev  Next

5.3.3.  Blocking Transport Callback

The callback function, loggerReadWrite records the key information regarding any transaction it receives. The payload is a TLM 2.0 generic payload, with appropriate access functions. In this simple implementation, a length of 4 bytes is assumed for the data in the payload.

To get at the data and byte enable mask, the pointers to unsigned char are cast to pointers to the POSIX fixed width type, uint32_t, as was used with Or1ksimSC. Endianness issues due to the byte pointers not being word aligned are not an issue, because the Or1ksimSC module also declared them as uint32_t.

void
LoggerSC::loggerReadWrite( tlm::tlm_generic_payload &payload,
                           sc_core::sc_time         &delay )
{
  // Break out the address, mask and data pointer.

  tlm::tlm_command   comm    = payload.get_command();
  sc_dt::uint64      addr    = payload.get_address();
  unsigned char     *maskPtr = payload.get_byte_enable_ptr();
  unsigned char     *dataPtr = payload.get_data_ptr();

  // Record the payload fields (data only if it's a write)

  const char *commStr;

  switch( comm ) {
  case tlm::TLM_READ_COMMAND:   commStr = "Read";   break;
  case tlm::TLM_WRITE_COMMAND:  commStr = "Write";  break;
  case tlm::TLM_IGNORE_COMMAND: commStr = "Ignore"; break;
  }

  std::cout << "Logging" << std::endl;
  std::cout << "  Command:      "   << commStr << std::endl;
  std::cout << "  Address:      0x" << std::setw( 8 ) << std::setfill( '0' )
            <<std::hex << (uint64_t)addr << std::endl;
  std::cout << "  Byte enables: 0x" << std::setw( 8 ) << std::setfill( '0' )
            <<std::hex << *((uint32_t *)maskPtr) << std::endl;

  if( tlm::TLM_WRITE_COMMAND == comm ) {
    std::cout << "  Data:         0x" << std::setw( 8 ) << std::setfill( '0' )
              <<std::hex << *((uint32_t *)dataPtr) << std::endl;
  }

  std::cout << std::endl;

  payload.set_response_status( tlm::TLM_OK_RESPONSE );  // Always OK

}       // loggerReadWrite()
	  
Embecosm divider strip