Jump to content
ankitks

passing size value of sc_fifo in sc_vector

Recommended Posts

I created vector of fifos:

sc_vector<sc_fifo>  fifos;

and in my constructor:
 

template <unsigned S>
class my_chnl : public my_chnl_if, public sc_channel {
  
  sc_vector<sc_fifo> fifos;  //vectors of fifos
  
  
//-----------------------------------------------------------
public:

  //-----------------------------------------------------------
  //constructor
  //-----------------------------------------------------------
  explicit my_chnl(sc_module_name nm, unsigned _size = 4)
    : sc_channel(nm),
      fifos("FIFO")
  {
    fifos.init(S, _size);
  }
  .....

I am getting compile error saying that 

include/sysc/utils/sc_vector.h:634: error: \u2018c\u2019 cannot be used as a function

 

If I do fifos.init(S), it works, but I get default size of 16.  How do I set custom size? Any help?

 

Thanks

Share this post


Link to post
Share on other sites

It seems you are using the sc_vector<>.init method incorrectly.

As per the source from sc_vector.h you are trying to pass _size as a function pointer (Creator function).

Can you make modifications from:

explicit my_chnl(sc_module_name nm, unsigned _size = 4)
    : sc_channel(nm),
      fifos("FIFO")

to:

explicit my_chnl(sc_module_name nm, unsigned _size = 4)
    : sc_channel(nm),
      fifos("FIFO", _size)

Also sc_fifo is template class what type are you specializing it to?

If you are creating to a vector of sc_fifo of int datatype your declaration should be:

sc_vector<sc_fifo<unsigned int> > fifos;  //vectors of fifos

Regards,

Ameya Vikram Singh

Share this post


Link to post
Share on other sites

Hello,

_size  is not the size of sc_vector which I am already setting by passing S. _size is the size of buffer inside each sc_fifo. sc_fifo constructor takes size argument and I don't know how to pass that argument.

Share this post


Link to post
Share on other sites

Hi.

If you want to pass arguments to the constructor of the elements of an sc_vector, you need a custom creator. See SystemC LRM IEEE:1666 Section 8.5.5 for details and examples.

A very easy way to realize custom creator by using a Lambda function is presented here:

https://www.researchgate.net/publication/284731273_Automated_SystemC_Model_Instantiation_with_Modern_C_Features_and_sc_vector

 

Greetings

Ralph

Share this post


Link to post
Share on other sites

Yes you can. If you do not have a chance to update your compiler, you can still use one of the two methods mentioned in the IEEE1666 SystemC LRM Section 8.5.5: A creator function object or a member function. Both solutions are not as compact as the Lambda solution, but they do not require any C++11 feature.

Share this post


Link to post
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.

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