P
Pete Fraser
Guest
I'm trying to read a list of stimulus files from a directory file.
This is described on page 527 of Ashenden's book.
At the start of file_loop, read(directory, file_name, file_name_length);
doesn't do what I expected. I assumed it would read an individual
string representing a file name, and would stop when it came to a <CR>
or <LF> . Then on the next pass of the loop it would read the
next filename. Instead, it fills file_name with 50 characters
(including <CR> and <LF> on each pass.
What am I doing wrong?
Thanks
file_reader : process is
type directory_file is file of string;
file directory : directory_file open read_mode is "stimulus-directory";
variable file_name : string(1 to 50);
variable file_name_length : natural;
variable open_status : file_open_status;
variable char : character;
type char_file is file of character; -- one byte each
file stim_file : char_file;
begin
file_loop : while not endfile(directory) loop
read(directory, file_name, file_name_length);
if file_name_length > file_name'length then
report "file name too long: " & file_name & "... - file skipped"
severity warning;
next file_loop;
end if;
file_open (open_status, stim_file,
file_name(1 to file_name_length), read_mode);
if open_status /= open_ok then
report file_open_status'image(open_status) & " while opening file "
& file_name(1 to file_name_length) & " -file skipped"
severity warning;
next file_loop;
end if;
stimulus_loop : while not endfile(stim_file) loop
if (rst = '1') then
sig <= "00000000";
data_valid <= '0';
elsif (clk'event and clk='1') then
data_valid <= valid;
if (valid = '1') then
read(stim_file, char);
end if;
sig <= char2std(char);
end if;
end loop stimulus_loop;
file_close(stim_file);
end loop file_loop;
wait;
end process file_reader;
This is described on page 527 of Ashenden's book.
At the start of file_loop, read(directory, file_name, file_name_length);
doesn't do what I expected. I assumed it would read an individual
string representing a file name, and would stop when it came to a <CR>
or <LF> . Then on the next pass of the loop it would read the
next filename. Instead, it fills file_name with 50 characters
(including <CR> and <LF> on each pass.
What am I doing wrong?
Thanks
file_reader : process is
type directory_file is file of string;
file directory : directory_file open read_mode is "stimulus-directory";
variable file_name : string(1 to 50);
variable file_name_length : natural;
variable open_status : file_open_status;
variable char : character;
type char_file is file of character; -- one byte each
file stim_file : char_file;
begin
file_loop : while not endfile(directory) loop
read(directory, file_name, file_name_length);
if file_name_length > file_name'length then
report "file name too long: " & file_name & "... - file skipped"
severity warning;
next file_loop;
end if;
file_open (open_status, stim_file,
file_name(1 to file_name_length), read_mode);
if open_status /= open_ok then
report file_open_status'image(open_status) & " while opening file "
& file_name(1 to file_name_length) & " -file skipped"
severity warning;
next file_loop;
end if;
stimulus_loop : while not endfile(stim_file) loop
if (rst = '1') then
sig <= "00000000";
data_valid <= '0';
elsif (clk'event and clk='1') then
data_valid <= valid;
if (valid = '1') then
read(stim_file, char);
end if;
sig <= char2std(char);
end if;
end loop stimulus_loop;
file_close(stim_file);
end loop file_loop;
wait;
end process file_reader;