Can I uses in VHDL something similar to the C-Sourcecode-Macros __DATE__ and __TIME__
to make the compile time available in the FPGA as a kind of version time stamp?
As a >>>new-comer<<< to VHDL I want to modify the following existing code, which puts a hard coded date into a FPGA register. I always have to remember adjusting the values before compiling. It would be easier if this is done automatically. Can I also include hours/minutes/seconds?
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY Datum2 IS
PORT
(
Day :OUT std_logic_vector(4 downto 0);
Month :OUT std_logic_vector(3 downto 0);
Year :OUT std_logic_vector(4 downto 0)
);
END Datum2 ;
ARCHITECTURE rtl OF Datum2 IS
BEGIN
-- "08.08.0013"
Day <= conv_std_logic_vector(8, 5);
Month <= conv_std_logic_vector(8, 4);
Year <= conv_std_logic_vector(13, 5);
END ARCHITECTURE rtl;
Current date and time is not directly available in VHDL, but solution is suggested below.
EDITED 2013-08-10: Added description for Altera Quartus II Tcl automatic generation.
One way to make date and time available is through an automatically generated VHDL package like the below:
This VHDL package can be created with a Tcl script like this:
In Altera Quartus II it is possible to make the flow run this script before synthesis, whereby the datetime package can be created. This is done in the .qsf file with the line below, where the script is named "make_datetime.tcl":
Further description of this Quartus II feature can be found in Quartus II Tcl Example: Automatic Script Execution.
The Datum2 module can then use the package like this:
After synthesis in Quartus II the RTL viewer shows the module outputs as below:
Previously described alternative solutions are to create the VHDL package with a Bash script like this:
For platform independence then a Python 3.x script like this may be used:
For presentation of date and time in 32-bit register values, a module can be like this:
Waveform shown below.
The Bash or Python script approach requires integration in the build flow for automatic package generation.
EDITED 2016-08-08 with update by Damien: Description of non-Tcl script call from Altera Quartus.
To integrate a bash script (under Linux), create a Tcl wrapper script which calls the bash script as part of the process. In this example, there is a "scripts" directory which has a "call_bash.tcl" script and a "make_datetime.sh" which does the actual work:
Integrating into Altera's build flow can then be achieved by adding the following to the the qsf file: