Here is what I am able to edit when I got few errors though there seem
to be no reason for those.
I have no idea what you mean. When I tried out my own code
just now I found a few silly errors that prevented it from
compiling; it took me about a minute to fix them.
What's the problem?
But now I am getting undefined values [...]
I don't want to change this code much
Why not? You'll learn far more if you *do* change it.
Hack around, add plenty of diagnostics, try things out,
see what happens, until you are confident that you
know how to do it all for yourself.
ReadAndApply
rocess
variable c: character;
variable i: integer;
variable L: line;
begin
file_open(StimCSV, "StimCSV.csv", READ_MODE);
wait until (clk'event and clk = '1'); [...]
din <= stimulus;
end if;
file_close(StimCSV);
wait;
You're OK with just getting exactly one line of stimulus
from the file? Doesn't sound very interesting to me.
Since you don't seem to want to debug for yourself,
here's my code fully debugged and working. I didn't
need to change very much. I've put in some fixed
time delays so that you can see the values on signal
"stimulus" in a wave viewer.
entity read_csv_test is end;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use std.textio.all;
architecture A of read_csv_test is
subtype slv10 is std_logic_vector(9 downto 0);
type arr_slv10 is array(natural range <>) of slv10;
signal stimulus: arr_slv10(0 to 7);
file StimCSV: text;
begin
ReadAndApply: process
variable c: character;
variable i: integer;
variable L: line;
begin
file_open(StimCSV, "test.csv", READ_MODE);
while not endfile(StimCSV) loop
wait for 10 ns;
readline(StimCSV, L); -- Get the next stimulus line
for j in stimulus'range loop
read(L, i); -- Get the next integer
if j /= stimulus'right then
-- it's not the last item; skip the next comma
read(L, c);
assert c = ',' report "Oops, bad separator";
end if;
stimulus(j) <= std_logic_vector(
to_unsigned(i, slv10'length));
end loop;
end loop;
file_close(StimCSV);
wait for 20 ns;
wait;
end process;
end;