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);
}
}
};