VHDL Programming

(C. Jardin) #1

Data Types 105


Line 2 of the example declares a file type rom_data_file_tthat is used
to declare a file object. In line 3, a rom_data_fileobject is declared. In
this example, the physical disk path name was hard-coded into the model,
but a generic could have been used to pass a different path name for each
instance of the rom.
Line 6 of the example tests variable rom_initfor true or false. If false,
the initialization loop is executed. Line 7 is the start of the initialization
loop. The loop test makes use of the predefined function ENDFILE. The loop
executes until there is no more data in the file or when the romstorage
area has been filled.
Each pass through the loop calls the predefined procedure READ. This
procedure reads one integer at a time and places it in the element of
rom_datathat is currently being accessed. Each time through the loop, the
index iis incremented to the next element position.
Finally, when the loop finishes, the variable rom_initis set to true. The
next time the process is invoked, variable rom_initwill be true, so the
initialization loop will not be invoked again.
Writing a file is analogous to reading, except that the loop does not test
every time through for an end-of-file condition. Each time a loop writing data
is executed, the new object is appended to the end of the file. When the model
is writing to a file, the file must have been declared with mode OUT.

File Type Caveats


In general, the file operations allowed are limited. Files cannot be
opened, closed, or accessed in a random sequence. All that VHDL pro-
vides is a simple sequential capability. See Appendix D for a description
of VHDHL93 file access. For textual input and output, there is another
facility that VHDL provides called TextIO. This facility provides for
formatted textual input and output and is discussed in Chapter 8,
“Advanced Topics.”

Subtypes


Subtype declarations are used to define subsets of a type. The subset can
contain the entire range of the base type but does not necessarily need to.
A typical subtype adds a constraint or constraints to an existing type.
Free download pdf