1 |
145 |
lanttu |
-------------------------------------------------------------------------------
|
2 |
|
|
-- Title : Avalon reader
|
3 |
|
|
-- Project :
|
4 |
|
|
-------------------------------------------------------------------------------
|
5 |
|
|
-- File : avalon_reader.vhd
|
6 |
|
|
-- Author : kulmala3
|
7 |
|
|
-- Created : 22.03.2005
|
8 |
|
|
-- Last update: 2011-11-11
|
9 |
|
|
-- Description: Testbench block to model the avalon bus.
|
10 |
|
|
--
|
11 |
|
|
-- Checks that write operations are to
|
12 |
|
|
-- consecutive addresess and that data values are running numbers.
|
13 |
|
|
-- Addr mismatch is reported with output port to the tb, and data
|
14 |
|
|
-- mismatch with assert.
|
15 |
|
|
-------------------------------------------------------------------------------
|
16 |
|
|
-- Revisions :
|
17 |
|
|
-- Date Version Author Description
|
18 |
|
|
-- 22.03.2005 1.0 AK Created
|
19 |
|
|
-------------------------------------------------------------------------------
|
20 |
|
|
-------------------------------------------------------------------------------
|
21 |
|
|
-- Funbase IP library Copyright (C) 2011 TUT Department of Computer Systems
|
22 |
|
|
--
|
23 |
|
|
-- This file is part of HIBI
|
24 |
|
|
--
|
25 |
|
|
-- This source file may be used and distributed without
|
26 |
|
|
-- restriction provided that this copyright statement is not
|
27 |
|
|
-- removed from the file and that any derivative work contains
|
28 |
|
|
-- the original copyright notice and the associated disclaimer.
|
29 |
|
|
--
|
30 |
|
|
-- This source file is free software; you can redistribute it
|
31 |
|
|
-- and/or modify it under the terms of the GNU Lesser General
|
32 |
|
|
-- Public License as published by the Free Software Foundation;
|
33 |
|
|
-- either version 2.1 of the License, or (at your option) any
|
34 |
|
|
-- later version.
|
35 |
|
|
--
|
36 |
|
|
-- This source is distributed in the hope that it will be
|
37 |
|
|
-- useful, but WITHOUT ANY WARRANTY; without even the implied
|
38 |
|
|
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
39 |
|
|
-- PURPOSE. See the GNU Lesser General Public License for more
|
40 |
|
|
-- details.
|
41 |
|
|
--
|
42 |
|
|
-- You should have received a copy of the GNU Lesser General
|
43 |
|
|
-- Public License along with this source; if not, download it
|
44 |
|
|
-- from http://www.opencores.org/lgpl.shtml
|
45 |
|
|
-------------------------------------------------------------------------------
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
library ieee;
|
49 |
|
|
use ieee.std_logic_1164.all;
|
50 |
|
|
use ieee.std_logic_arith.all;
|
51 |
|
|
use ieee.std_logic_unsigned.all;
|
52 |
|
|
use std.textio.all;
|
53 |
|
|
use work.txt_util.all;
|
54 |
|
|
use work.tb_n2h2_pkg.all;
|
55 |
|
|
|
56 |
|
|
entity avalon_reader is
|
57 |
|
|
|
58 |
|
|
generic (
|
59 |
|
|
-- data_file_g : string := "";
|
60 |
|
|
addr_width_g : integer := 0;
|
61 |
|
|
data_width_g : integer
|
62 |
|
|
);
|
63 |
|
|
|
64 |
|
|
port (
|
65 |
|
|
clk : in std_logic;
|
66 |
|
|
rst_n : in std_logic;
|
67 |
|
|
avalon_we_in : in std_logic;
|
68 |
|
|
avalon_be_in : in std_logic_vector(data_width_g/8-1 downto 0);
|
69 |
|
|
avalon_writedata_in : in std_logic_vector(data_width_g-1 downto 0);
|
70 |
|
|
avalon_addr_in : in std_logic_vector(addr_width_g-1 downto 0);
|
71 |
|
|
avalon_waitrequest_out : out std_logic;
|
72 |
|
|
increment_data_ptr : in std_logic; -- hops over one data, obsolete?
|
73 |
|
|
waitrequest_real_in : in std_logic;
|
74 |
|
|
|
75 |
|
|
-- tb gets
|
76 |
|
|
not_my_addr_out : out std_logic;
|
77 |
|
|
--tb gives.
|
78 |
|
|
init_in : in std_logic;
|
79 |
|
|
my_own_addr_in : in std_logic_vector(addr_width_g-1 downto 0)
|
80 |
|
|
--my_own_addr_in : in std_logic_vector(data_width_g-1 downto 0)
|
81 |
|
|
);
|
82 |
|
|
|
83 |
|
|
end avalon_reader;
|
84 |
|
|
|
85 |
|
|
architecture rtl of avalon_reader is
|
86 |
|
|
|
87 |
|
|
constant addr_offset_c : integer := data_width_g/8; -- #bytes
|
88 |
|
|
constant assign_waitreq_c : integer := 3; -- request wait after 10 datas...
|
89 |
|
|
constant release_waitreq_c : integer := 3; -- cycles
|
90 |
|
|
|
91 |
|
|
signal addr_counter_r : std_logic_vector(addr_width_g-1 downto 0);
|
92 |
|
|
signal data_counter_r : integer;
|
93 |
|
|
signal waitreq_counter_r : integer;
|
94 |
|
|
signal release_counter_r : integer;
|
95 |
|
|
signal waitrequest_to_n2h_rx : std_logic;
|
96 |
|
|
|
97 |
|
|
constant data_fixed_width_c : integer := 32; -- bits
|
98 |
|
|
constant n_words_output_c : integer := data_width_g/ data_fixed_width_c;
|
99 |
|
|
|
100 |
|
|
begin -- rtl
|
101 |
|
|
|
102 |
|
|
avalon_waitrequest_out <= waitrequest_to_n2h_rx;
|
103 |
|
|
|
104 |
|
|
--
|
105 |
|
|
-- Drives wait_request high every now and then.
|
106 |
|
|
-- This tests that N2H2 handles the stalling correctly
|
107 |
|
|
--
|
108 |
|
|
process (clk, rst_n)
|
109 |
|
|
begin -- process
|
110 |
|
|
if rst_n = '0' then
|
111 |
|
|
waitreq_counter_r <= 0;
|
112 |
|
|
waitrequest_to_n2h_rx <= '0';
|
113 |
|
|
release_counter_r <= 0;
|
114 |
|
|
|
115 |
|
|
elsif clk'event and clk = '1' then -- rising clock edge
|
116 |
|
|
if avalon_we_in = '1' then
|
117 |
|
|
|
118 |
|
|
-- Request wait after every n-th write operation
|
119 |
|
|
if (waitreq_counter_r = assign_waitreq_c) then
|
120 |
|
|
waitreq_counter_r <= 0;
|
121 |
|
|
waitrequest_to_n2h_rx <= '1';
|
122 |
|
|
else
|
123 |
|
|
-- waitrequest_to_n2h_rx <= '0'; Keep old value instead! ES 2011-11-10
|
124 |
|
|
waitreq_counter_r <= waitreq_counter_r+1;
|
125 |
|
|
end if;
|
126 |
|
|
end if;
|
127 |
|
|
|
128 |
|
|
-- Release the wait after few cycles
|
129 |
|
|
if waitrequest_to_n2h_rx = '1' then
|
130 |
|
|
release_counter_r <= release_counter_r+1;
|
131 |
|
|
if release_counter_r >= release_waitreq_c then
|
132 |
|
|
release_counter_r <= 0;
|
133 |
|
|
waitrequest_to_n2h_rx <= '0';
|
134 |
|
|
-- assert false report "kukkuu" severity note; -- ES
|
135 |
|
|
end if;
|
136 |
|
|
end if;
|
137 |
|
|
|
138 |
|
|
end if;
|
139 |
|
|
end process;
|
140 |
|
|
|
141 |
|
|
--
|
142 |
|
|
-- Checks the values coming from N2H2 to "mem" (=here)
|
143 |
|
|
--
|
144 |
|
|
process (clk, rst_n)
|
145 |
|
|
-- file data_file : text open read_mode is data_file_g;
|
146 |
|
|
variable data_v : integer;
|
147 |
|
|
variable data_to_check_v : integer;
|
148 |
|
|
variable not_my_addr_v : integer;
|
149 |
|
|
|
150 |
|
|
begin -- process
|
151 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
152 |
|
|
addr_counter_r <= (others => '0');
|
153 |
|
|
data_counter_r <= 0;
|
154 |
|
|
not_my_addr_out <= '0';
|
155 |
|
|
data_v := 0;
|
156 |
|
|
not_my_addr_v := 0;
|
157 |
|
|
elsif clk'event and clk = '1' then -- rising clock edge
|
158 |
|
|
|
159 |
|
|
-- Synchronous clearing may be requested by tb between transfers
|
160 |
|
|
if init_in = '1' then
|
161 |
|
|
addr_counter_r <= (others => '0');
|
162 |
|
|
end if;
|
163 |
|
|
|
164 |
|
|
|
165 |
|
|
|
166 |
|
|
if avalon_we_in = '1' and waitrequest_real_in = '0' then
|
167 |
|
|
|
168 |
|
|
-- Check if incoming addr matches
|
169 |
|
|
if (addr_counter_r + my_own_addr_in) /= avalon_addr_in then
|
170 |
|
|
not_my_addr_out <= '1';
|
171 |
|
|
not_my_addr_v := 1;
|
172 |
|
|
else
|
173 |
|
|
not_my_addr_out <= '0';
|
174 |
|
|
not_my_addr_v := 0;
|
175 |
|
|
addr_counter_r <= addr_counter_r + addr_offset_c;
|
176 |
|
|
end if;
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
-- Check data if addr was ok.
|
180 |
|
|
-- Data values must be running numbers
|
181 |
|
|
if not_my_addr_v = 0 then
|
182 |
|
|
for i in 0 to n_words_output_c-1 loop
|
183 |
|
|
|
184 |
|
|
if avalon_be_in((i+1)*4-1 downto i*4) = "1111" then
|
185 |
|
|
data_to_check_v := conv_integer(avalon_writedata_in(data_fixed_width_c*(i+1)-1 downto data_fixed_width_c*i));
|
186 |
|
|
if data_v /= data_to_check_v then
|
187 |
|
|
assert false report "Data mismatch on avalon!" severity error;
|
188 |
|
|
assert false report " waited for: " & str(data_v) & ", but got: " & str(data_to_check_v) severity error;
|
189 |
|
|
else
|
190 |
|
|
assert false report "Data OK" severity note;
|
191 |
|
|
end if;
|
192 |
|
|
data_v := data_v+1;
|
193 |
|
|
else
|
194 |
|
|
assert false report "Byte enables were not 1...1" severity warning;
|
195 |
|
|
end if;
|
196 |
|
|
end loop; -- i
|
197 |
|
|
end if;
|
198 |
|
|
|
199 |
|
|
-- elsif increment_data_ptr = '1' and waitrequest_real_in = '0' and not_my_addr_v = 0 then
|
200 |
|
|
-- -- weren't actually writing, but data wre thrown away due to irq amount
|
201 |
|
|
-- -- -> update file here also
|
202 |
|
|
-- -- read_data_file (
|
203 |
|
|
-- -- data => data_v,
|
204 |
|
|
-- -- file_txt => data_file
|
205 |
|
|
-- -- );
|
206 |
|
|
-- -- ??? AK 25.06.2007
|
207 |
|
|
-- -- data_v := data_v +1;
|
208 |
|
|
end if;
|
209 |
|
|
|
210 |
|
|
end if;
|
211 |
|
|
end process;
|
212 |
|
|
|
213 |
|
|
end rtl;
|