Jump to content

LT coding style. Blocking interface. Synchronization point


Recommended Posts

Hi everybody! About my model:
Here is two different initiators and one target. Initiators makes b_transport to different sockets. first b_transport of each initiator its "req to transition", second - data transition. Could anybody help me to write synch point? My target should will call some behavioral function when all initiators will make "req to transition".
Could anybody helps me to change this code? Please, help me!
 

#define SC_INCLUDE_DYNAMIC_PROCESSES

#include <systemc.h>
#include <tlm.h>
#include <tlm_utils\simple_initiator_socket.h>
#include <tlm_utils\simple_target_socket.h>

SC_MODULE(Initiator) {

	tlm_utils::simple_initiator_socket<Initiator> socket;	
    	
	void process() {
		tlm::tlm_generic_payload *trans = new tlm::tlm_generic_payload;
		sc_time delay = sc_time(10, SC_NS);						

		for(int i =0 ; i < 100; i++) {
			
			cout << "Initiator1: send payload with req to target @ " << sc_time_stamp() << endl;
			socket->b_transport(*trans, delay);

			if(trans->is_response_ok()) {
				cout << "Initiator1: Start transaction. Send data @ " << sc_time_stamp() << endl;
				trans->set_data_ptr(reinterpret_cast<unsigned char*>(&i));			
				socket->b_transport(*trans, delay);
			}
		}
	}

	SC_CTOR(Initiator) {
		SC_THREAD(process);
	}
};

SC_MODULE(Initiator2) {

	tlm_utils::simple_initiator_socket<Initiator2> socket;	
    	
	void process() {
		tlm::tlm_generic_payload *trans = new tlm::tlm_generic_payload;
		sc_time delay = sc_time(0, SC_NS);				
	

		for(int i =5 ; i < 100; i++) {
						
			cout << "Initiator2: send payload with req to target @ " << sc_time_stamp() << endl;
			socket->b_transport(*trans, delay);

			if(trans->is_response_ok()) {
				cout << "Initiator2: Start transaction. Send data @ " << sc_time_stamp() << endl;
				trans->set_data_ptr(reinterpret_cast<unsigned char*>(&i));			
				socket->b_transport(*trans, delay);				
			}
		}
	}

	SC_CTOR(Initiator2) {
		SC_THREAD(process);
	}
};

 
SC_MODULE(Target) {

	tlm_utils::simple_target_socket<Target> socket, socket2;
	bool dataRecievedI1, dataRecoevedI2;

	virtual void process1(tlm::tlm_generic_payload &tx, sc_time& dt) {
		if(!dataRecievedI1) {
			wait(socket->default_event());
		}		
	}	

	virtual void process2(tlm::tlm_generic_payload &tx, sc_time& dt) {
		if(!dataRecoevedI2) {
		}
	}

	SC_CTOR(Target) {
		dataRecievedI1 = false;
		dataRecoevedI2 = false;

		socket.register_b_transport(this, &Target::process1);
		socket2.register_b_transport(this, &Target::process2);
	}
};

SC_MODULE(Top) {
	Initiator		*initiator;	
	Initiator2		*initiator2;
	Target			*target;

	SC_CTOR(Top) {
		initiator			= new Initiator	("initiator");
		target				= new Target	("target");		
		initiator2			= new Initiator2("initiator2");

		initiator->socket.bind(target->socket);		
		initiator2->socket.bind(target->socket2);
	}
};

int sc_main(int argc, char* argv[]) {
  Top top("top");
  sc_start();

  getchar();
  return 0;
}

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...