Jump to content

Best way to pass parameters trough modules

João Paulo

Recommended Posts

As @Eyck suggested, constructor parameters should fit best your needs. You can even give them default values if it is sensible. If the number of parameters grows, grouping them in a struct may become handy. Its members can be default-initialised and you can override them with assignments before passing the whole struct to the module constructor. Personally, I like to first check for consistency and legal range for these parameters in the constructor / member function to which I pass this struct, e.g., by using assertions before actually using them for describing any behaviour/internal structure.

Link to comment
Share on other sites

  • 1 year later...


I have a similar preoblem :

I define a parameter NUM in My_module : static const int NUM = 7;

And this parameter is for port : sc_in< sc_uint<NUM> > a{"a"};

Then i would like to initialize this parameter in module constructor like this:
SC_CTOR(My_module ); My_module (const sc_module_name& name, int NUM): sc_module(name), NUM(NUM) {}

But it doesn't work, because of the error :
error: 'const int My_module::NUM' is a static data member; it can only be initialized at its definition

It seems like that sc_unit<> accepts onlt static parameter, and constructor parameter doesn't accept static...

Do you have some good advise for this parameter transfer need, pls?

Link to comment
Share on other sites

The discussed issue indicates a lack of proper understanding and mastery of C++ by the originators of this thread. Both @João Paulo and @songlin941111 need to obtain a better education in C++. There are many ways to do this, but it is fundamental to success with SystemC. SystemC is not C; although, I find many folks don't understand this. You can indeed understand a lot of SystemC with just a C background, but you truly do not understand SystemC until you fully understand C++.

C++ templates are a compile-time abstraction. As @Eyck and @maehne suggest, constructor arguments are the right way to go, which probably means using some base classes (e.g., sc_int_base or sc_uint_base -- see IEEE-1666-2011 section 7.5 and following) rather than templates. The use of CCI would also be appropriate to augment this.



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.

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