Jump to content

How to create a vector of fifos and add new fifos values depending on an input?


gabriel123

Recommended Posts

Hi, im  new to systemC.

I want to know how to create a specific amount of sc_fifos<int> depending on an argument. Usually something like this is done with a vector in c++. That is why i thought that an sc_vector is appropriate here.

My original code (static). I would have to write new fifos depending on how much i need:

sc_fifo<int> *fifos1;
sc_fifo<int> *fifos2;
sc_fifo<int> *fifos3;
  
fifos1 = new sc_fifo<int>(50000);
fifos2 = new sc_fifo<int>(50000);
fifos3 = new sc_fifo<int>(50000);

 

The approach with vectors:

sc_vector< sc_fifo<int> > fifos;

fifos(outputs)
for (int i = 0; i < outputs; i++) {
	fifos[i] = new sc_fifo<int>(50000);
}

The above code doesn't work. How am i supposed to initialize the vector and add new sc_fifos?

Link to comment
Share on other sites

SystemC FIFO's represent hardware and as such may only be created during construction of a model. After elaboration closes, you are not allowed to add more fifos. None of your code examples above are complete, so it is fairly hard to give you a complete answer. Perhaps you could put your design on https://edaplayground.com and share a link with us.

For details on phases of SystemC (e.g. elaboration) see IEEE-1666-2011.pdf, which you can obtain through Accellera.org.

 

Link to comment
Share on other sites

This is all in the constructor so they are created during construction if i understand correctly. I want to know how to add members to my sc_vector. In C++ the method push_back would be used. If it isnt possible does that mean if i need 1000 fifos i would have to write the below code 1000 times?

sc_fifo<int> *fifos1;
  
fifos1 = new sc_fifo<int>(50000);

 

Link to comment
Share on other sites

In the constructor list you would provide a creator function. This is a functor(a function pointer, a std::function object, a Functor classinstance, a lambda function, ...) which accepts a char const* and a size_type and returns a constructed object. In your case it would look like (C++11):

class example: public sc_core::sc_module {
public:
  sc_core::sc_vector<sc_core::sc_fifo<unsigned>> fifos;
  
  example(sc_core::sc_module_name nm, unsigned outputs)
    : sc_core::sc_module(nm)
    , fifos("fifos", outputs, [](char const* name, unsigned i)->sc_core::sc_fifo<unsigned> {
        return new sc_core::sc_fifo<unsigned>(5000);
      }
  {
    // some construction code
  }
}

 

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