ankitks

passing size value of sc_fifo in sc_vector

8 posts in this topic

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

Hello,

Sorry for misunderstanding the problem.

But your problem seems to be too similar to the topic discussed here.

Specifically the comments: 

Regards,

Ameya Vikram Singh

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

AmeyaVS likes this

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now