Jump to content

Recommended Posts

Posted

I'll give a brief example of what I intend to to:

 

template <int N>

SC_MODULE(request_scheduler_m) 
{  
   subblock subblock[N];
 
   void proc();
   
   SC_CTOR(request_scheduler_m)     
   {
      unsigned int i;
 
      for (i = 0; i < N; i++)
      {
         round_robin[N]("subblock instance");
      }
(...)
 
Basically, N subblocks must be instantiated inside request_scheduler and N is a template parameter. The compiler is complaining about the code above. Is it possible to do that?
Posted

The compiler is complaining because you can't supply a constructor argument to an element of an array.

 

Either replace your array of subblocks with an array of pointers to sub-blocks, or, even better, use sc_vector (see 1666-2011).

 

kind regards

Alan

Posted

Thanks for the answer, using the sc_vector did the trick :)

 

But how can I use vectors when submodules require extra arguments in the constructor? They tried to cover it in 1666-2011, but they wouldn't be able to write a worst explanation even if they would have put a lot of effort on it. Really tough to understand with incomplete examples.

Posted (edited)

I think I can safely say the LRM is not intended to be a tutorial :-)

 

Philipp Hartmann wrote a paper

 

https://complex.offis.de/documents/doc_download/29-scvector-container-and-the-ieee-p1666-2011-systemc-standard

 

and he also wrote the original code.

 

I'm sure Philipp will pop up if you have any further questions,

 

kind regards

Alan

 

P.S. I couldn't get the download link to work - but if you click View, you can then download it from the viewer.

Edited by apfitch
Posted (edited)

Thanks for letting me know, that the download link is somewhat broken.  I tried to fix it and it seems to be working here now.  The link to the details page is https://complex.offis.de/documents/doc_details/29. In this presentation, several examples for "custom creator functions" are given.  Personally, I prefer the variant of using sc_bind in combination with a local member function:

 

// creator function (member function of surrounding block)
subblock*
request_scheduler_m::create_subblock( const char* nm, size_t idx ) {
  // call constructor with other parameters
  subblock* sub_p = new subblock(nm, param_1, param_2);
  return sub_p;
}

// initialize vector with custom creator
subblock_vec.init( N, sc_bind( &request_scheduler_m::create_subblock, this, sc_unnamed::_1, sc_unnamed::_2 ) );

 

Using this variant of a creator, you can easily "store" and/or prepare the values of the module parameters within member variables of the surrounding module.

 

Greetings from Oldenburg,
  Philipp

Edited by Philipp A. Hartmann

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.

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