Jump to content

IO port by reference


Hans64
 Share

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.

Link to comment
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

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

 Share

×
×
  • Create New...