2 <block_impl ref_name="read_csv.xml" ref_md5="">
4 <author lastname="Domas" mail="sdomas@univ-fcomte.fr" firstname="stephane"/>
5 <log creation="2018-05-02">
12 <package name="std_logic_1164" use="all"/>
13 <package name="numeric_std" use="all"/>
16 <package name="textio" use="all"/>
21 file in_data : text open read_mode is in_file; -- the file to read
22 signal out_s : unsigned(item_width-1 downto 0); -- signed output
24 signal new_line : std_logic := '1'; -- '1' when a new line is read just after
25 -- another one (used in read_lines)
27 signal do_read : std_logic;
28 signal line_delay_s : unsigned(15 downto 0);
29 signal group_delay_s : unsigned(15 downto 0);
34 line_delay_s <= to_unsigned(line_delay-1, 16);
35 group_delay_s <= to_unsigned(group_delay-1, 16);
37 @{out_val} <= std_logic_vector(out_s);
39 read_data : process(@{reset}, @{clk})
42 variable in_val : integer;
43 variable comma : character;
44 variable item_count : integer;
45 variable line_count : integer; -- to count lines until the last is reached
46 variable last_line : std_logic;
47 variable dly_item_count : integer;
48 variable dly_line_count : integer;
49 variable item_count_enb : std_logic := '0'; -- '1' when a delay between two
51 variable line_count_enb : std_logic := '0'; -- '1' when a delay between two
56 if (@{reset} = '1') then
59 out_s <= to_unsigned(0, item_width);
68 item_count_enb := '0';
69 line_count_enb := '0';
71 elsif rising_edge(@{clk}) then
77 if new_line = '1' then
80 line_count := line_count + 1;
81 if (endfile(in_data)) or (line_count = nb_lines) then
84 if line_delay_s > 0 then
85 line_count_enb := '1';
89 if line_count_enb = '1' then
90 dly_line_count := dly_line_count + 1;
91 if dly_line_count = line_delay_s then
92 line_count_enb := '0';
95 elsif item_count_enb = '1' then
96 dly_item_count := dly_item_count + 1;
97 if dly_item_count = group_delay_s then
98 item_count_enb := '0';
103 out_s <= to_unsigned(in_val, item_width);
105 item_count := item_count + 1;
106 if (item_count < item_per_line) then
108 if (group_delay_s > 0) and (item_count mod group_size = 0) then
109 item_count_enb := '1';
112 if (last_line = '1') then
124 elsif start_read = '1' then
125 -- reading the first line
126 readline(in_data, l);
127 line_count := line_count + 1;
128 if (endfile(in_data)) or (line_count = nb_lines) then
134 end process read_data;
136 end architecture read_csv_a;
139 <delta value="$nb_lines*$item_per_line"/>
141 <production counter="1">
142 <output name="out_val_enb" pattern="((1{$group_size}0{$group_delay-1}){($item_per_line-1)|$group_size}1{1+(($item_per_line-1)%$group_size)}0{$line_delay-1}){$nb_lines}"/>