Jump to content
dilawar

Making a port optional

Recommended Posts

https://www.doulos.com/knowhow/systemc/new_standard suggests to do the following.

sc_port<i_f, 1, SC_ZERO_OR_MORE_BOUND> opt_port;

I am trying to replace some of my `sc_out` and `sc_in` with optional ports. I would like to replace them with `sc_out_opt` and `sc_in_opt` class in headers of my modules.

What is the best way to derive these classes such that my code-base works with minimal changes to code?

1. Should I derive them from `sc_port<i_f, 1, SC_ZERO_OR_MORE_BOUND>` or `sc_in` and `sc_out` classes?

2. Can I force a port policy on `sc_in` and `sc_out` in module constructor?

Any other suggestions?

Share this post


Link to post
Share on other sites

If you don't use the member functions added that were added for convenience to `sc_in`, `sc_out`, and `sc_inout` to, e.g., call `read()`, `write()`, and the event member functions via the `.` operator than via the corresponding member function in the interface accessed via the `->` operator, you might be able to avoid entirely the derivation of new port classes. Instead, you could simply use a template alias, which was introduced with C++'11:

template<typename T>
using sc_in_opt = sc_core::sc_port<sc_signal_in_if<T>, 1, SC_ZERO_OR_MORE_BOUND>;
template<typename T>
using sc_inout_opt = sc_core::sc_port<sc_signal_inout_if<T>, 1, SC_ZERO_OR_MORE_BOUND>;
template<typename T>
using sc_out_opt = sc_core::sc_port<sc_signal_inout_if<T>, 1, SC_ZERO_OR_MORE_BOUND>;

If you want to also provide all member functions of `sc_in`, `sc_out`, and `sc_inout`, you will have to derive from the `sc_port` class and implement the full interface as defined in IEEE Std 1666-2011. 

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