1 |
14 |
nussgipfel |
-- GECKO3COM IP Core
|
2 |
|
|
--
|
3 |
23 |
nussgipfel |
-- Copyright (C) 2010 by
|
4 |
14 |
nussgipfel |
-- ___ ___ _ _
|
5 |
|
|
-- ( _ \ ( __)( ) ( )
|
6 |
|
|
-- | (_) )| ( | |_| | Bern University of Applied Sciences
|
7 |
|
|
-- | _ < | _) | _ | School of Engineering and
|
8 |
|
|
-- | (_) )| | | | | | Information Technology
|
9 |
|
|
-- (____/ (_) (_) (_)
|
10 |
|
|
--
|
11 |
|
|
-- This program is free software: you can redistribute it and/or modify
|
12 |
|
|
-- it under the terms of the GNU General Public License as published by
|
13 |
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
14 |
|
|
-- (at your option) any later version.
|
15 |
|
|
--
|
16 |
|
|
-- This program is distributed in the hope that it will be useful,
|
17 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
|
|
-- GNU General Public License for more details.
|
20 |
|
|
-- You should have received a copy of the GNU General Public License
|
21 |
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
22 |
|
|
--
|
23 |
|
|
-- URL to the project description:
|
24 |
|
|
-- http://labs.ti.bfh.ch/gecko/wiki/systems/gecko3com/start
|
25 |
23 |
nussgipfel |
--------------------------------------------------------------------------------
|
26 |
14 |
nussgipfel |
--
|
27 |
|
|
-- Author: Andreas Habegger, Christoph Zimmermann
|
28 |
23 |
nussgipfel |
-- Date of creation: 11. February 2010
|
29 |
14 |
nussgipfel |
-- Description:
|
30 |
23 |
nussgipfel |
-- Test scenario for the GECKO3com simple IP core.
|
31 |
|
|
-- (Not the one for Xilinx EDK)
|
32 |
|
|
-- This test module has two operation mode (selectable by external switch):
|
33 |
|
|
-- - Send back a response message stored in rom
|
34 |
25 |
nussgipfel |
-- - Send back a stream of pseudo random data. Size is defined as a
|
35 |
|
|
-- constant (currently 1 MiB)
|
36 |
14 |
nussgipfel |
--
|
37 |
|
|
-- Target Devices: general
|
38 |
|
|
-- Tool versions: 11.1
|
39 |
|
|
-- Dependencies:
|
40 |
|
|
--
|
41 |
23 |
nussgipfel |
--------------------------------------------------------------------------------
|
42 |
14 |
nussgipfel |
|
43 |
11 |
nussgipfel |
library ieee;
|
44 |
|
|
use ieee.std_logic_1164.all;
|
45 |
24 |
nussgipfel |
use ieee.std_logic_unsigned.all;
|
46 |
11 |
nussgipfel |
|
47 |
|
|
library work;
|
48 |
14 |
nussgipfel |
use work.GECKO3COM_defines.all;
|
49 |
11 |
nussgipfel |
|
50 |
24 |
nussgipfel |
|
51 |
23 |
nussgipfel |
entity GECKO3COM_simple_test is
|
52 |
11 |
nussgipfel |
port (
|
53 |
23 |
nussgipfel |
i_nReset : in std_logic;
|
54 |
|
|
i_sysclk : in std_logic; -- FPGA System CLK
|
55 |
|
|
-- Interface signals to the EZ-USB FX2
|
56 |
|
|
i_IFCLK : in std_logic; -- GPIF CLK
|
57 |
|
|
i_WRU : in std_logic; -- write from GPIF
|
58 |
|
|
i_RDYU : in std_logic; -- GPIF is ready
|
59 |
|
|
o_WRX : out std_logic; -- To write to GPIF
|
60 |
|
|
o_RDYX : out std_logic; -- IP Core is ready
|
61 |
|
|
-- bidirect data bus
|
62 |
24 |
nussgipfel |
b_gpif_bus : inout std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
|
63 |
23 |
nussgipfel |
-- simple test "user interface" signals
|
64 |
|
|
o_LEDrx : out std_logic; -- controll LED receive data
|
65 |
|
|
o_LEDtx : out std_logic; -- controll LED send data
|
66 |
|
|
o_LEDrun : out std_logic; -- power LED
|
67 |
26 |
nussgipfel |
o_dummy : out std_logic; -- dummy output for otherwise unused signals
|
68 |
23 |
nussgipfel |
i_mode_switch : in std_logic_vector(2 downto 0));
|
69 |
|
|
end GECKO3COM_simple_test;
|
70 |
11 |
nussgipfel |
|
71 |
|
|
|
72 |
|
|
|
73 |
23 |
nussgipfel |
architecture behavour of GECKO3COM_simple_test is
|
74 |
11 |
nussgipfel |
|
75 |
23 |
nussgipfel |
-----------------------------------------------------------------------------
|
76 |
|
|
-- CONSTANTS
|
77 |
|
|
-----------------------------------------------------------------------------
|
78 |
|
|
constant BUSWIDTH : integer := 32; -- you can choose here 32 or 16
|
79 |
|
|
|
80 |
|
|
-- lenght of the message stored in the response message rom:
|
81 |
24 |
nussgipfel |
signal c_transfer_size_rom : std_logic_vector(31 downto 0) := x"0000000E";
|
82 |
23 |
nussgipfel |
|
83 |
|
|
-- we will transmitt 1 MiB data when the pseude random number generator
|
84 |
|
|
-- is used:
|
85 |
26 |
nussgipfel |
--signal c_transfer_size_prng : std_logic_vector(31 downto 0) := x"00100000";
|
86 |
28 |
nussgipfel |
signal c_transfer_size_prng : std_logic_vector(31 downto 0) := x"00000001";
|
87 |
23 |
nussgipfel |
|
88 |
11 |
nussgipfel |
|
89 |
23 |
nussgipfel |
-----------------------------------------------------------------------------
|
90 |
|
|
-- COMPONENTS
|
91 |
|
|
-----------------------------------------------------------------------------
|
92 |
|
|
component GECKO3COM_simple
|
93 |
|
|
generic (
|
94 |
|
|
BUSWIDTH : integer);
|
95 |
|
|
port (
|
96 |
|
|
i_nReset : in std_logic;
|
97 |
|
|
i_sysclk : in std_logic;
|
98 |
|
|
i_receive_fifo_rd_en : in std_logic;
|
99 |
|
|
o_receive_fifo_empty : out std_logic;
|
100 |
|
|
o_receive_fifo_data : out std_logic_vector(BUSWIDTH-1 downto 0);
|
101 |
|
|
o_receive_transfersize : out std_logic_vector(31 downto 0);
|
102 |
|
|
o_receive_end_of_message : out std_logic;
|
103 |
|
|
o_receive_newdata : out std_logic;
|
104 |
|
|
i_send_fifo_wr_en : in std_logic;
|
105 |
|
|
o_send_fifo_full : out std_logic;
|
106 |
|
|
i_send_fifo_data : in std_logic_vector(BUSWIDTH-1 downto 0);
|
107 |
|
|
i_send_transfersize : in std_logic_vector(31 downto 0);
|
108 |
|
|
i_send_transfersize_en : in std_logic;
|
109 |
|
|
i_send_have_more_data : in std_logic;
|
110 |
|
|
o_send_data_request : out std_logic;
|
111 |
|
|
o_send_finished : out std_logic;
|
112 |
|
|
o_rx : out std_logic;
|
113 |
|
|
o_tx : out std_logic;
|
114 |
|
|
i_IFCLK : in std_logic;
|
115 |
|
|
i_WRU : in std_logic;
|
116 |
|
|
i_RDYU : in std_logic;
|
117 |
|
|
o_WRX : out std_logic;
|
118 |
|
|
o_RDYX : out std_logic;
|
119 |
|
|
b_gpif_bus : inout std_logic_vector(SIZE_DBUS_GPIF-1 downto 0));
|
120 |
|
|
end component;
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
component response_message_rom
|
124 |
|
|
port (
|
125 |
|
|
A : in std_logic_vector(3 downto 0);
|
126 |
|
|
D : out std_logic_vector(31 downto 0));
|
127 |
|
|
end component;
|
128 |
11 |
nussgipfel |
|
129 |
23 |
nussgipfel |
-----------------------------------------------------------------------------
|
130 |
|
|
-- interconection signals
|
131 |
|
|
-----------------------------------------------------------------------------
|
132 |
11 |
nussgipfel |
|
133 |
23 |
nussgipfel |
signal s_receive_fifo_rd_en : std_logic;
|
134 |
|
|
signal s_receive_fifo_empty : std_logic;
|
135 |
|
|
signal s_receive_fifo_data : std_logic_vector(BUSWIDTH-1 downto 0);
|
136 |
|
|
signal s_receive_transfersize : std_logic_vector(31 downto 0);
|
137 |
|
|
signal s_receive_end_of_message : std_logic;
|
138 |
|
|
signal s_receive_newdata : std_logic;
|
139 |
|
|
signal s_send_fifo_wr_en : std_logic;
|
140 |
|
|
signal s_send_fifo_full : std_logic;
|
141 |
|
|
signal s_send_fifo_data : std_logic_vector(BUSWIDTH-1 downto 0);
|
142 |
|
|
signal s_send_transfersize : std_logic_vector(31 downto 0);
|
143 |
|
|
signal s_send_transfersize_en : std_logic;
|
144 |
|
|
signal s_send_have_more_data : std_logic;
|
145 |
|
|
signal s_send_data_request : std_logic;
|
146 |
|
|
signal s_send_finished : std_logic;
|
147 |
|
|
|
148 |
|
|
signal s_mode : std_logic_vector(1 downto 0);
|
149 |
|
|
signal s_transfer_size_reg_select : std_logic;
|
150 |
|
|
signal s_transfer_size_reg_en : std_logic;
|
151 |
|
|
signal s_send_counter_reset : std_logic;
|
152 |
|
|
signal s_send_counter_en : std_logic;
|
153 |
|
|
signal s_send_counter_equals_transfer_size : std_logic;
|
154 |
|
|
signal s_prng_en : std_logic;
|
155 |
|
|
signal s_prng_feedback : std_logic;
|
156 |
|
|
signal s_receive_data_error : std_logic;
|
157 |
|
|
|
158 |
|
|
signal s_receive_data_old : std_logic_vector(31 downto 0);
|
159 |
|
|
signal s_selected_transfer_size : std_logic_vector(31 downto 0);
|
160 |
|
|
signal s_remaining_transfer_size : std_logic_vector(31 downto 0);
|
161 |
24 |
nussgipfel |
signal s_subtract_value : std_logic_vector(31 downto 0);
|
162 |
23 |
nussgipfel |
signal s_send_counter_value : std_logic_vector(31 downto 0);
|
163 |
|
|
signal s_prng_data : std_logic_vector(31 downto 0);
|
164 |
|
|
signal s_message_rom_data : std_logic_vector(31 downto 0);
|
165 |
|
|
|
166 |
24 |
nussgipfel |
|
167 |
11 |
nussgipfel |
-----------------------------------------------------------------------------
|
168 |
23 |
nussgipfel |
-- finite state machine signals
|
169 |
11 |
nussgipfel |
-----------------------------------------------------------------------------
|
170 |
23 |
nussgipfel |
-- XST specific synthesize attributes
|
171 |
|
|
attribute safe_implementation: string;
|
172 |
|
|
attribute safe_recovery_state: string;
|
173 |
11 |
nussgipfel |
|
174 |
23 |
nussgipfel |
type t_fsmState is (st1_idle, st2_get_data, st3_load_total_transfer_size,
|
175 |
|
|
st4_save_remaining_transfer_size, st5_send_data,
|
176 |
|
|
st6_send_wait, st7_subtract_transfered_data,
|
177 |
|
|
st8_reset_send_counter);
|
178 |
11 |
nussgipfel |
|
179 |
23 |
nussgipfel |
signal state, next_state : t_fsmState;
|
180 |
|
|
|
181 |
|
|
-- XST specific synthesize attributes
|
182 |
24 |
nussgipfel |
attribute safe_recovery_state of state : signal is "st1_idle";
|
183 |
|
|
attribute safe_implementation of state : signal is "yes";
|
184 |
14 |
nussgipfel |
|
185 |
|
|
|
186 |
11 |
nussgipfel |
|
187 |
23 |
nussgipfel |
begin -- behavour
|
188 |
11 |
nussgipfel |
|
189 |
23 |
nussgipfel |
GECKO3COM_simple_1: GECKO3COM_simple
|
190 |
|
|
generic map (
|
191 |
|
|
BUSWIDTH => BUSWIDTH)
|
192 |
|
|
port map (
|
193 |
|
|
i_nReset => i_nReset,
|
194 |
|
|
i_sysclk => i_sysclk,
|
195 |
|
|
i_receive_fifo_rd_en => s_receive_fifo_rd_en,
|
196 |
|
|
o_receive_fifo_empty => s_receive_fifo_empty,
|
197 |
|
|
o_receive_fifo_data => s_receive_fifo_data,
|
198 |
|
|
o_receive_transfersize => s_receive_transfersize,
|
199 |
|
|
o_receive_end_of_message => s_receive_end_of_message,
|
200 |
|
|
o_receive_newdata => s_receive_newdata,
|
201 |
|
|
i_send_fifo_wr_en => s_send_fifo_wr_en,
|
202 |
|
|
o_send_fifo_full => s_send_fifo_full,
|
203 |
|
|
i_send_fifo_data => s_send_fifo_data,
|
204 |
|
|
i_send_transfersize => s_send_transfersize,
|
205 |
|
|
i_send_transfersize_en => s_send_transfersize_en,
|
206 |
|
|
i_send_have_more_data => s_send_have_more_data,
|
207 |
|
|
o_send_data_request => s_send_data_request,
|
208 |
|
|
o_send_finished => s_send_finished,
|
209 |
|
|
o_rx => o_LEDrx,
|
210 |
|
|
o_tx => o_LEDtx,
|
211 |
|
|
i_IFCLK => i_IFCLK,
|
212 |
|
|
i_WRU => i_WRU,
|
213 |
|
|
i_RDYU => i_RDYU,
|
214 |
|
|
o_WRX => o_WRX,
|
215 |
|
|
o_RDYX => o_RDYX,
|
216 |
|
|
b_gpif_bus => b_gpif_bus);
|
217 |
11 |
nussgipfel |
|
218 |
|
|
|
219 |
23 |
nussgipfel |
response_message_rom_1: response_message_rom
|
220 |
|
|
port map (
|
221 |
26 |
nussgipfel |
A => s_send_counter_value(5 downto 2),
|
222 |
23 |
nussgipfel |
D => s_message_rom_data);
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
o_LEDrun <= '1';
|
226 |
|
|
|
227 |
26 |
nussgipfel |
o_dummy <= s_send_finished or s_receive_end_of_message or s_receive_newdata
|
228 |
|
|
or s_receive_data_error;
|
229 |
23 |
nussgipfel |
|
230 |
26 |
nussgipfel |
|
231 |
23 |
nussgipfel |
-- purpose: converts the mode_switch input to a binary coded value
|
232 |
|
|
-- type : combinational
|
233 |
|
|
-- inputs : i_mode_switch
|
234 |
|
|
-- outputs: s_mode
|
235 |
|
|
mode_switch_decoder: process (i_mode_switch)
|
236 |
|
|
begin -- process mode_switch_decoder
|
237 |
24 |
nussgipfel |
if i_mode_switch = "001" then
|
238 |
23 |
nussgipfel |
s_mode <= "00";
|
239 |
24 |
nussgipfel |
elsif i_mode_switch = "010" then
|
240 |
23 |
nussgipfel |
s_mode <= "01";
|
241 |
24 |
nussgipfel |
elsif i_mode_switch = "100" then
|
242 |
23 |
nussgipfel |
s_mode <= "10";
|
243 |
|
|
else
|
244 |
|
|
s_mode <= "00";
|
245 |
11 |
nussgipfel |
end if;
|
246 |
23 |
nussgipfel |
end process mode_switch_decoder;
|
247 |
11 |
nussgipfel |
|
248 |
|
|
|
249 |
|
|
-----------------------------------------------------------------------------
|
250 |
23 |
nussgipfel |
-- components needed in the send path
|
251 |
|
|
-----------------------------------------------------------------------------
|
252 |
|
|
|
253 |
|
|
-- purpose: mulitiplexer to select the send data source
|
254 |
|
|
-- type : combinational
|
255 |
|
|
-- inputs : s_mode, s_prng_data, s_message_rom_data
|
256 |
|
|
-- outputs: s_send_fifo_data
|
257 |
|
|
send_data_mux: process (s_mode, s_prng_data, s_message_rom_data)
|
258 |
|
|
begin -- process send_data_mux
|
259 |
24 |
nussgipfel |
case s_mode is
|
260 |
27 |
nussgipfel |
-- we have to change here the "16bit word order" else the data is
|
261 |
|
|
-- transmitted in the wrong order
|
262 |
|
|
when "00" => s_send_fifo_data <= s_message_rom_data(15 downto 0) &
|
263 |
|
|
s_message_rom_data(31 downto 16);
|
264 |
|
|
when "01" => s_send_fifo_data <= s_prng_data(15 downto 0) &
|
265 |
|
|
s_prng_data(31 downto 16);
|
266 |
24 |
nussgipfel |
when others => s_send_fifo_data <= (others => 'X');
|
267 |
23 |
nussgipfel |
end case;
|
268 |
|
|
end process send_data_mux;
|
269 |
11 |
nussgipfel |
|
270 |
23 |
nussgipfel |
|
271 |
|
|
-- purpose: mulitiplexer to select the send transfer size
|
272 |
|
|
-- type : combinational
|
273 |
|
|
-- inputs : s_mode, c_transfer_size_rom, c_transfer_size_prng
|
274 |
|
|
-- outputs: s_selected_transfer_size
|
275 |
|
|
send_transfersize_mode_mux: process (s_mode, c_transfer_size_rom, c_transfer_size_prng)
|
276 |
|
|
begin -- process send_transfersize_mode_mux
|
277 |
|
|
case s_mode is
|
278 |
|
|
when "00" => s_selected_transfer_size <= c_transfer_size_rom;
|
279 |
|
|
when "01" => s_selected_transfer_size <= c_transfer_size_prng;
|
280 |
24 |
nussgipfel |
when others => s_selected_transfer_size <= (others => 'X');
|
281 |
23 |
nussgipfel |
end case;
|
282 |
|
|
end process send_transfersize_mode_mux;
|
283 |
11 |
nussgipfel |
|
284 |
|
|
|
285 |
23 |
nussgipfel |
-- purpose: stores the initial or remaining transfer size
|
286 |
|
|
-- type : sequential
|
287 |
|
|
-- inputs : i_sysclk, i_nReset, s_transfer_size_reg_en, s_transfer_size_reg_select,
|
288 |
|
|
-- s_subtract_value
|
289 |
|
|
-- outputs: s_remaining_transfer_size
|
290 |
|
|
remaining_transfer_size_reg: process (i_sysclk, i_nReset)
|
291 |
|
|
begin -- process current_transfer_size_reg
|
292 |
|
|
if i_nReset = '0' then -- asynchronous reset (active low)
|
293 |
|
|
s_remaining_transfer_size <= (others => '0');
|
294 |
|
|
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
295 |
|
|
if s_transfer_size_reg_en = '1' then
|
296 |
|
|
if s_transfer_size_reg_select = '1' then
|
297 |
|
|
s_remaining_transfer_size <= s_selected_transfer_size;
|
298 |
|
|
else
|
299 |
|
|
s_remaining_transfer_size <= s_subtract_value;
|
300 |
|
|
end if;
|
301 |
|
|
end if;
|
302 |
|
|
end if;
|
303 |
24 |
nussgipfel |
end process remaining_transfer_size_reg;
|
304 |
11 |
nussgipfel |
|
305 |
23 |
nussgipfel |
|
306 |
|
|
-- maximum alowed transfer size comparator
|
307 |
24 |
nussgipfel |
s_send_have_more_data <=
|
308 |
23 |
nussgipfel |
'1' when s_remaining_transfer_size > s_receive_transfersize else
|
309 |
|
|
'0';
|
310 |
|
|
|
311 |
|
|
|
312 |
|
|
-- purpose: mulitiplexer to select the send transfer size
|
313 |
|
|
-- type : combinational
|
314 |
|
|
-- inputs : s_have_more_data, s_remaining_transfer_size,
|
315 |
|
|
-- s_receive_transfersize
|
316 |
|
|
-- outputs: s_send_transfersize
|
317 |
24 |
nussgipfel |
send_transfersize_mux: process (s_send_have_more_data, s_receive_transfersize,
|
318 |
|
|
s_remaining_transfer_size)
|
319 |
|
|
|
320 |
23 |
nussgipfel |
begin -- process send_transfersize_mux
|
321 |
24 |
nussgipfel |
case s_send_have_more_data is
|
322 |
23 |
nussgipfel |
when '0' => s_send_transfersize <= s_remaining_transfer_size;
|
323 |
24 |
nussgipfel |
when '1' => s_send_transfersize <= s_receive_transfersize;
|
324 |
|
|
when others => s_send_transfersize <= (others => 'X');
|
325 |
23 |
nussgipfel |
end case;
|
326 |
|
|
end process send_transfersize_mux;
|
327 |
|
|
|
328 |
|
|
|
329 |
|
|
-- purpose: up counter for the send transfer size
|
330 |
|
|
-- type : sequential
|
331 |
|
|
-- inputs : i_sysclk, i_nReset, s_send_counter_en, s_send_counter_reset
|
332 |
|
|
--
|
333 |
|
|
-- outputs: s_send_counter_value
|
334 |
|
|
send_counter : process (i_sysclk, i_nReset)
|
335 |
|
|
begin -- process send_counter
|
336 |
|
|
if i_nReset = '0' then -- asynchronous reset (active low)
|
337 |
|
|
s_send_counter_value <= (others => '0');
|
338 |
|
|
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
339 |
28 |
nussgipfel |
if s_send_counter_reset = '1' and s_send_counter_en = '0' then
|
340 |
23 |
nussgipfel |
s_send_counter_value <= (others => '0');
|
341 |
11 |
nussgipfel |
end if;
|
342 |
28 |
nussgipfel |
if s_send_counter_reset = '0' and s_send_counter_en = '1' then
|
343 |
26 |
nussgipfel |
s_send_counter_value(31 downto 2) <=
|
344 |
|
|
s_send_counter_value(31 downto 2) + 1;
|
345 |
|
|
s_send_counter_value(1 downto 0) <= "00"; -- every fifo write (32bit)
|
346 |
|
|
-- transfers 4 bytes.
|
347 |
23 |
nussgipfel |
end if;
|
348 |
|
|
end if;
|
349 |
|
|
end process send_counter;
|
350 |
|
|
|
351 |
|
|
-- transfer size counter comparator
|
352 |
|
|
s_send_counter_equals_transfer_size <=
|
353 |
28 |
nussgipfel |
'1' when s_send_counter_value > s_send_transfersize else
|
354 |
23 |
nussgipfel |
'0';
|
355 |
11 |
nussgipfel |
|
356 |
|
|
|
357 |
23 |
nussgipfel |
-- purpose: subracts the send counter end value from the remaining transfer size value
|
358 |
|
|
-- type : combinational
|
359 |
|
|
-- inputs : s_remaining_transfer_size, s_send_counter_value
|
360 |
|
|
-- outputs: s_subtract_value
|
361 |
|
|
transfer_size_subract: process (s_remaining_transfer_size, s_send_counter_value)
|
362 |
|
|
begin -- process transfer_size_subract
|
363 |
|
|
s_subtract_value <= s_remaining_transfer_size - s_send_counter_value;
|
364 |
|
|
end process transfer_size_subract;
|
365 |
11 |
nussgipfel |
|
366 |
23 |
nussgipfel |
|
367 |
|
|
|
368 |
|
|
-----------------------------------------------------------------------------
|
369 |
|
|
-- components needed in the receive path
|
370 |
|
|
-----------------------------------------------------------------------------
|
371 |
|
|
|
372 |
|
|
-- purpose: saves the previous received data word
|
373 |
|
|
-- type : sequential
|
374 |
|
|
-- inputs : i_sysclk, i_nReset, s_receive_fifo_data, s_receive_fifo_rd_en
|
375 |
|
|
-- outputs: s_receive_fifo_data_old
|
376 |
|
|
receive_fifo_data_reg: process (i_sysclk, i_nReset)
|
377 |
|
|
begin -- process receive_fifo_data_reg
|
378 |
|
|
if i_nReset = '0' then -- asynchronous reset (active low)
|
379 |
24 |
nussgipfel |
s_receive_data_old <= (others => '0');
|
380 |
23 |
nussgipfel |
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
381 |
|
|
if s_receive_fifo_rd_en = '1' then
|
382 |
24 |
nussgipfel |
s_receive_data_old <= s_receive_fifo_data;
|
383 |
23 |
nussgipfel |
end if;
|
384 |
|
|
end if;
|
385 |
|
|
end process receive_fifo_data_reg;
|
386 |
|
|
|
387 |
|
|
|
388 |
|
|
-- receive data comparator
|
389 |
|
|
-- (use together with test data with incrementing values)
|
390 |
|
|
s_receive_data_error <=
|
391 |
24 |
nussgipfel |
'0' when s_receive_data_old + 1 = s_receive_fifo_data else
|
392 |
23 |
nussgipfel |
'1';
|
393 |
|
|
|
394 |
|
|
|
395 |
|
|
-- purpose: linear shift register for the pseude random number
|
396 |
|
|
-- generator (PRNG)
|
397 |
|
|
-- type : sequential
|
398 |
|
|
-- inputs : i_sysclk, i_nReset, s_prng_en, s_prng_feedback
|
399 |
|
|
-- outputs: s_prng_data
|
400 |
|
|
prng_shiftregister: process (i_sysclk, i_nReset)
|
401 |
|
|
begin -- process prng_shiftregister
|
402 |
|
|
if i_nReset = '0' then -- asynchronous reset (active low)
|
403 |
24 |
nussgipfel |
s_prng_data <= "01010101010101010101010101010101";
|
404 |
23 |
nussgipfel |
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
405 |
|
|
if s_prng_en = '1' then
|
406 |
24 |
nussgipfel |
s_prng_data(31 downto 1) <= s_prng_data(30 downto 0);
|
407 |
|
|
s_prng_data(0) <= s_prng_feedback;
|
408 |
23 |
nussgipfel |
end if;
|
409 |
|
|
end if;
|
410 |
|
|
end process prng_shiftregister;
|
411 |
|
|
|
412 |
|
|
-- purpose: feedback polynom for the pseudo random number generator (PRNG)
|
413 |
|
|
-- inputs : s_prng_data
|
414 |
|
|
-- outputs: s_prng_feedback
|
415 |
|
|
s_prng_feedback <= s_prng_data(15) xor s_prng_data(13) xor s_prng_data(12)
|
416 |
|
|
xor s_prng_data(10);
|
417 |
|
|
|
418 |
|
|
|
419 |
24 |
nussgipfel |
|
420 |
23 |
nussgipfel |
-----------------------------------------------------------------------------
|
421 |
|
|
-- finite state machine (moore)
|
422 |
|
|
-----------------------------------------------------------------------------
|
423 |
|
|
|
424 |
|
|
-- state reg
|
425 |
|
|
fsm_state_reg : process(i_sysclk, i_nReset)
|
426 |
|
|
begin
|
427 |
|
|
if i_nReset = '0' then
|
428 |
|
|
state <= st1_idle;
|
429 |
|
|
elsif i_sysclk'event and i_sysclk = '1' then
|
430 |
|
|
state <= next_state;
|
431 |
|
|
end if;
|
432 |
|
|
end process fsm_state_reg;
|
433 |
|
|
|
434 |
|
|
|
435 |
|
|
-- comb logic
|
436 |
|
|
next_state_decode: process(state, s_receive_fifo_empty, s_send_fifo_full,
|
437 |
24 |
nussgipfel |
s_send_data_request, s_send_have_more_data, s_mode,
|
438 |
|
|
s_send_counter_equals_transfer_size)
|
439 |
23 |
nussgipfel |
begin -- process next_state_decode
|
440 |
|
|
|
441 |
|
|
--declare default state for next_state to avoid latches
|
442 |
|
|
next_state <= state; --default is to stay in current state
|
443 |
|
|
|
444 |
|
|
-- default signal values to avoid latches:
|
445 |
|
|
s_receive_fifo_rd_en <= '0';
|
446 |
|
|
s_send_transfersize_en <= '0';
|
447 |
|
|
s_send_fifo_wr_en <= '0';
|
448 |
|
|
s_transfer_size_reg_select <= '0';
|
449 |
|
|
s_transfer_size_reg_en <= '0';
|
450 |
|
|
s_send_counter_reset <= '0';
|
451 |
|
|
s_send_counter_en <= '0';
|
452 |
|
|
s_prng_en <= '0';
|
453 |
|
|
|
454 |
|
|
case state is
|
455 |
|
|
-- controll
|
456 |
|
|
|
457 |
|
|
when st1_idle =>
|
458 |
|
|
|
459 |
|
|
if s_receive_fifo_empty = '0' then
|
460 |
|
|
next_state <= st2_get_data;
|
461 |
|
|
elsif s_send_data_request = '1' then
|
462 |
|
|
next_state <= st3_load_total_transfer_size;
|
463 |
11 |
nussgipfel |
end if;
|
464 |
23 |
nussgipfel |
|
465 |
|
|
when st2_get_data =>
|
466 |
27 |
nussgipfel |
if s_receive_fifo_empty = '0' then
|
467 |
|
|
s_receive_fifo_rd_en <= '1';
|
468 |
|
|
end if;
|
469 |
11 |
nussgipfel |
|
470 |
23 |
nussgipfel |
if s_receive_fifo_empty = '1' then
|
471 |
|
|
next_state <= st1_idle;
|
472 |
|
|
end if;
|
473 |
|
|
|
474 |
|
|
when st3_load_total_transfer_size =>
|
475 |
|
|
s_send_counter_reset <= '1';
|
476 |
|
|
s_transfer_size_reg_en <= '1';
|
477 |
|
|
s_transfer_size_reg_select <= '1';
|
478 |
11 |
nussgipfel |
|
479 |
23 |
nussgipfel |
next_state <= st4_save_remaining_transfer_size;
|
480 |
|
|
|
481 |
|
|
when st4_save_remaining_transfer_size =>
|
482 |
|
|
s_send_transfersize_en <= '1';
|
483 |
11 |
nussgipfel |
|
484 |
23 |
nussgipfel |
next_state <= st5_send_data;
|
485 |
|
|
|
486 |
|
|
when st5_send_data =>
|
487 |
27 |
nussgipfel |
if s_send_fifo_full = '0' then
|
488 |
|
|
s_send_fifo_wr_en <= '1';
|
489 |
|
|
s_send_counter_en <= '1';
|
490 |
|
|
if s_mode = "01" then
|
491 |
|
|
s_prng_en <= '1';
|
492 |
|
|
end if;
|
493 |
23 |
nussgipfel |
end if;
|
494 |
|
|
|
495 |
24 |
nussgipfel |
if s_send_counter_equals_transfer_size = '1' and
|
496 |
|
|
s_send_have_more_data = '0'
|
497 |
|
|
then
|
498 |
23 |
nussgipfel |
next_state <= st1_idle;
|
499 |
24 |
nussgipfel |
elsif s_send_counter_equals_transfer_size = '1' and
|
500 |
|
|
s_send_have_more_data = '1'
|
501 |
|
|
then
|
502 |
23 |
nussgipfel |
next_state <= st7_subtract_transfered_data;
|
503 |
|
|
elsif s_send_fifo_full = '1' then
|
504 |
|
|
next_state <= st6_send_wait;
|
505 |
|
|
end if;
|
506 |
|
|
|
507 |
|
|
when st6_send_wait =>
|
508 |
28 |
nussgipfel |
|
509 |
23 |
nussgipfel |
if s_send_fifo_full = '0' then
|
510 |
|
|
next_state <= st5_send_data;
|
511 |
|
|
end if;
|
512 |
|
|
|
513 |
24 |
nussgipfel |
when st7_subtract_transfered_data =>
|
514 |
28 |
nussgipfel |
s_transfer_size_reg_select <= '0';
|
515 |
23 |
nussgipfel |
s_transfer_size_reg_en <= '1';
|
516 |
|
|
|
517 |
|
|
if s_send_data_request = '1' then
|
518 |
24 |
nussgipfel |
next_state <= st8_reset_send_counter;
|
519 |
23 |
nussgipfel |
end if;
|
520 |
|
|
|
521 |
|
|
when st8_reset_send_counter =>
|
522 |
|
|
s_send_counter_reset <= '1';
|
523 |
|
|
|
524 |
|
|
next_state <= st4_save_remaining_transfer_size;
|
525 |
|
|
|
526 |
|
|
when others =>
|
527 |
|
|
next_state <= st1_idle;
|
528 |
|
|
end case;
|
529 |
|
|
|
530 |
|
|
end process next_state_decode;
|
531 |
|
|
|
532 |
|
|
end behavour;
|
533 |
|
|
|
534 |
|
|
|
535 |
|
|
-----------------------------------------------------------------------------
|
536 |
|
|
-- RESPONSE MESSAGE ROM
|
537 |
|
|
-----------------------------------------------------------------------------
|
538 |
|
|
-- This file was generated with hex2rom written by Daniel Wallner
|
539 |
|
|
|
540 |
24 |
nussgipfel |
library ieee;
|
541 |
|
|
use ieee.std_logic_1164.all;
|
542 |
|
|
use IEEE.numeric_std.all;
|
543 |
|
|
|
544 |
23 |
nussgipfel |
entity response_message_rom is
|
545 |
|
|
port(
|
546 |
|
|
A : in std_logic_vector(3 downto 0);
|
547 |
|
|
D : out std_logic_vector(31 downto 0)
|
548 |
|
|
);
|
549 |
|
|
end response_message_rom;
|
550 |
|
|
|
551 |
|
|
architecture rtl of response_message_rom is
|
552 |
|
|
subtype ROM_WORD is std_logic_vector(31 downto 0);
|
553 |
|
|
type ROM_TABLE is array(0 to 3) of ROM_WORD;
|
554 |
|
|
signal ROM: ROM_TABLE := ROM_TABLE'(
|
555 |
|
|
"00100010001000000010110000110000", -- 0x0000
|
556 |
|
|
"01100101001000000110111101001110", -- 0x0004
|
557 |
|
|
"01110010011011110111001001110010", -- 0x0008
|
558 |
|
|
"00001010000010100000101000100010"); -- 0x000C
|
559 |
|
|
begin
|
560 |
|
|
D <= ROM(to_integer(unsigned(A)));
|
561 |
|
|
end;
|