VHDL Programming

(C. Jardin) #1

104 Chapter Four


disk where the file is located. (In most implementations this is true, but it
is not necessarily true.)

FILE TYPE EXAMPLES To read the contents of a file, you can call the
READprocedure within a loop statement. The loop statement can perform
read operations until an end of file is reached, at which time the loop is
terminated. Following is an example of a file read operation:

LIBRARY IEEE;

USE IEEE.std_logic_1164.ALL;
ENTITY rom IS
PORT(addr : IN INTEGER;
PORT(cs : IN std_logic;
PORT(data : OUT INTEGER);
END rom;

ARCHITECTURE rom OF rom IS
BEGIN
PROCESS(addr, cs)
VARIABLE rom_init : BOOLEAN := FALSE; --line 1
TYPE rom_data_file_t IS FILE OF INTEGER; --line 2

FILE rom_data_file : rom_data_file_t IS IN
“/doug/dlp/test1.dat”; --line 3

TYPE dtype IS ARRAY(0 TO 63) OF INTEGER;

VARIABLE rom_data : dtype; --line 4
VARIABLE i : INTEGER := 0; --line 5
BEGIN
IF (rom_init = false) THEN --line 6
WHILE NOT ENDFILE(rom_data_file) --line 7
AND (i < 64) LOOP
READ(rom_data_file, rom_data(i)); --line 8
i := i  1; --line 9
END LOOP;
rom_init := true; --line 10
END IF;
IF (cs = ‘ 1 ’) THEN --line 11
data <= rom_data(addr); --line 12
ELSE
data <= -1; --line 13
END IF;
END PROCESS;
END rom;

This example shows how a romcan be initialized from a file the first time
the model is executed and never again. A variable called rom_initis used
to keep track of whether the romhas been initialized or not. If false, the rom
has not been initialized; if true, the romhas already been initialized.
Free download pdf