Jump to content

ips

Members
  • Content Count

    8
  • Joined

  • Last visited

  • Days Won

    1
  1. 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; }
  2. Hi everyone! I have model: two different initiators send data to one target. My allocate code below #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); //tlm::tlm_command cmd = (tlm::tlm_command) (rand()%2); for(int i =0 ; i < 100; i++) { trans->set_data_ptr(reinterpret_cast<unsigned char*>(&i)); socket->b_transport(*trans, delay); } } SC_CTOR(Initiator) { SC_THREAD(process); } }; SC_MODULE(SecondInitiator) { tlm_utils::simple_initiator_socket<SecondInitiator> 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++) { trans->set_data_ptr(reinterpret_cast<unsigned char*>(&i)); socket->b_transport(*trans, delay); } } SC_CTOR(SecondInitiator) { SC_THREAD(process); } }; SC_MODULE(Target) { tlm_utils::simple_target_socket<Target> socket, socket2; virtual void process(tlm::tlm_generic_payload &tx, sc_time& dt) { //This process should start when both initiators will send data } SC_CTOR(Target) { socket.register_b_transport(this, &Target::process); socket2.register_b_transport(this, &Target::process); } }; SC_MODULE(Top) { Initiator *initiator; SecondInitiator *secondInitiator; Target *target; SC_CTOR(Top) { initiator = new Initiator ("initiator"); target = new Target ("target"); secondInitiator = new SecondInitiator("second initiator"); initiator->socket.bind(target->socket); secondInitiator->socket.bind(target->socket2); } }; int sc_main(int argc, char* argv[]) { Top top("top"); sc_start(); getchar(); return 0; } Question: How to implement synch point - start target behavior process only when both initiator will send the data. Target should has only one behavioral process
  3. Hi everyone, I'm met some problem. In box below you can see my code. struct Some_stuct { int data; float data_f; }; class payload_t { public: unsigned char *data; unsigned lenght; inline friend ostream& operator << ( ostream& os, payload_t const & v ) { os << "(" << v.data << "," << std::boolalpha << "," << v.lenght << ")"; return os; } }; SC_MODULE(tx) { sc_port<sc_fifo_out_if<payload_t> > out_port; void process() { Some_stuct data; payload_t out_data; while(true) { data.data = 5; data.data_f = 6; out_data.data = reinterpret_cast<unsigned char*>(&data); out_data.lenght = sizeof(Some_stuct); out_port->write(out_data); data.data++; data.data_f++; wait(1, SC_NS); } } SC_CTOR(tx) { SC_THREAD(process); } }; SC_MODULE(rx) { sc_port<sc_fifo_in_if<payload_t> > in_port; void process() { int realData = 0; payload_t in_data; while(true) { wait(in_port->data_written_event()); wait(171, SC_NS); in_data = in_port->read(); Some_stuct *val = reinterpret_cast<Some_stuct*>(in_data.data); cout << sc_time_stamp() << " " << val->data << " " << val->data_f << endl; } } SC_CTOR(rx) { SC_THREAD(process); } }; int sc_main(int argc, char* argv[]) { rx rx_i("rx"); tx tx_i("tx"); sc_fifo<payload_t> buf(8); tx_i.out_port(buf); rx_i.in_port(buf); sc_start(); getchar(); return 0; } I'm have two blocks: transmitter and receiver. When we call method write to fifo from transmitter, actually we will send address of our local data. And when i will read from buffer, I will receive address of transmitter local data. But if transmitter works more faster than receiver, my rx block will receive "New" data and sended data will loss. How to solve this problem? I should receive correct data
  4. Aptfich, before establishing of this topic, I too felt that wait(SC_ZERO_TIME) construction will helps, but no. wait(SC_ZERO_TIME) construction will defer execution of code in the end of delta cycle. Philipp already explained why your second proposal too does not work This is too bad decision. Actually, my behavioral code should wake up only when he will has data in all buffers.
  5. Thanks. But what I'm need to do, for example, if I'm will be have more that one input port. for example #include <iostream> #include <systemc.h> SC_MODULE(peObj1) { sc_port<sc_fifo_in_if<data_1004to1009> > in_port_1009; sc_port<sc_fifo_in_if<data_1004to1009> > in_port_1008; void process_thread() { int in_dataValue1009 = 0; int res = 0; data_1004to1009 inMessage1009; while(true) { while(in_port_1009->num_available() && in_port_10098->num_available() ) { cout << sc_time_stamp() << " Im insinde obj 1: "<< endl; in_port_1009->read(inMessage1009); in_dataValue1009 = atoi(inMessage1009.data); wait(6, SC_NS); cout << sc_time_stamp() << " peObj1 recieved data: "<< in_dataValue1009 << endl; } } } SC_CTOR(peObj1) { SC_THREAD(process_thread); }; }; One nuance of my block, that behavioral code must be executed only when block will have data at all ports. How to realise this synch point correctly?
  6. Hi everybody. I'm try to develop some project and met with problem. My project is very simple: 2 Blocks has not duplex connection. (Block1 -> Block2). Block1 generating some data and send it to Block2. In fact, in behavioral code block2 have line while(in_port_1009->num_available()); { // do something } i.e. he should wait some data in buffer. But I'm wrote some dbg line to check: wait my block some data or not. while(in_port_1009->num_available()); { cout << sc_time_stamp() << " Im insinde obj 1: "<< endl; //Do something }; This is code of Block1 (tranciever) void process_thread() { int res = 0; data_1004to1009 outMessage1004; while(true) { res = gen_data(); itoa(res, outMessage1004.data, 10); wait(7, SC_NS); // <- block2 go inside to the loop, when I'm do this line, //i.e. data not sended yet out_port_1004->write(outMessage1004); } } You can ask me why I'm use classes like a type of data for links. Answer: this is conditions of project. Please, someone, help me ASAP. Here attached code: main.cpp #include <iostream> #include <fstream> using namespace std; class data_1004to1009 { public: char data[8]; data_1004to1009() { memset(data, 0, sizeof(data)); } inline friend ostream& operator << ( ostream& os, data_1004to1009_t const & v ) { os << "(" << v.data << "," << std::boolalpha << "," << v.data << ")"; return os; } }; #include "peObj0.h" #include "peObj1.h" int sc_main(int argc, char* argv[]) { peObj0 peObj0Component("peObj0"); peObj1 peObj1Component("peObj1"); sc_fifo<data_1004to1009_t> fifoBufferPort1004toPort1009(1); peObj1Component.in_port_1009(fifoBufferPort1004toPort1009); peObj0Component.out_port_1004(fifoBufferPort1004toPort1009); sc_start(150, SC_NS); sc_stop(); getchar(); return 0; } pe0Obj.h #include <iostream> #include <systemc.h> SC_MODULE(peObj0) { //Ports declaration sc_port<sc_fifo_out_if<data_1004to1009> > out_port_1004; void process_thread() { int res = 0; data_1004to1009 outMessage1004; while(true) { res = rand()%10; out_busy.write(0); itoa(res, outMessage1004.data, 10); wait(7, SC_NS); out_port_1004->write(outMessage1004); } } SC_CTOR(peObj0) { SC_THREAD(process_thread); }; }; peObj1.h #include <iostream> #include <systemc.h> SC_MODULE(peObj1) { sc_port<sc_fifo_in_if<data_1004to1009> > in_port_1009; void process_thread() { int in_dataValue1009 = 0; int res = 0; data_1004to1009 inMessage1009; while(true) { out_busy.write(0); out_working.write(0); while(in_port_1009->num_available()); { cout << sc_time_stamp() << " Im insinde obj 1: "<< endl; in_port_1009->read(inMessage1009); in_dataValue1009 = atoi(inMessage1009.data); wait(6, SC_NS); cout << sc_time_stamp() << " peObj1 recieved data: "<< in_dataValue1009 << endl; } } } SC_CTOR(peObj1) { SC_THREAD(process_thread); }; }; I HAVE TROUBLE WITH FILE UPLOADING. SORRY
×
×
  • Create New...