EEVblog Electronics Community Forum

Electronics => FPGA => Topic started by: BrianHG on August 16, 2022, 11:39:52 am

Title: In Verilog, is it possible to define XXX only if a parameter is set?
Post by: BrianHG on August 16, 2022, 11:39:52 am
In Verilog, is it possible to define XXX only if a parameter is set?

I have a bunch of portions of my code where I include or exclude using `ifdef XXXX, `else XXXX, endif.

However, instead of globally `define XXXX, for each instance of my module, I wish for that `define to be turned on or off based on a parameter.  Is there a way to do this?
Title: Re: In Verilog, is it possible to define XXX only if a parameter is set?
Post by: cruff on August 16, 2022, 12:43:33 pm
Not sure what you need to accomplish, but can you just use a regular parameter and use if statements within a generate block and test for parameter equal to zero or not?
Title: Re: In Verilog, is it possible to define XXX only if a parameter is set?
Post by: BrianHG on August 16, 2022, 01:07:24 pm
That will only work for code I have inside the 'generate' & 'endgenerate'.
I have too may little snipets of code all over the place which are either there or not there depending on the option of the `define.
I'll stick with the good old `define for now unless I want to re-engineer the code.

My other choice is to have 2 version of the module, 1 with the enhanced features, one with the vanilla layer.
Title: Re: In Verilog, is it possible to define XXX only if a parameter is set?
Post by: langwadt on August 16, 2022, 01:26:15 pm
That will only work for code I have inside the 'generate' & 'endgenerate'.
I have too may little snipets of code all over the place which are either there or not there depending on the option of the `define.
I'll stick with the good old `define for now unless I want to re-engineer the code.

My other choice is to have 2 version of the module, 1 with the enhanced features, one with the vanilla layer.

make a file that contains `define XXXX use generate and param to conditionally include that file where you need it?
Title: Re: In Verilog, is it possible to define XXX only if a parameter is set?
Post by: Bassman59 on August 16, 2022, 02:40:32 pm

My other choice is to have 2 version of the module, 1 with the enhanced features, one with the vanilla layer.

With VHDL, you could create two (or more) architectures for one entity, and select which one is used with a generic or a configuration. Just sayin'.