kid123 Posted March 2, 2016 Report Share Posted March 2, 2016 Hi all, I just have started with TLM 2.0. I'm trying complete doulos's example but it's fails. I have 2 modules: Initiator and Memory. I want to transmit "data" from Initiator throught Memory, but "trans.get_data_ptr" is fails. I have printed "&data" and "ptr" into monitor but ptr is nothing. #define SC_INCLUDE_DYNAMIC_PROCESSES #include "systemc" using namespace sc_core; using namespace sc_dt; using namespace std; #include "tlm.h" #include "tlm_utils/simple_initiator_socket.h" #include "tlm_utils/simple_target_socket.h" #include "Initiator.h" #include "Memory.h" SC_MODULE(Top) { Initiator *initiator; Memory *memory; SC_CTOR(Top) { // Instantiate components initiator = new Initiator("initiator"); memory = new Memory ("memory"); // One initiator is bound directly to one target with no intervening bus // Bind initiator socket to target socket initiator->socket.bind( memory->socket ); } }; int sc_main(int argc, char* argv[]) { Top top("top"); sc_start(); return 0; } #define SC_INCLUDE_DYNAMIC_PROCESSES #include "systemc" using namespace sc_core; using namespace sc_dt; using namespace std; #include "tlm.h" #include "tlm_utils/simple_initiator_socket.h" #include "tlm_utils/simple_target_socket.h" 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(thread_process); } void thread_process() { // 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); // Generate a random sequence of reads and writes tlm::tlm_command cmd = tlm::TLM_WRITE_COMMAND; if (cmd == tlm::TLM_WRITE_COMMAND) data = 0; // Initialize 8 out of the 10 attributes, byte_enable_length and extensions being unused trans->set_command( cmd ); trans->set_address( 1 ); trans->set_data_ptr( reinterpret_cast<unsigned char*>(&data) ); trans->set_data_length( 1 ); trans->set_streaming_width( 1 ); // = 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 << " data = " << &data << endl; // Realize the delay annotated onto the transport call wait(delay); } // Internal data buffer used by initiator with generic payload bool data; }; #define SC_INCLUDE_DYNAMIC_PROCESSES #include "systemc" using namespace sc_core; using namespace sc_dt; using namespace std; #include "tlm.h" #include "tlm_utils/simple_initiator_socket.h" #include "tlm_utils/simple_target_socket.h" // Target module representing a simple memory struct Memory: sc_module { // TLM-2 socket, defaults to 32-bits wide, base protocol tlm_utils::simple_target_socket<Memory> socket; enum { SIZE = 256 }; SC_CTOR(Memory) : socket("socket") { // Register callback for incoming b_transport interface method call socket.register_b_transport(this, &Memory::b_transport); // Initialize memory with random data for (int i = 0; i < SIZE; i++) mem[i] = 0xAA000000 | (rand() % 256); } // TLM-2 blocking transport method 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(); // Obliged to check address range and check for unsupported features, // i.e. byte enables, streaming, and bursts // Can ignore DMI hint and extensions // Using the SystemC report handler is an acceptable way of signalling an error 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 implement read and write commands if ( cmd == tlm::TLM_READ_COMMAND ) memcpy(&ptr, &mem[adr], len); else if ( cmd == tlm::TLM_WRITE_COMMAND ) memcpy(&mem[adr], &ptr, len); // Obliged to set response status to indicate successful completion trans.set_response_status( tlm::TLM_OK_RESPONSE ); cout << " ptr = " << ptr << endl; } int mem[SIZE]; }; Quote Link to comment Share on other sites More sharing options...
apfitch Posted March 2, 2016 Report Share Posted March 2, 2016 Did you download the example from this page: http://www.doulos.com/knowhow/systemc/tlm2/tutorial__1/tlm2_1_downloads.php ? It works for me... SystemC 2.3.1-Accellera --- Nov 18 2015 09:31:09 Copyright (c) 1996-2014 by all Contributors, ALL RIGHTS RESERVED trans = { R, 20 } , data = aa000029 at time 0 s delay = 10 ns trans = { R, 24 } , data = aa0000cd at time 10 ns delay = 10 ns trans = { R, 28 } , data = aa0000ba at time 20 ns delay = 10 ns trans = { R, 2c } , data = aa0000ab at time 30 ns delay = 10 ns trans = { R, 30 } , data = aa0000f2 at time 40 ns delay = 10 ns trans = { W, 34 } , data = ff000034 at time 50 ns delay = 10 ns trans = { R, 38 } , data = aa0000e3 at time 60 ns delay = 10 ns trans = { R, 3c } , data = aa000046 at time 70 ns delay = 10 ns trans = { R, 40 } , data = aa00007c at time 80 ns delay = 10 ns trans = { R, 44 } , data = aa0000c2 at time 90 ns delay = 10 ns trans = { R, 48 } , data = aa000054 at time 100 ns delay = 10 ns trans = { W, 4c } , data = ff00004c at time 110 ns delay = 10 ns trans = { R, 50 } , data = aa00001b at time 120 ns delay = 10 ns trans = { R, 54 } , data = aa0000e8 at time 130 ns delay = 10 ns trans = { R, 58 } , data = aa0000e7 at time 140 ns delay = 10 ns trans = { R, 5c } , data = aa00008d at time 150 ns delay = 10 ns regards Alan Quote Link to comment Share on other sites More sharing options...
kid123 Posted March 3, 2016 Author Report Share Posted March 3, 2016 I've solved it thanks Alan Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.