|
<< Click to Display Table of Contents >> 6.9 Input Data Dynamically from a File (VHDL) |
![]() ![]()
|
VHDL test benches can read data from a file during simulation. This is not supported in Verilog, but there is a way to mimic this feature by initializing an array during the test bench build process as described in Section 6.10 (Verilog) Initialize Array from File or Section 6.11 (VHDL) Initialize Array from File.
To read data from a file, first create a Test Vector data file and put it in the File Input folder. TestBencher will parse the file and create a project-level variable of type File Input to read from the file. This variable is defined by a class with fields (one field per column in the test vector spreadsheet file). Inside a timing diagram, the @FileName_in.ColumnName notation can be used to access the file variable in waveforms, delays, setups, holds, markers, and the conditional and action fields of Samples. Each time a diagram transaction is applied, TestBencher will read the next data line from the input file.
1) Create a data file:
Create a tab separated text file with data as described in Section 6.7 SynaptiCAD Test Vector File Format using a spreadsheet program or a timing diagram. The data values read from the test vector file during the simulation run are not allowed prefixes that indicate the radix type (e.g. A4 is allowed for a hex value in the file, but 'hA4 is not). Below is an example of a legal test vector input file:
[Vectors] Radix=hex Addr Data[7:0](bin) A4 10110011 54 11011010 .... |
2) Add Test Vector File to project to Automatically create file class and variable:
|
|
|
Investigate the file class and variable that was created:
|
|
|
|

|

|

3) Accessing the File Variable:
Once a file variable is created at the project level, its fields can be accessed in any of the project's timing diagrams. Use the @filevariablename_in.fieldname to read or write to a field. This code can be entered anywhere a variable can be used, such as in a waveform state (Section 2.4 Waveform States and Conditions), samples (Section 3.2 Sample Checking and Actions), parameters (Chapter 4: Transaction Delays, Setups, and Holds), and in markers (Section 5.6 HDL Code Markers).
Causing an input line to be read from a file:
ReadFromFile(filename_in, filename_in_handle); This says read the next line from the file into the filename_in file variable. This will fill the fields of this structure with the new address and data values from the next line in the file. |
For output files, a line of data is written at the end of any transaction that references the file variable.