songlin941111 Posted August 26 Report Share Posted August 26 Hello, 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? Quote Link to comment Share on other sites More sharing options...
AmeyaVS Posted August 26 Report Share Posted August 26 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. Regards, Ameya Vikram Singh Quote Link to comment Share on other sites More sharing options...
songlin941111 Posted August 26 Author Report Share Posted August 26 struct My_module : sc_module{ static const int NUM = 7; sc_in< sc_uint<NUM> > a{"a"}; SC_CTOR(My_module); My_module(const sc_module_name& name, int NUM): sc_module(name), NUM(NUM) {} }; struct Top : sc_module{ SC_CTOR(top) { 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, Songlin Quote Link to comment Share on other sites More sharing options...
maehne Posted August 26 Report Share Posted August 26 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. Quote Link to comment Share on other sites More sharing options...
songlin941111 Posted August 28 Author Report Share Posted August 28 Hello maehne, Yes I'm a starter for C++ and SystemC... Thanks, your methode works very well. And thanks for your recommendation, i will learn these basic tools. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.