Jump to content
rahuljn

creating additional ports in before_end_of_elaboration callback

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

Share this post


Link to post
Share on other sites

The "problem" here is that your variable in1 gets destroyed as soon as the scope of your before_end_of_elaboration function is left. This means this port is non-existant during the call to sc_start and therefore no error occurs.

Share this post


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

Share this post


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!

 

Edited by Stephan Gerth

Share this post


Link to post
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...