2
votes

I wanted to have a parameterized FIFO instantiation so that I can call a single FIFO instance with change in depth(parameter).

e.g. I have written a code for FIFO with depth as a parameter.

I will know the depth of the FIFO only by the configuration from Microprocessor. Based on the register configuration, can i call this FIFO with variable parameter like value?

integer depth_param;
 if(config_reg[1])
   depth_param <= 128;
 else
   depth_param <= 512;

 genfifo #(depth_param) (.din (din),.wr(wr)....);

fifo module is:

 module gen_fifo #(depth = 128)
 ( din,wr,rd,clk....);

can you please suggest is there a way I can do this?

1
Just make a tap in your fifo at position 128, then make a switching logic that will use data from tap in case of config_reg[1] = 1, else use data from fifo end.Sergei Kulik
A parameter needs a constant value. The value cannot change after compilation or synthesis. The name config_reg implies a register, something that is load after compilation/synthesis. Is config_reg a register or parameter?Greg
@Sergei: you can't do that. Everything changes when you change the FIFO depth - address pointer wrap-around, AE, EF, AF, FF flags - you can't just take data from the middle. The OP must create a complete run-time configurable FIFO.EML
I doubt you can create "runtime" configurable FIFO. What is runtime in hardware world? Just a bunch of FF and wires. At most you can cover several constant cases.Sergei Kulik
@Sergei - it's straightforward - program your FIFO depth into a register, and use that register as the limit test in the RW pointers, instead of testing against a constant. Similarly, the flags are derived against the register, instead of being derived against a constant.EML

1 Answers

0
votes

This is what the LRM says:

Parameters represent constants; hence, it is illegal to modify their value at run time. However, module parameters can be modified at compilation time to have values that are different from those specified in the declaration assignment. This allows customization of module instances. A parameter can be modified with the defparam statement or in the module instance statement. Typical uses of parameters are to specify delays and width of variables.

'run time' means during simulation, after elaboration. A synthesiser doesn't 'run' anything, but what you're doing is effectively "run time", and so is illegal.

This doesn't mean that you can't do it, though. Pass in your FIFO depth as a module port. I'm assuming that you know how to code a FIFO from first principles. If so, you will normally have a constant for the FIFO size; just replace this constant with the value at the port, and find some way to set the memory size. You'll obviously need to be careful when changing the FIFO size - you may need to reset it, for example. If you don't know how to code a FIFO you should ask with an FPGA or an electronics tag.