Jump to content
Thomas_M

Fifo slots

Recommended Posts

Hi every one,

 

My question might be a bit dumb, i'm a bit new to all of this.

I have a module using an array of Fifos and I want to initialize em with custom depth (# of slots, not 16 as default).

 

When using only one sc_fifo you can give the number of slots in the constructor for instance SC_CTOR(....):......... fifo(#Slots){

But when using an array of, it I don't know how I am supposed to do. Everything I try won't work.

 

Can you help me with this ? Please :)

 

Thomas

Share this post


Link to post
Share on other sites

Dear Thomas,

 

Maybe using sc_vector instead of an array could solve your issue.

For details about sc_vector usage see Section 8.5 in the SystemC LRM (IEEE1666).

 

The following paper describes easy using, instantiating and binding or arbitrary numbers of signals and ports with sc_vector and C++11.

https://dvcon-europe.org/sites/dvcon-europe.org/files/archive/2015/proceedings/DVCon_Europe_2015_TA2_4_Paper.pdf

 

Greetings

Ralph

Share this post


Link to post
Share on other sites

Hey,

 

Thank you for your answer :) I didn't try it but it might work ! (I don't necesserly need vectors for my purpose :) )

 

Some guy working with me gave me another one which worked just fine. I share in case some one else is interested. Instead of static declaration, use dynamic in constructor.

 

 

 

 

sc_fifo<... >                  *Fifos [...];

 

 my_module(sc_module_name _name) : sc_module(_name)  {

  

for(i=0;i<...;i++)
          Fifos = new sc_fifo< ... > (nb_of_slots);
...

}

 

 

~my_module()
{
  for(i=0;i<...;i++)

    delete Fifos;
};

 

 

 

Here you go.

Share this post


Link to post
Share on other sites

This is the old and nasty way :) (before sc_vector was available).

 

sc_vector is not meant to be resizable. It is more to avoid error prone pointer handling and dynamic memory handling.

It hides memory handling from the user and gives you safe access to the elements.

 

One more benefit: Naming of objects.

You should give the fifos a name because it makes error messages (like 'unbound port', ...) much more readable and helpfull.

 

Doing this with your implementation (array of pointers/new) is possible but a lot of code writing.

sc_vector automatically names its elements by appending the element index to a prefix given by the user.

 

In addition to this, sc_vector provides some facilities for binding, ... of entire vectors instead of element by element. 

 

But for me most important is: No pointers and no dynamic memory required (and these are the root cause of so many errors in C and C++ programms).

 

So, my advice: have a look at sc_vector, and if you like it, tell the guys working with you about it :)

 

Greetings

Ralph

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

×