Jump to content

How to terminate unused ports of modules in the port binding?


sc_fox

Recommended Posts

Hi.

 

In SystemC, you need a channel (signal) connected to each port. 

That is because writing to a port writes actually to the connected channel and without a channel, ...

 

Hence, you need to connect dummy signals to unused ports. 

To reduce the implementation effort, we implemented a small object comparable to the OPEN keyword in VHDL. 

 

I think this should only be used for output ports (like VHDL's OPEN). But a similar solution (with in-interface instead of inout-interface) should work for input ports aswell. 

 

static struct {
  
  template < typename T >
  operator sc_core::sc_signal_inout_if<T> & () const
  {
    return *(new sc_core::sc_signal<T>(sc_core::sc_gen_unique_name("vh_open")));
  }
  
} const vh_open = {};

 

You can bind the vh_open object to any unused output port. 

 

The code above works with GCC but does not work in ModelSim or Incisive (I don't know why). 

In ModelSim you can use:

static struct {
  
  template < typename T >
  operator sc_core::sc_port_b<sc_core::sc_signal_inout_if<T> > & () const
  {
    //return *(new sc_core::sc_signal<T>(sc_core::sc_gen_unique_name("vh_open")));
    sc_core::sc_signal<T> * sigp_ = new sc_core::sc_signal<T>(sc_core::sc_gen_unique_name("vh_open_s"));
    sc_core::sc_inout<T> * portp_ = new sc_core::sc_inout<T>(sc_core::sc_gen_unique_name("vh_open"));
    portp_->bind(*sigp_);
    return *portp_;
  }
  
} const vh_open = {};

 

To use it, you bind your ports to vh_open instead of an actual signal. 

model.port(vh_open);

Greetings

Link to comment
Share on other sites

Ralph, thanks for your reply. I appreciate it.

 

BTW, after I plugged in "vh_open" structure into my code, and bound my unused port "sc_out<int>" to "vh_open". But I have compile error like below. 

 

// myModule.h

SC_MODULE (myModule){

  sc_out<int> p1_;

  .....

};

 

 

// main.cpp

 

// your vh_open structure included here,,,.

 

int sc_main(){

...

  myModule m_;  // module instantiation

 

  m_.p1_(vh_open);  // binding to vh_open

...

 

}

 

 

 

 

 

error C2664: 'void sc_core::sc_in<T>::operator ()(sc_core::sc_port<IF,N,P> &)' : cannot convert parameter 1 from 'const <unnamed-type-vh_open>' to 'sc_core::sc_port<IF,N,P> &'
1>        with
1>        [
1>            T=int,
1>            IF=sc_core::sc_signal_inout_if<int>,
1>            N=1,
1>            P=SC_ONE_OR_MORE_BOUND
1>        ]
1>        and
1>        [
1>            IF=sc_core::sc_signal_inout_if<int>,
1>            N=1,
1>            P=SC_ONE_OR_MORE_BOUND
1>        ]
Link to comment
Share on other sites

I think, your error message does not match the code you've shown.  The compiler complains about an sc_in, not an sc_out as you've shown in your code.

 

For input ports, you can apply a similar trick, but instead converting to an sc_signal_in_if<T> const&.  If you need to provide a non-zero constant value, you'll need to assign this value to the signal that is created before returning it for the binding.  It can be done via a free-standing function then (to avoid duplicating the datatype template argument).  Something like the following (untested) snippet:

 

 

template<typename T>
sc_core::sc_signal_in_if<T> const &
vh_const( T const & v ) // keep the name consistent with vh_open
{
  // Yes, this is an (elaboration-time) memory leak.  You can avoid it with some extra effort
  sc_core::sc_signal<T>* sig_p = new sc_core::sc_signal<T>( sc_core::sc_gen_unique_name("vh_const") );
  sig_p->write( v );
  return *sig_p;
}

 

Which version of MSVC do you use?  You may want to try a newer one instead...

 

hth,
  Philipp
 

Link to comment
Share on other sites

Thanks for your message, Philipp. 

And you're right, I bound the input port to "vh_open", rather than output ports. 

After fixing, it worked for the output port.

Thanks to Ralph, again and Philipp, too.

 

BTW, Philipp, the snipped one in your message causes compile error when I bound the input port to "vh_const".

 

 

error C2664: 'void sc_core::sc_in<T>::operator ()(sc_core::sc_port<IF,N,P> &)' : cannot convert parameter 1 from 'const sc_core::sc_signal_in_if<T> &(__cdecl *)(const T &)' to 'sc_core::sc_port<IF,N,P> &'
1>        with
1>        [
1>            T=int,
1>            IF=sc_core::sc_signal_inout_if<int>,
1>            N=1,
1>            P=SC_ONE_OR_MORE_BOUND
1>        ]
1>        and
1>        [
1>            IF=sc_core::sc_signal_inout_if<int>,
1>            N=1,
1>            P=SC_ONE_OR_MORE_BOUND
1>        ]

 

 

I'm using MSVC2008.

 

Thanks!

Link to comment
Share on other sites

You're supposed to call the function, not to pass the function (pointer) to the bind call.

Try something like

 

sc_in<int> p_in;

p_in( vh_const(42) );

 

You'll need to make sure that the parameter passed to vh_const matches the type of the port exactly, otherwise the binding will fail as well.  If needed, you can add the type explicitly to the vh_const call:
 

p_in( vh_const<int>(42L) ); // should work, even though argument is of type 'long'

 

hth,
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.

×
×
  • Create New...