Reputation: 335
Is there a way to change the header file on the fly?
The header file contains a lot of constants that can be used for the modules. In my application however, some of the constants must be changed often manually. Is there any way to change the values automatically?
I have tried the following approaches. 1. Use C++ to determine the constants and write them into the header file. 2. Use SV module to update the header file. All these methods need additional steps before running the top module. Is there any way to update the header file at the time of executing the simulator?
In the following header.v contains NUM, which is used in the module main. The NUM is changed often.
This problem also holds for other languages, too, such as C++ or Java.
header.v:
`define NUM 256 //256 must be changed often
module top ();
initial ...
//instantiation
main MAIN();
endmodule
//this module contains NUM
module main ();
byte[0:`NUM - 1];
endmodule
Upvotes: 0
Views: 208
Reputation: 19112
If it is different per module in the same simulation, then you should use parameter
instead of `define
.
main #(parameter NUM) (/*portlist*/);
// ...
byte array [0:`NUM - 1]; // FYI 'byte' is a SystemVerilog keyword
// ...
endmodule
Most simulations support passing a define from command line, which can work if the value is the same within a simulation, but different for each simulation.
+define+NUM=256
-define NUM=256
-D NUM=256
To reduce redefine warnings, wrap a `ifndef
to the definition in header.v
:
`ifndef NUM
`define NUM 256 //256 must be changed often
`endif
Upvotes: 1
Reputation: 417
C++ is a compiled language, where constants like stuff is translated to machine language during compile time ( I know its very raw description, for detailed understanding you may refer to process address space and where constants reside in it http://www.geeksforgeeks.org/memory-layout-of-c-program/). If you want to change these constants (or similar stuff), code should be recompiled. There are techniques where you can generated customized code from input text files using some tools. But that is not applicable in your scenario.
I suppose a configuration file is the best match in your case where you can define parameters as per customization.
Upvotes: 1