Jump to content
Hans64

IO port by reference

Recommended Posts

Hi All,

Can I pass a reference to IO port?

The code below results in a Modelsim error which I suspect is because of the sc_out reference
 

SC_MODULE(PROC3) {

    sc_in<bool >    clk;
    sc_in<bool >    reset;
    sc_in<bool >      dbusin;
    sc_out<bool >     dbusout;
   
    void doff(const sc_core::sc_in<bool>pin, sc_core::sc_out<bool>&pout) {
        pout.write(pin.read());
    }   
       
    void entry_clk() { 
        while(true) {
            doff(dbusin,dbusout);               
            wait();
        }  
    }   

    SC_CTOR(PROC3) {
         SC_CTHREAD(entry_clk,clk.pos());       
    }
};


# ** Error: (vsim-6511) Insert port failed: simulation running: port '/proc3_tb/DUT/entry_clk/port_0' (sc_port_base)
# In process: /proc3_tb/DUT/entry_clk @ 55 ns


Thanks,
Hans.

Share this post


Link to post
Share on other sites

Hans,

 

Can I pass a reference to IO port?

 

Yes, you can (no pun intended).

 

    void doff(const sc_core::sc_in<bool>pin, sc_core::sc_out<bool>&pout) {

 

Here, you try to pass pin by value, which invokes a (deprecated, non-naming) copy-constructor, taking a non-const reference to dbusin.  Since the simulation is already running (as it is said in the error message), this port creation fails.

 

Add the missing & to pass pin by const-reference (as probably intended anyway).

 

/Philipp

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×