kaiserhaz Posted July 15, 2015 Report Share Posted July 15, 2015 Hello, I've been trying to instantiate (if I'm not mistaken) an array of submodules that were created using sc_vector. So far, I've followed the recommendations for using custom creator functions, but I'm kind of lost at how to actually make it work. Especially with sc_bind, which keeps returning me errors. The module master houses an array of ports that will be connected to a corresponding number of slaves. Order of connection does not matter. I'm using MSVC++ 10. The code is as follows: class top : public sc_module { //Submodule declarations master master_i; sc_vector<slave> slave_i; public: // Constructor top( sc_module_name module_name , int k ) : sc_module( module_name ) , master_i("master"), slave_i("slave") { slave_i.init(N_SLAVE, sc_bind(&top::create_slave, this, sc_unnamed::_1, sc_unnamed::_2)("slave",k)); sc_assemble_vector(slave_i, &slave::target_port).bind(master_i.initiator_port); } The creator function, which is a member of the class top, is as follows: static slave* top::create_slave(const char* name, size_t idx) { slave* s = new slave(name,1); // Hardcoding not intended; it's just to get it to // compile return s; } slave class constructor prototype: slave( sc_module_name module_name , int k ); Errors that I have so far: 1>c:\systemc\systemc-2.3.1\src\sysc\packages\boost\bind.hpp(63): error C2825: 'F': must be a class or namespace when followed by '::' 1> c:\systemc\systemc-2.3.1\src\sysc\packages\boost\bind\bind_template.hpp(15) : see reference to class template instantiation 'sc_boost::_bi::result_traits<R,F>' being compiled 1> with 1> [ 1> R=sc_boost::_bi::unspecified, 1> F=slave *(__cdecl *)(const char *,size_t) 1> ] 1> c:\users\khairul\dropbox\cours\systemc\examples\source\11\master_slave\top.h(32) : see reference to class template instantiation 'sc_boost::_bi::bind_t<R,F,L>' being compiled 1> with 1> [ 1> R=sc_boost::_bi::unspecified, 1> F=slave *(__cdecl *)(const char *,size_t), 1> L=sc_boost::_bi::list3<sc_boost::_bi::value<top *>,sc_boost::arg<1>,sc_boost::arg<2>> 1> ] Any ideas? Thanks, Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted July 15, 2015 Report Share Posted July 15, 2015 Hi, I see two problems here: A) why is your creator function static? I am not sure if this is allowed. The ("slave",k) part in the init/bind call should not be there. The actual arguments are handeled inside the vector init method. The first (sc_unnamed::_1) is the name of the vector (given as constructor argument to the sc_vector). The second (sc_unnamed::_2) is the index of the current element to be created within the sc_vector. Greetings Ralph Quote Link to comment Share on other sites More sharing options...
kaiserhaz Posted July 16, 2015 Author Report Share Posted July 16, 2015 Hello, Alright, I followed your suggestions and it seems to work . I also changed the port binding from using sc_assemble_vector to iterating over the array. But it still didn't solve one problem: that k in the ("slave",k) is actually a variable that determines the size of an array in the slave module (something like mem[ k * (int) ]), and not an index. So basically, I'm trying to instantiate a vector of slaves that has an extra parameter that would determine the size of it's memory array. slave( sc_module_name module_name , int k ) : /* Init items here */ { /* Other constructor codes here */ memory = new ADDRESS_TYPE[ k * 64 ]; } Pardon me, I may have forgotten to mention that So is there anything that could be done? Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted July 16, 2015 Report Share Posted July 16, 2015 Hi. Inside the create_slave method, you can do whatever you want. You can use the name and index arguments passed to the method by the sc_vector infrastructure. If there is no dependency to the index, you can simply ignore it (in this case you can leave out the parameter name in the declaration to avoid compiler warnings: ... create_slave(const char* name, size_t) ... ). Furthermore you can use everything you can use in any other member method of top (because create_slave is a member method of top), i.e. the members of top, global variables, ... Greetings Ralph Quote Link to comment Share on other sites More sharing options...
kaiserhaz Posted July 17, 2015 Author Report Share Posted July 17, 2015 Thanks for the tip. 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.