Jump to content

Parameter transfer during module instantiation


Recommended Posts


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

I also tried to change the signal definition to sc_in<bool> a[NUM]; but can't work either.

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

Link to comment
Share on other sites

Hello @songlin941111,

What are you trying to achieve in you implementation?

I see two different interface implementation in your query

1. sc_in of sc_uint with bithwidth set to NUM.

2 hours ago, songlin941111 said:

sc_in< sc_uint<NUM> > a{"a"};

2. sc_in of bool array of size NUM.

2 hours ago, songlin941111 said:

sc_in<bool> a[NUM];

It would be better if you could share the interface design you are looking out for module you are implementing.


Ameya Vikram Singh

Link to comment
Share on other sites

struct My_module : sc_module{
   static const int	NUM = 7;

	sc_in< sc_uint<NUM> >			a{"a"};


	My_module(const sc_module_name& name, int NUM):
		sc_module(name), NUM(NUM)

struct Top : sc_module{

		My_module* mod = new My_module("mode", 7);

Hello Ameya,

The code is as below. In fact, I would like to initialize the parameter NUM when instantiate 'My_module' in 'Top'. The problem is that constructor doesn't accept static parameter, and sc_uint<NUM> accept only static parameter... I appreciate a lot if you have some suggestions.

Best regards,


Link to comment
Share on other sites

You don't seem to be familiar with basic C++ concepts: You pass NUM as template parameter to the type sc_uint, i.e., its value needs to be known at compile time. If you want to pass this parameter when you instantiate your My_module, you'll have to make it a templated struct:

template<int NUM>
struct My_module : public sc_core::sc_module {
  sc_core::sc_in<sc_dt::sc_uint<NUM>> a{"a"};

Your Top module is also unsuitably structured: The My_module pointer mod needs to be a member variable. I wouldn't recommend to use C-style raw pointers, but std::unique_ptr for this purpose to automatically handle deallocation. Note that you need to pass NUM as template parameter like you did it for your port a in the sample code.

I recommend you to first learn properly C++, before exploring more SystemC.

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