library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
library UNISIM;
use UNISIM.VComponents.all;
library std;
use std.textio.all; --include package textio.vhd
use ieee.std_logic_textio.all;
entity filehandle is
port(
data_out : out std_logic_vector(15 downto 0)
);
end filehandle;
--architecture definition
architecture Behavioral of filehandle is
--period of clock,bit for indicating end of file.
signal endoffile : bit := '0';
signal clock : std_logic := '0';
signal rst : std_logic := '1';
signal dataread : integer;
signal linenumber : integer:=1; --line number of the file read or written.
signal rd_en : std_logic := '0';
signal wr_en: std_logic := '1';
COMPONENT FIFOa
--<skipping component here to save space>
END COMPONENT;
begin
uutF : FIFOa
PORT MAP (
rst => rst,
wr_clk => clock,
rd_clk => clock,
din => std_logic_vector(to_signed(dataread, 16)) ,
wr_en => wr_en,
rd_en => rd_en,
dout => data_out,
full => open,
empty => opem,
valid => open,
rd_data_count => open,
wr_data_count => open
);
clock <= not (clock) after 5 ns; --clock with time period 2 ns
process
begin
wait for 30 ns; rst <= '0';
wait for 500 ns ; rd_en <= '1';
end process;
--read process
reading :
process
file infile : text is in "1.txt"; --declare input file
variable inline : line; --line number declaration
variable dataread1 : integer;
begin
-- wait until clock = '1' and clock'event;
wait until rising_edge(clock);
if (not endfile(infile)) then --checking the "END OF FILE" is not reached.
readline(infile, inline); --reading a line from the file.
--reading the data from the line and putting it in a real type variable.
read(inline, dataread1);
wr_en <= '1';
dataread <= dataread1; --put the value available in variable in a signal.
else
endoffile <='1'; --set signal to tell end of file read file is reached.
wr_en <= '0';
end if;
end process reading;
end Behavioral;