Jump to content

creating additional ports in before_end_of_elaboration callback


rahuljn

Recommended Posts

Hello

 

As per standard we can create new sc_port in before_end_of_elaboration callback

In the following example, I am creating a new port in before_end_of_elaboration callback but it is not connected in sc_main.

#include "systemc.h"

class test : public sc_module {
    public:
    SC_HAS_PROCESS(test);
    test(sc_module_name name){
        SC_THREAD(fun);
    }
    void fun(){}
    void before_end_of_elaboration(){
        sc_port<sc_signal_inout_if<bool> > in1;
    }
};

int sc_main(int, char**){
    test t("t");
    sc_start(100,SC_NS);
    sc_stop();
    return 0;
}

But I am not getting unconnected port error.

 

 

Thanks

RahulJn

Link to post
Share on other sites

Hello

 

I agree with you but the standard says that you can instantiate new sc_ports etc in before_end_of_elaboration callbacks.

If you see @24 of IEEE doc, it says

"The instantiation of objects of class sc_module,sc_port,sc_export, sc_prim_channel"

 

Then how it works ?

 

Thanks

Rahul

Link to post
Share on other sites

It has nothing to do with the SystemC standard but with how C++ works. You create in1 on the stack instead of the heap which is why it is destroyed at the and of the function scope. If you can't move the port to be a member of test you would need to do it via a pointer:

sc_port<sc_signal_inout_if<bool> >* in1 = new sc_port<sc_signal_inout_if<bool> >();

Please not that you can't access in1 after the function scope. It would need to be a member of test!

 

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...