1 |
145 |
lanttu |
-------------------------------------------------------------------------------
|
2 |
|
|
-- Title : Nios to HIBI version 2
|
3 |
|
|
-- Project :
|
4 |
|
|
-------------------------------------------------------------------------------
|
5 |
|
|
-- File : n2h2_rx_channels.vhdl
|
6 |
|
|
-- Author : kulmala3
|
7 |
|
|
-- Created : 22.03.2005
|
8 |
|
|
-- Last update: 2011-04-19
|
9 |
|
|
-- Description: This version acts as a real dma.
|
10 |
|
|
--
|
11 |
|
|
-- Currently there's no double-registers in config - the user
|
12 |
|
|
-- must take care when configuring the device. (datas can go to
|
13 |
|
|
-- wrong address etc, if configured while still receiving data from
|
14 |
|
|
-- source)
|
15 |
|
|
--
|
16 |
|
|
-- Needs 2 clock cycles to propagate the IRQ (ack->irq down-> irq req)
|
17 |
|
|
-------------------------------------------------------------------------------
|
18 |
|
|
-- Copyright (c) 2005
|
19 |
|
|
-------------------------------------------------------------------------------
|
20 |
|
|
-- Revisions :
|
21 |
|
|
-- Date Version Author Description
|
22 |
|
|
-- 22.03.2005 1.0 AK Created
|
23 |
|
|
-------------------------------------------------------------------------------
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
library ieee;
|
27 |
|
|
use ieee.std_logic_1164.all;
|
28 |
|
|
use ieee.std_logic_arith.all;
|
29 |
|
|
use ieee.std_logic_unsigned.all;
|
30 |
|
|
use ieee.std_logic_misc.all;
|
31 |
|
|
--use work.txt_util.all;
|
32 |
|
|
--use work.log2_pkg.all;
|
33 |
|
|
|
34 |
|
|
entity n2h2_rx_channels is
|
35 |
|
|
|
36 |
|
|
generic (
|
37 |
|
|
-- generic values for @£$ stupid SOPC builder -crap...
|
38 |
|
|
n_chans_g : integer := 3;
|
39 |
|
|
n_chans_bits_g : integer := 2; -- how many bits to represent n_chans
|
40 |
|
|
-- eg 2 for 4, 3 for 5, basically log2(n_chans_g)
|
41 |
|
|
|
42 |
|
|
data_width_g : integer := 1;
|
43 |
|
|
addr_width_g : integer := 1; -- the memory addr width
|
44 |
|
|
hibi_addr_cmp_hi_g : integer := 1; -- the highest bit used for comparing address
|
45 |
|
|
hibi_addr_cmp_lo_g : integer := 1; -- the lowest bit
|
46 |
|
|
amount_width_g : integer := 1); -- in bits, maximum amount of data
|
47 |
|
|
-- supposes that amount is always in 32 bit words!
|
48 |
|
|
-- (due to Nios II 32-bitness)
|
49 |
|
|
|
50 |
|
|
port (
|
51 |
|
|
clk : in std_logic;
|
52 |
|
|
rst_n : in std_logic;
|
53 |
|
|
-- avalon master (rx) if
|
54 |
|
|
avalon_addr_out : out std_logic_vector(addr_width_g-1 downto 0);
|
55 |
|
|
avalon_we_out : out std_logic;
|
56 |
|
|
avalon_be_out : out std_logic_vector(data_width_g/8-1 downto 0);
|
57 |
|
|
avalon_writedata_out : out std_logic_vector(data_width_g-1 downto 0);
|
58 |
|
|
avalon_waitrequest_in : in std_logic;
|
59 |
|
|
-- hibi if
|
60 |
|
|
hibi_data_in : in std_logic_vector(data_width_g-1 downto 0);
|
61 |
|
|
hibi_av_in : in std_logic;
|
62 |
|
|
hibi_empty_in : in std_logic;
|
63 |
|
|
hibi_comm_in : in std_logic_vector(4 downto 0);
|
64 |
|
|
hibi_re_out : out std_logic;
|
65 |
|
|
|
66 |
|
|
--avalon slave if (config)
|
67 |
|
|
--conf_bits_c bits for each channel
|
68 |
|
|
avalon_cfg_addr_in : in std_logic_vector(n_chans_bits_g+4-1 downto 0);
|
69 |
|
|
avalon_cfg_writedata_in : in std_logic_vector(addr_width_g-1 downto 0);
|
70 |
|
|
avalon_cfg_we_in : in std_logic;
|
71 |
|
|
avalon_cfg_readdata_out : out std_logic_vector(addr_width_g-1 downto 0);
|
72 |
|
|
avalon_cfg_re_in : in std_logic;
|
73 |
|
|
avalon_cfg_cs_in : in std_logic;
|
74 |
|
|
avalon_cfg_waitrequest_out : out std_logic;
|
75 |
|
|
|
76 |
|
|
rx_irq_out : out std_logic;
|
77 |
|
|
|
78 |
|
|
-- to/from tx
|
79 |
|
|
tx_start_out : out std_logic;
|
80 |
|
|
tx_comm_out : out std_logic_vector(4 downto 0);
|
81 |
|
|
tx_mem_addr_out : out std_logic_vector(addr_width_g-1 downto 0);
|
82 |
|
|
tx_hibi_addr_out : out std_logic_vector(addr_width_g-1 downto 0);
|
83 |
|
|
tx_amount_out : out std_logic_vector(amount_width_g-1 downto 0);
|
84 |
|
|
tx_status_done_in : in std_logic
|
85 |
|
|
|
86 |
|
|
);
|
87 |
|
|
|
88 |
|
|
end n2h2_rx_channels;
|
89 |
|
|
|
90 |
|
|
architecture rtl of n2h2_rx_channels is
|
91 |
|
|
|
92 |
|
|
-- NOTE!! Also have to change to interface!! avalon_cfg_addr_in !!!
|
93 |
|
|
constant conf_bits_c : integer := 4; -- number of configuration bits in CPU
|
94 |
|
|
-- side address
|
95 |
|
|
constant control_bits_c : integer := 2; -- how many bits in ctrl reg
|
96 |
|
|
constant status_bits_c : integer := 2; -- how many bits in ctrl reg
|
97 |
|
|
constant addr_offset_c : integer := data_width_g/8;
|
98 |
|
|
constant be_width_c : integer := data_width_g/8;
|
99 |
|
|
|
100 |
|
|
constant hibi_addr_width_c : integer := addr_width_g;
|
101 |
|
|
|
102 |
|
|
type chan_addr_array is array (n_chans_g-1 downto 0) of std_logic_vector(addr_width_g-1 downto 0);
|
103 |
|
|
type chan_be_array is array (n_chans_g-1 downto 0) of std_logic_vector(be_width_c-1 downto 0);
|
104 |
|
|
type chan_amount_array is array (n_chans_g-1 downto 0) of std_logic_vector(amount_width_g-1 downto 0);
|
105 |
|
|
|
106 |
|
|
-- registers the CPU will set
|
107 |
|
|
signal mem_addr_r : chan_addr_array;
|
108 |
|
|
signal sender_addr_r : chan_addr_array;
|
109 |
|
|
signal irq_amount_r : chan_amount_array;
|
110 |
|
|
signal control_r : std_logic_vector(control_bits_c-1 downto 0);
|
111 |
|
|
signal tx_mem_addr_r : std_logic_vector(addr_width_g-1 downto 0);
|
112 |
|
|
signal tx_hibi_addr_r : std_logic_vector(hibi_addr_width_c-1 downto 0);
|
113 |
|
|
signal tx_amount_r : std_logic_vector(amount_width_g-1 downto 0);
|
114 |
|
|
signal tx_comm_r : std_logic_vector(4 downto 0);
|
115 |
|
|
|
116 |
|
|
-- cpu sets, n2h clears
|
117 |
|
|
signal init_chan_r : std_logic_vector(n_chans_g-1 downto 0);
|
118 |
|
|
|
119 |
|
|
signal irq_chan_r : std_logic_vector(n_chans_g-1 downto 0);
|
120 |
|
|
signal irq_type_r : std_logic; -- 0: rx ready, 1: unknown rx
|
121 |
|
|
|
122 |
|
|
-- cpu can read
|
123 |
|
|
-- tells where the next data is stored
|
124 |
|
|
signal current_mem_addr_r : chan_addr_array;
|
125 |
|
|
signal current_be_r : chan_be_array;
|
126 |
|
|
signal avalon_be_r : std_logic_vector(be_width_c-1 downto 0);
|
127 |
|
|
|
128 |
|
|
signal status_r : std_logic_vector(status_bits_c-1 downto 0);
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
-- counter of how many datas gotten (irq nullifies)
|
132 |
|
|
signal irq_counter_r : chan_amount_array;
|
133 |
|
|
signal irq_r : std_logic;
|
134 |
|
|
signal irq_given_r : std_logic_vector(n_chans_g-1 downto 0);
|
135 |
|
|
signal irq_reset_r : std_logic; -- irq was reseted last cycle
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
signal hibi_re_r : std_logic;
|
139 |
|
|
signal avalon_we_r : std_logic;
|
140 |
|
|
|
141 |
|
|
signal unknown_rx : std_logic; -- high when not expecting this rx
|
142 |
|
|
signal unknown_rx_irq_r : std_logic;
|
143 |
|
|
signal unknown_rx_r : std_logic;
|
144 |
|
|
|
145 |
|
|
-- high when tx is overriding previous one
|
146 |
|
|
-- (user didn't poll if previous tx is still in progress)
|
147 |
|
|
signal tx_illegal : std_logic;
|
148 |
|
|
signal tx_illegal_r : std_logic;
|
149 |
|
|
signal ignore_tx_write : std_logic;
|
150 |
|
|
signal ignored_last_tx_r : std_logic;
|
151 |
|
|
|
152 |
|
|
-- calc_chan signals
|
153 |
|
|
signal avalon_addr_r : std_logic_vector(addr_width_g-1 downto 0);
|
154 |
|
|
signal curr_chan_avalon_we_r : std_logic; -- 0 if no channel found
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
component n2h2_rx_chan
|
158 |
|
|
generic (
|
159 |
|
|
data_width_g : integer := 0;
|
160 |
|
|
hibi_addr_width_g : integer := 0;
|
161 |
|
|
addr_width_g : integer;
|
162 |
|
|
amount_width_g : integer;
|
163 |
|
|
addr_cmp_lo_g : integer;
|
164 |
|
|
addr_cmp_hi_g : integer);
|
165 |
|
|
port (
|
166 |
|
|
clk : in std_logic;
|
167 |
|
|
rst_n : in std_logic;
|
168 |
|
|
avalon_addr_in : in std_logic_vector(addr_width_g-1 downto 0);
|
169 |
|
|
hibi_addr_in : in std_logic_vector(hibi_addr_width_g-1 downto 0);
|
170 |
|
|
irq_amount_in : in std_logic_vector(amount_width_g-1 downto 0);
|
171 |
|
|
hibi_data_in : in std_logic_vector(hibi_addr_width_g-1 downto 0);
|
172 |
|
|
hibi_av_in : in std_logic;
|
173 |
|
|
hibi_empty_in : in std_logic;
|
174 |
|
|
init_in : in std_logic;
|
175 |
|
|
irq_ack_in : in std_logic;
|
176 |
|
|
avalon_waitreq_in : in std_logic;
|
177 |
|
|
avalon_we_in : in std_logic;
|
178 |
|
|
avalon_addr_out : out std_logic_vector(addr_width_g-1 downto 0);
|
179 |
|
|
avalon_we_out : out std_logic;
|
180 |
|
|
avalon_be_out : out std_logic_vector(data_width_g/8-1 downto 0);
|
181 |
|
|
addr_match_out : out std_logic;
|
182 |
|
|
addr_match_cmb_out : out std_logic;
|
183 |
|
|
irq_out : out std_logic);
|
184 |
|
|
end component;
|
185 |
|
|
-- signal irq_amount_r : chan_amount_array;
|
186 |
|
|
signal avalon_wes : std_logic_vector(n_chans_g-1 downto 0);
|
187 |
|
|
signal matches : std_logic_vector(n_chans_g-1 downto 0);
|
188 |
|
|
signal matches_cmb : std_logic_vector(n_chans_g-1 downto 0);
|
189 |
|
|
signal irq_ack_r : std_logic_vector(n_chans_g-1 downto 0);
|
190 |
|
|
|
191 |
|
|
component one_hot_mux
|
192 |
|
|
generic (
|
193 |
|
|
data_width_g : integer);
|
194 |
|
|
port (
|
195 |
|
|
data_in : in std_logic_vector(data_width_g-1 downto 0);
|
196 |
|
|
sel_in : in std_logic_vector(data_width_g-1 downto 0);
|
197 |
|
|
data_out : out std_logic);
|
198 |
|
|
end component;
|
199 |
|
|
|
200 |
|
|
type chan_addr_switched is array (addr_width_g-1 downto 0) of std_logic_vector(n_chans_g-1 downto 0);
|
201 |
|
|
type chan_be_switched is array (be_width_c-1 downto 0) of std_logic_vector(n_chans_g-1 downto 0);
|
202 |
|
|
|
203 |
|
|
signal avalon_addr_temp : chan_addr_switched;
|
204 |
|
|
signal avalon_be_temp : chan_be_switched;
|
205 |
|
|
|
206 |
|
|
|
207 |
|
|
signal avalon_cfg_waitrequest_out_r : std_logic;
|
208 |
|
|
signal avalon_cfg_waitrequest_out_s : std_logic;
|
209 |
|
|
|
210 |
|
|
signal cfg_write : std_logic;
|
211 |
|
|
signal cfg_reg : integer range (2**conf_bits_c)-1 downto 0;
|
212 |
|
|
|
213 |
|
|
-- high when tx conf registers (8-11) are being written
|
214 |
|
|
signal cfg_tx_reg_used : std_logic;
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
begin -- rtl
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
-----------------------------------------------------------------------------
|
221 |
|
|
-- Handle waitrequest for config interface
|
222 |
|
|
-----------------------------------------------------------------------------
|
223 |
|
|
|
224 |
|
|
avalon_cfg_waitrequest_out <= avalon_cfg_waitrequest_out_s;
|
225 |
|
|
|
226 |
|
|
cfg_write <= avalon_cfg_we_in and avalon_cfg_cs_in;
|
227 |
|
|
|
228 |
|
|
avalon_cfg_waitrequest_out_s <= ((not avalon_cfg_waitrequest_out_r)
|
229 |
|
|
and avalon_cfg_re_in
|
230 |
|
|
and avalon_cfg_cs_in);
|
231 |
|
|
|
232 |
|
|
wait_p : process (clk, rst_n)
|
233 |
|
|
begin -- process wait_p
|
234 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
235 |
|
|
avalon_cfg_waitrequest_out_r <= '0';
|
236 |
|
|
elsif clk'event and clk = '1' then -- rising clock edge
|
237 |
|
|
avalon_cfg_waitrequest_out_r <= avalon_cfg_waitrequest_out_s;
|
238 |
|
|
end if;
|
239 |
|
|
end process wait_p;
|
240 |
|
|
|
241 |
|
|
-----------------------------------------------------------------------------
|
242 |
|
|
-- Handle txs, dismiss tx if previous one is still in progress
|
243 |
|
|
-----------------------------------------------------------------------------
|
244 |
|
|
|
245 |
|
|
cfg_reg <= conv_integer(avalon_cfg_addr_in(conf_bits_c-1 downto 0));
|
246 |
|
|
|
247 |
|
|
cfg_tx_p: process (cfg_reg)
|
248 |
|
|
begin -- process cfg_tx_p
|
249 |
|
|
case cfg_reg is
|
250 |
|
|
when 8 | 9 | 10 | 11 => cfg_tx_reg_used <= '1';
|
251 |
|
|
when others => cfg_tx_reg_used <= '0';
|
252 |
|
|
end case;
|
253 |
|
|
end process cfg_tx_p;
|
254 |
|
|
|
255 |
|
|
tx_illegal <= (not tx_status_done_in) and cfg_tx_reg_used and cfg_write;
|
256 |
|
|
|
257 |
|
|
tx_illegal_p: process (clk, rst_n)
|
258 |
|
|
begin -- process tx_illegal_p
|
259 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
260 |
|
|
tx_illegal_r <= '0';
|
261 |
|
|
elsif clk'event and clk = '1' then -- rising clock edge
|
262 |
|
|
if tx_illegal_r = '0' then
|
263 |
|
|
tx_illegal_r <= tx_illegal;
|
264 |
|
|
elsif tx_illegal_r = '1' and cfg_reg = 4 and cfg_tx_reg_used = '1'
|
265 |
|
|
and cfg_write = '1'
|
266 |
|
|
then
|
267 |
|
|
tx_illegal_r <= '0';
|
268 |
|
|
elsif cfg_reg = 7 and cfg_write = '1'
|
269 |
|
|
and avalon_cfg_writedata_in(data_width_g-2) = '1'
|
270 |
|
|
then
|
271 |
|
|
tx_illegal_r <= '0';
|
272 |
|
|
else
|
273 |
|
|
tx_illegal_r <= '1';
|
274 |
|
|
end if;
|
275 |
|
|
end if;
|
276 |
|
|
end process tx_illegal_p;
|
277 |
|
|
|
278 |
|
|
ignore_tx_write <= tx_illegal or tx_illegal_r;
|
279 |
|
|
|
280 |
|
|
-----------------------------------------------------------------------------
|
281 |
|
|
-- Rest of the stuff
|
282 |
|
|
-----------------------------------------------------------------------------
|
283 |
|
|
|
284 |
|
|
avalon_we_r <= hibi_empty_in nor hibi_av_in;
|
285 |
|
|
avalon_we_out <= avalon_we_r and curr_chan_avalon_we_r; -- and not_dirty_chan_we_r;
|
286 |
|
|
|
287 |
|
|
-- hibi_re_r <= (not avalon_waitrequest_in) or hibi_av_in;
|
288 |
|
|
hibi_re_r <= not (avalon_waitrequest_in and avalon_we_r
|
289 |
|
|
and curr_chan_avalon_we_r)
|
290 |
|
|
and not (unknown_rx or unknown_rx_irq_r);
|
291 |
|
|
|
292 |
|
|
unknown_rx <= (not or_reduce(matches_cmb) and
|
293 |
|
|
(hibi_av_in and not hibi_empty_in));
|
294 |
|
|
|
295 |
|
|
hibi_re_out <= hibi_re_r and not unknown_rx;
|
296 |
|
|
avalon_writedata_out <= hibi_data_in;
|
297 |
|
|
|
298 |
|
|
avalon_addr_out <= avalon_addr_r;
|
299 |
|
|
avalon_be_out <= avalon_be_r;
|
300 |
|
|
|
301 |
|
|
channels : for i in 0 to n_chans_g-1 generate
|
302 |
|
|
|
303 |
|
|
n2h2_rx_chan_1 : n2h2_rx_chan
|
304 |
|
|
generic map (
|
305 |
|
|
data_width_g => data_width_g,
|
306 |
|
|
hibi_addr_width_g => hibi_addr_width_c,
|
307 |
|
|
addr_width_g => addr_width_g,
|
308 |
|
|
amount_width_g => amount_width_g,
|
309 |
|
|
addr_cmp_lo_g => hibi_addr_cmp_lo_g,
|
310 |
|
|
addr_cmp_hi_g => hibi_addr_cmp_hi_g)
|
311 |
|
|
port map (
|
312 |
|
|
clk => clk,
|
313 |
|
|
rst_n => rst_n,
|
314 |
|
|
avalon_addr_in => mem_addr_r(i),
|
315 |
|
|
hibi_addr_in => sender_addr_r(i),
|
316 |
|
|
irq_amount_in => irq_amount_r(i),
|
317 |
|
|
hibi_data_in => hibi_data_in(hibi_addr_width_c-1 downto 0),
|
318 |
|
|
hibi_av_in => hibi_av_in,
|
319 |
|
|
hibi_empty_in => hibi_empty_in,
|
320 |
|
|
init_in => init_chan_r(i),
|
321 |
|
|
irq_ack_in => irq_ack_r(i),
|
322 |
|
|
avalon_waitreq_in => avalon_waitrequest_in,
|
323 |
|
|
avalon_we_in => avalon_we_r,
|
324 |
|
|
avalon_addr_out => current_mem_addr_r(i),
|
325 |
|
|
avalon_we_out => avalon_wes(i),
|
326 |
|
|
avalon_be_out => current_be_r(i),
|
327 |
|
|
addr_match_out => matches(i),
|
328 |
|
|
addr_match_cmb_out => matches_cmb(i),
|
329 |
|
|
irq_out => irq_chan_r(i)
|
330 |
|
|
);
|
331 |
|
|
|
332 |
|
|
end generate channels;
|
333 |
|
|
|
334 |
|
|
one_hot_mux_1 : one_hot_mux
|
335 |
|
|
generic map (
|
336 |
|
|
data_width_g => n_chans_g)
|
337 |
|
|
port map (
|
338 |
|
|
data_in => avalon_wes,
|
339 |
|
|
sel_in => matches,
|
340 |
|
|
data_out => curr_chan_avalon_we_r
|
341 |
|
|
);
|
342 |
|
|
|
343 |
|
|
|
344 |
|
|
ava_temp : for i in 0 to n_chans_g-1 generate
|
345 |
|
|
j : for j in 0 to addr_width_g-1 generate
|
346 |
|
|
avalon_addr_temp(j)(i) <= current_mem_addr_r(i)(j);
|
347 |
|
|
end generate j;
|
348 |
|
|
|
349 |
|
|
k : for k in 0 to be_width_c-1 generate
|
350 |
|
|
avalon_be_temp(k)(i) <= current_be_r(i)(k);
|
351 |
|
|
end generate k;
|
352 |
|
|
end generate ava_temp;
|
353 |
|
|
|
354 |
|
|
|
355 |
|
|
avalon_address : for i in 0 to addr_width_g-1 generate
|
356 |
|
|
one_hot_mux_addr_i : one_hot_mux
|
357 |
|
|
generic map (
|
358 |
|
|
data_width_g => n_chans_g)
|
359 |
|
|
port map (
|
360 |
|
|
data_in => avalon_addr_temp(i),
|
361 |
|
|
sel_in => matches,
|
362 |
|
|
data_out => avalon_addr_r(i)
|
363 |
|
|
);
|
364 |
|
|
end generate avalon_address;
|
365 |
|
|
|
366 |
|
|
|
367 |
|
|
be : for i in 0 to be_width_c-1 generate
|
368 |
|
|
one_hot_mux_be_i : one_hot_mux
|
369 |
|
|
generic map (
|
370 |
|
|
data_width_g => n_chans_g)
|
371 |
|
|
port map (
|
372 |
|
|
data_in => avalon_be_temp(i),
|
373 |
|
|
sel_in => matches,
|
374 |
|
|
data_out => avalon_be_r(i)
|
375 |
|
|
);
|
376 |
|
|
end generate be;
|
377 |
|
|
|
378 |
|
|
|
379 |
|
|
cpu_side : process (clk, rst_n)
|
380 |
|
|
variable legal_write : std_logic;
|
381 |
|
|
variable legal_read : std_logic;
|
382 |
|
|
variable n_chan : integer range n_chans_g-1 downto 0;
|
383 |
|
|
variable n_dest : integer range (2**conf_bits_c)-1 downto 0;
|
384 |
|
|
begin -- process cpu
|
385 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
386 |
|
|
for i in n_chans_g-1 downto 0 loop
|
387 |
|
|
mem_addr_r(i) <= (others => '0');
|
388 |
|
|
sender_addr_r(i) <= (others => '0');
|
389 |
|
|
irq_amount_r(i) <= (others => '1');
|
390 |
|
|
end loop; -- i
|
391 |
|
|
avalon_cfg_readdata_out <= (others => '0');
|
392 |
|
|
init_chan_r <= (others => '0');
|
393 |
|
|
control_r <= (others => '0');
|
394 |
|
|
-- status for only rx signals..
|
395 |
|
|
status_r(1) <= '0';
|
396 |
|
|
-- status_r(1) <= '0';
|
397 |
|
|
-- status_r <= (others => '0');
|
398 |
|
|
-- irq_chan_r <= (others => '0');
|
399 |
|
|
tx_mem_addr_r <= (others => '0');
|
400 |
|
|
tx_comm_r <= (others => '0');
|
401 |
|
|
tx_amount_r <= (others => '0');
|
402 |
|
|
rx_irq_out <= '0';
|
403 |
|
|
irq_reset_r <= '0';
|
404 |
|
|
unknown_rx_irq_r <= '0';
|
405 |
|
|
unknown_rx_r <= '0';
|
406 |
|
|
ignored_last_tx_r <= '0';
|
407 |
|
|
|
408 |
|
|
elsif clk'event and clk = '1' then -- rising clock edge
|
409 |
|
|
|
410 |
|
|
unknown_rx_r <= unknown_rx;
|
411 |
|
|
|
412 |
|
|
if unknown_rx = '1' and unknown_rx_r = '0' then
|
413 |
|
|
unknown_rx_irq_r <= '1';
|
414 |
|
|
end if;
|
415 |
|
|
|
416 |
|
|
|
417 |
|
|
-- set the IRQ. may be changed below if some IRQ
|
418 |
|
|
-- is cleared and others are pending.
|
419 |
|
|
if unknown_rx_irq_r = '1' or ignored_last_tx_r = '1' or
|
420 |
|
|
(irq_chan_r /= 0 and irq_reset_r = '0') then
|
421 |
|
|
-- irq ena bit...
|
422 |
|
|
rx_irq_out <= control_r(1);
|
423 |
|
|
end if;
|
424 |
|
|
|
425 |
|
|
irq_reset_r <= '0'; -- default
|
426 |
|
|
|
427 |
|
|
control_r(0) <= '0';
|
428 |
|
|
-- nullifies the tx start after CPU has set it
|
429 |
|
|
-- otherwise CPU can't keep up with N2H2 with small transfers
|
430 |
|
|
|
431 |
|
|
irq_ack_r <= (others => '0');
|
432 |
|
|
|
433 |
|
|
legal_write := avalon_cfg_cs_in and avalon_cfg_we_in;
|
434 |
|
|
legal_read := avalon_cfg_cs_in and avalon_cfg_re_in;
|
435 |
|
|
n_chan := conv_integer(avalon_cfg_addr_in(n_chans_bits_g+conf_bits_c-1 downto conf_bits_c));
|
436 |
|
|
n_dest := conv_integer(avalon_cfg_addr_in(conf_bits_c-1 downto 0));
|
437 |
|
|
|
438 |
|
|
if legal_write = '1' then
|
439 |
|
|
case n_dest is
|
440 |
|
|
when 0 => -- mem_addr
|
441 |
|
|
mem_addr_r(n_chan) <= avalon_cfg_writedata_in;
|
442 |
|
|
when 1 => -- sender addr
|
443 |
|
|
sender_addr_r(n_chan) <= avalon_cfg_writedata_in;
|
444 |
|
|
when 2 => -- irq_amount
|
445 |
|
|
irq_amount_r(n_chan) <=
|
446 |
|
|
avalon_cfg_writedata_in(amount_width_g-1 downto 0);
|
447 |
|
|
-- 3 is unwritable, curr addr ptr
|
448 |
|
|
when 4 => -- control
|
449 |
|
|
if ignore_tx_write = '0' then
|
450 |
|
|
control_r <= avalon_cfg_writedata_in(control_bits_c-1 downto 0);
|
451 |
|
|
end if;
|
452 |
|
|
|
453 |
|
|
-- remember wether a tx gets lost or not
|
454 |
|
|
if ignore_tx_write = '1' then
|
455 |
|
|
ignored_last_tx_r <= '1';
|
456 |
|
|
else
|
457 |
|
|
ignored_last_tx_r <= ignored_last_tx_r;
|
458 |
|
|
end if;
|
459 |
|
|
|
460 |
|
|
when 5 => -- init channel
|
461 |
|
|
init_chan_r <= avalon_cfg_writedata_in(n_chans_g-1 downto 0);
|
462 |
|
|
when 7 => -- IRQ chan
|
463 |
|
|
|
464 |
|
|
-- goes down so that generates an edge
|
465 |
|
|
-- when many interrupts are pending.
|
466 |
|
|
rx_irq_out <= '0';
|
467 |
|
|
irq_reset_r <= '1';
|
468 |
|
|
|
469 |
|
|
irq_ack_r <= avalon_cfg_writedata_in(n_chans_g-1 downto 0);
|
470 |
|
|
|
471 |
|
|
if avalon_cfg_writedata_in(data_width_g-1) = '1' then
|
472 |
|
|
unknown_rx_irq_r <= '0';
|
473 |
|
|
end if;
|
474 |
|
|
|
475 |
|
|
if avalon_cfg_writedata_in(data_width_g-2) = '1' then
|
476 |
|
|
ignored_last_tx_r <= '0';
|
477 |
|
|
end if;
|
478 |
|
|
|
479 |
|
|
|
480 |
|
|
-- NOW TX SIGNALS
|
481 |
|
|
when 8 =>
|
482 |
|
|
if avalon_cfg_waitrequest_out_s = '0' and ignore_tx_write = '0' then
|
483 |
|
|
tx_mem_addr_r <= avalon_cfg_writedata_in;
|
484 |
|
|
end if;
|
485 |
|
|
when 9 =>
|
486 |
|
|
if avalon_cfg_waitrequest_out_s = '0' and ignore_tx_write = '0' then
|
487 |
|
|
tx_amount_r <= avalon_cfg_writedata_in(amount_width_g-1 downto 0);
|
488 |
|
|
end if;
|
489 |
|
|
when 10 =>
|
490 |
|
|
if avalon_cfg_waitrequest_out_s = '0' and ignore_tx_write = '0' then
|
491 |
|
|
tx_comm_r <= avalon_cfg_writedata_in(4 downto 0);
|
492 |
|
|
end if;
|
493 |
|
|
when 11 =>
|
494 |
|
|
if avalon_cfg_waitrequest_out_s = '0' and ignore_tx_write = '0' then
|
495 |
|
|
tx_hibi_addr_r <= avalon_cfg_writedata_in;
|
496 |
|
|
end if;
|
497 |
|
|
when others =>
|
498 |
|
|
|
499 |
|
|
-- do nothing
|
500 |
|
|
|
501 |
|
|
end case;
|
502 |
|
|
end if;
|
503 |
|
|
|
504 |
|
|
if legal_read = '1' then
|
505 |
|
|
case n_dest is
|
506 |
|
|
when 0 => -- mem_addr
|
507 |
|
|
avalon_cfg_readdata_out <= mem_addr_r(n_chan);
|
508 |
|
|
when 1 => -- sender addr
|
509 |
|
|
avalon_cfg_readdata_out <= sender_addr_r(n_chan);
|
510 |
|
|
when 2 => -- irq amount
|
511 |
|
|
avalon_cfg_readdata_out(addr_width_g-1 downto amount_width_g) <= (others => '0');
|
512 |
|
|
avalon_cfg_readdata_out(amount_width_g-1 downto 0) <= irq_amount_r(n_chan);
|
513 |
|
|
when 3 => -- current addr ptr
|
514 |
|
|
avalon_cfg_readdata_out <= current_mem_addr_r(n_chan);
|
515 |
|
|
when 4 => -- control and status regs
|
516 |
|
|
avalon_cfg_readdata_out(15 downto control_bits_c) <= (others => '0');
|
517 |
|
|
avalon_cfg_readdata_out(control_bits_c-1 downto 0) <= control_r;
|
518 |
|
|
avalon_cfg_readdata_out(31 downto status_bits_c+15) <= (others => '0');
|
519 |
|
|
avalon_cfg_readdata_out(status_bits_c+15 downto 16) <= status_r;
|
520 |
|
|
when 5 => -- Init Channel
|
521 |
|
|
avalon_cfg_readdata_out(addr_width_g-1 downto n_chans_g) <= (others => '0');
|
522 |
|
|
avalon_cfg_readdata_out(n_chans_g-1 downto 0) <= init_chan_r;
|
523 |
|
|
-- 6 is reserved
|
524 |
|
|
when 7 => -- IRQ chan
|
525 |
|
|
avalon_cfg_readdata_out(addr_width_g-1) <= unknown_rx_irq_r;
|
526 |
|
|
avalon_cfg_readdata_out(addr_width_g-2) <= ignored_last_tx_r;
|
527 |
|
|
avalon_cfg_readdata_out(addr_width_g-3 downto n_chans_g) <= (others => '0');
|
528 |
|
|
avalon_cfg_readdata_out(n_chans_g-1 downto 0) <= irq_chan_r;
|
529 |
|
|
|
530 |
|
|
when 12 =>
|
531 |
|
|
|
532 |
|
|
avalon_cfg_readdata_out(31 downto 0) <= hibi_data_in;
|
533 |
|
|
|
534 |
|
|
when others =>
|
535 |
|
|
-- do nothing;
|
536 |
|
|
end case;
|
537 |
|
|
end if;
|
538 |
|
|
|
539 |
|
|
-- status reg
|
540 |
|
|
--status_r <= status_r;
|
541 |
|
|
-- busy bit
|
542 |
|
|
status_r(1) <= avalon_we_r;
|
543 |
|
|
|
544 |
|
|
if init_chan_r /= conv_std_logic_vector(0, n_chans_g) then
|
545 |
|
|
init_chan_r <= (others => '0');
|
546 |
|
|
end if;
|
547 |
|
|
|
548 |
|
|
-- -- irq req
|
549 |
|
|
-- if irq_r = '1' then
|
550 |
|
|
-- irq_chan_r(curr_chan_r) <= '1';
|
551 |
|
|
-- end if;
|
552 |
|
|
|
553 |
|
|
|
554 |
|
|
end if;
|
555 |
|
|
end process cpu_side;
|
556 |
|
|
|
557 |
|
|
|
558 |
|
|
|
559 |
|
|
|
560 |
|
|
-- tx signals
|
561 |
|
|
-- done bit, start tx
|
562 |
|
|
status_r(0) <= tx_status_done_in;
|
563 |
|
|
tx_amount_out <= tx_amount_r;
|
564 |
|
|
tx_mem_addr_out <= tx_mem_addr_r;
|
565 |
|
|
tx_comm_out <= tx_comm_r;
|
566 |
|
|
tx_hibi_addr_out <= tx_hibi_addr_r;
|
567 |
|
|
|
568 |
|
|
tx_start : process (clk, rst_n)
|
569 |
|
|
variable was_high_r : std_logic;
|
570 |
|
|
begin -- process sel_tx_start
|
571 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
572 |
|
|
was_high_r := '0';
|
573 |
|
|
tx_start_out <= '0';
|
574 |
|
|
|
575 |
|
|
elsif clk'event and clk = '1' then -- rising clock edge
|
576 |
|
|
if control_r(0) = '1' then
|
577 |
|
|
if was_high_r = '0' then
|
578 |
|
|
was_high_r := '1';
|
579 |
|
|
tx_start_out <= '1';
|
580 |
|
|
else
|
581 |
|
|
was_high_r := '1';
|
582 |
|
|
tx_start_out <= '0';
|
583 |
|
|
end if;
|
584 |
|
|
else
|
585 |
|
|
was_high_r := '0';
|
586 |
|
|
tx_start_out <= '0';
|
587 |
|
|
end if;
|
588 |
|
|
end if;
|
589 |
|
|
end process tx_start;
|
590 |
|
|
|
591 |
|
|
end rtl;
|
592 |
|
|
|