João Paulo Posted August 31, 2021 Report Share Posted August 31, 2021 I'm creating a parametrized Network on Chip on SystemC, and i need to pass the position of each router by parameters, so i tried templates but they don't accept variables, only const values, for now, i'm using the sc_in port, but i'm trying to not use this, anyone now's other ways? Quote Link to comment Share on other sites More sharing options...
Eyck Posted September 1, 2021 Report Share Posted September 1, 2021 Why not use constructor prameters? Another option would be cci_params. Via the broker they can be given a value before they are created. So you can use them in contructor bodies.... João Paulo, David Black and swami-cdsi 3 Quote Link to comment Share on other sites More sharing options...
maehne Posted September 1, 2021 Report Share Posted September 1, 2021 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. swami-cdsi and João Paulo 2 Quote Link to comment Share on other sites More sharing options...
songlin941111 Posted August 26, 2023 Report Share Posted August 26, 2023 Hello, 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? Quote Link to comment Share on other sites More sharing options...
David Black Posted August 26, 2023 Report Share Posted August 26, 2023 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. 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.