VanTeo Posted March 9, 2016 Report Share Posted March 9, 2016 I have an example of systemc which implements "and" function. I have assigned 4 value for input signal but it have implemented only 1 value. help me please! #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" #include "Router.h" unsigned int Memory::mem_nr = 0; int sc_main(int argc, char* argv[]) { Initiator* initiator; Router<4>* router; Memory* memory[4]; initiator = new Initiator("initiator"); router = new Router<4>("router"); for (int i = 0; i < 4; i++) { char txt[20]; sprintf(txt, "memory_%d", i); memory[i] = new Memory(txt); } // Bind sockets initiator->socket.bind( router->target_socket ); for (int i = 0; i < 4; i++) router->initiator_socket[i]->bind( memory[i]->socket ); sc_signal<bool> a, b, c, d; sc_time t(100, SC_PS); initiator->a(a); initiator->b(; initiator->c(c); //memory.d(d); sc_trace_file *wf = sc_create_vcd_trace_file("and2"); sc_trace(wf, initiator->a, "a"); sc_trace(wf, initiator->b, "b"); sc_trace(wf, initiator->c, "c"); //sc_trace_file(wf, memory.d, "d"); a.write(0); b.write(0); sc_start(t); a.write(0); b.write(1); sc_start(t); a.write(1); b.write(0); sc_start(t); a.write(1); b.write(1); sc_start(t); a.write(0); b.write(0); sc_start(); sc_stop(); sc_close_vcd_trace_file(wf); 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_utils::simple_initiator_socket<Initiator> socket; sc_in<bool> a, b; sc_out<bool> c; SC_CTOR(Initiator) : socket("socket") { SC_THREAD(thread_process); sensitive << a << b; } void thread_process() { bool c_temp; int data; while(true) { wait(); c_temp = a.read()&b.read(); c.write(c_temp); data = 0xFF000030 | c_temp; tlm::tlm_generic_payload* trans = new tlm::tlm_generic_payload; sc_time delay = sc_time(10, SC_NS); tlm::tlm_command cmd = tlm::TLM_WRITE_COMMAND; trans->set_command( cmd ); trans->set_address( 100 ); 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 if ( trans->is_response_error() ) { char txt[100]; sprintf(txt, "Error from b_transport, response status = %s", trans->get_response_string().c_str()); SC_REPORT_ERROR("TLM-2", txt); } cout << " a = " << hex << a << " , b = " << hex << b << " , c_temp = " << hex << c_temp << " , c = " << hex << c << " , data = " << hex << data << " , " << sc_time_stamp() << endl; } } }; #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" template<unsigned int N_TARGETS> struct Router: sc_module { tlm_utils::simple_target_socket<Router> target_socket; tlm_utils::simple_initiator_socket_tagged<Router>* initiator_socket[N_TARGETS]; SC_CTOR(Router) : target_socket("target_socket") { target_socket.register_b_transport(this, &Router::b_transport); for (unsigned int i = 0; i < N_TARGETS; i++) { char txt[20]; sprintf(txt, "socket_%d", i); initiator_socket[i] = new tlm_utils::simple_initiator_socket_tagged<Router>(txt); } } virtual void b_transport( tlm::tlm_generic_payload& trans, sc_time& delay ) { sc_dt::uint64 address = trans.get_address(); unsigned int target_nr = static_cast<unsigned int>( (address >> 6) & 0x3 ); trans.set_address( address ); ( *initiator_socket[target_nr] )->b_transport( trans, delay ); cout << "address = " << address << " , target_nr = " << target_nr <<endl; } /*inline unsigned int decode_address( sc_dt::uint64 address, sc_dt::uint64& masked_address ) { unsigned int target_nr = static_cast<unsigned int>( (address >> 6) & 0x3 ); masked_address = address & 0xFF; return target_nr; } inline sc_dt::uint64 compose_address( unsigned int target_nr, sc_dt::uint64 address) { return (target_nr << 6) | (address & 0xFF); }*/ }; #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 Memory: sc_module { tlm_utils::simple_target_socket<Memory> socket; enum { SIZE = 256 }; const sc_time LATENCY; SC_CTOR(Memory) : socket("socket"), LATENCY(10, SC_NS) { socket.register_b_transport(this, &Memory::b_transport); for (int i = 0; i < SIZE; i++) mem[i] = 0xAA000000; } 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() / 4; 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(); 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"); wait(delay); delay = SC_ZERO_TIME; if ( cmd == tlm::TLM_READ_COMMAND ) memcpy(ptr, &mem[adr], len); else if ( cmd == tlm::TLM_WRITE_COMMAND ) memcpy(&mem[adr], ptr, len); trans.set_response_status( tlm::TLM_OK_RESPONSE ); cout << " ptr = " << hex << ptr << " , adr = " << hex << adr << " , mem[" << dec << adr << "] = " << hex << mem[adr] << endl; } //int d; int mem[SIZE]; }; Quote Link to comment Share on other sites More sharing options...
ai.asic Posted July 5, 2023 Report Share Posted July 5, 2023 Have you solve this issue yet? Recently I have read some code about TLM2 which implement router function. And you can find it on edaplaygroud.com named TLM-2.0-Example6. Wish it help. Quote Link to comment Share on other sites More sharing options...
David Black Posted July 5, 2023 Report Share Posted July 5, 2023 The original question is 7 years old with a very unclear problem statement. The code is poorly commented, and probably did not receive a response because nobody understood what @VanTeo was trying to say. He likely found a solution elsewhere. @ai.asicWhat is your problem? Please be very specific. If you have a question about an issue on EDAplayground, then fully specify the link. Quote Link to comment Share on other sites More sharing options...
ai.asic Posted July 13, 2023 Report Share Posted July 13, 2023 Here is the link which I mentioned. https://www.edaplayground.com/x/2SaZ @David Black 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.