jcmel Posted December 2, 2016 Report Share Posted December 2, 2016 Hi everybody, I would like to implement a communication between a process (P1) and another process P2 inside an instance (m2) through a fifo of schedule. At compilation it looks well but at run time i am facing a problem of binding failed (port p0 not bound). I don't understand the error (E109) because in constructor of m1, I did the binding m2->p0(c0). Thanks for your help. regards Jean-Claude Quote Link to comment Share on other sites More sharing options...
apfitch Posted December 8, 2016 Report Share Posted December 8, 2016 Could you post your code? regards Alan Quote Link to comment Share on other sites More sharing options...
jcmel Posted December 12, 2016 Author Report Share Posted December 12, 2016 Hi, Here is a part of the code. Regards, Jean-Claude class M2 : public sc_module { public: // Constructor M2(sc_module_name name); // Destructor ~M2(); sc_port<sc_fifo_in_if< Schedule> > p0; private: void threadReceiveSchedule(); .... }; SC_HAS_PROCESS(M2); M2::M2(sc_module_name name) { SC_THREAD(threadReceiveSchedule); } void M2::threadReceiveSchedule() { Schedule schedule; while(true) { if (p0->nb_read(schedule)) { // DO something } wait(10, SC_NS); } } ////////////////////////////////////////// class M1 : public sc_module { public: // Constructor M1(sc_module_name name); // Destructor ~M1(); sc_fifo<schedule > > c0; private: M2* _m2; .... }; SC_HAS_PROCESS(M1); M1::M1(sc_module_name name): c0("fifo_schedule", 10) { _m2 = new M2("M2"); // binding _m2->p0(c0); } void M1::process() { .... c0.write(schedule); } Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted December 12, 2016 Report Share Posted December 12, 2016 Hi Jean-Claude, I am not sure if this couses the port not bound error but I see at least one issue in your code: SC_HAS_PROCESS macro shall beinvoked within the class definition or the constructor body. I looks like you are calling it in a global area between class definition and ctor body or in a cpp file right before the ctor body. Please try to move the macro call into the module/class definition. Greetings Ralph Quote Link to comment Share on other sites More sharing options...
jcmel Posted December 12, 2016 Author Report Share Posted December 12, 2016 Hi Ralph, For the definition of SC_HAS_PROCESS macro, I followed the recommended style defined in SystemC: From the Ground up illustrated in figure 4.20: Recommended style NAME.cpp page 57. I believe I dont' have the permission to provide a pdf of this page. I'am right. Regards, Jean-Claude Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted December 12, 2016 Report Share Posted December 12, 2016 OK. It seems to work as well when you place the constructor in a cpp file. I did not use it that way so far. Actually, the standard says something differrent: IEEE1666-2011: Sec 5.2.8: "Macro SC_HAS_PROCESS shall only be used within the class definition, constructor body, or member function body of a module. The name of the module class being constructed shall be passed as the argument to the macro. The macro invocation shall be terminated with a semicolon." Rest of your example seems to be OK and the code below works in my environment (slight modification of your code replacing Schedule with int and fixed typos): //m2.h #include <systemc> using namespace sc_core; class M2 : public sc_module { public: // Constructor M2(sc_module_name name); sc_port<sc_fifo_in_if< int > > p0; private: void threadReceiveSchedule(); }; //m2.cpp #include "m2.h" SC_HAS_PROCESS(M2); M2::M2(sc_module_name name) { SC_THREAD(threadReceiveSchedule); } void M2::threadReceiveSchedule() { int schedule; while(true) { std::cout << "read fifo" << std::endl; if (p0->nb_read(schedule)) { } wait(10, SC_NS); } } //m1.h #include <systemc> #include "m2.h" class M1 : public sc_module { public: // Constructor M1(sc_module_name name); sc_fifo< int > c0; void process(); private: M2* _m2; }; //m1.cpp #include "m1.h" SC_HAS_PROCESS(M1); M1::M1(sc_module_name name): c0("fifo_schedule", 10) { _m2 = new M2("M2"); _m2->p0(c0); } void M1::process() { int schedule; c0.write(schedule); } //main.cpp #include "m1.h" using namespace sc_core; int sc_main(int,char**) { M1 _m1("m1"); sc_core::sc_start(sc_core::SC_ZERO_TIME); return 0; } 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.