1 |
22 |
nussgipfel |
-- GECKO3COM IP Core
|
2 |
|
|
--
|
3 |
|
|
-- Copyright (C) 2009 by
|
4 |
|
|
-- ___ ___ _ _
|
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 |
|
|
--------------------------------------------------------------------------------
|
26 |
|
|
--
|
27 |
|
|
-- Author: Christoph Zimmermann
|
28 |
|
|
-- Date of creation: 16:52:52 01/28/2010
|
29 |
|
|
-- Description:
|
30 |
|
|
-- This is the top module for the GECKO3com simple IP core.
|
31 |
|
|
-- Not the one for Xilinx EDK (with PLB bus), for processor less designs.
|
32 |
|
|
--
|
33 |
|
|
-- This core provides a simple FIFO and register interface to the
|
34 |
|
|
-- USB data transfer capabilities of the GECKO3COM/GECKO3main system.
|
35 |
|
|
--
|
36 |
23 |
nussgipfel |
-- Look at GECKO3COM_simple_test.vhd for an example how to use it.
|
37 |
22 |
nussgipfel |
--
|
38 |
|
|
-- Target Devices: general
|
39 |
|
|
-- Tool versions: 11.1
|
40 |
|
|
-- Dependencies: Xilinx FPGA's Spartan3 and up or Virtex4 and up.
|
41 |
|
|
--
|
42 |
|
|
--------------------------------------------------------------------------------
|
43 |
|
|
|
44 |
|
|
library IEEE;
|
45 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
46 |
|
|
use IEEE.STD_LOGIC_ARITH.all;
|
47 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.all;
|
48 |
|
|
|
49 |
|
|
library work;
|
50 |
|
|
use work.GECKO3COM_defines.all;
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
entity GECKO3COM_simple_datapath is
|
54 |
|
|
|
55 |
|
|
generic (
|
56 |
|
|
BUSWIDTH : integer := 16);
|
57 |
|
|
|
58 |
|
|
port (
|
59 |
|
|
i_nReset : in std_logic;
|
60 |
|
|
i_sysclk : in std_logic;
|
61 |
|
|
i_rx_data : in std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
|
62 |
|
|
o_tx_data : out std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
|
63 |
|
|
|
64 |
26 |
nussgipfel |
i_receive_fifo_rd_en : in std_logic;
|
65 |
|
|
i_receive_fifo_wr_en : in std_logic;
|
66 |
|
|
o_receive_fifo_empty : out std_logic;
|
67 |
|
|
o_receive_fifo_full : out std_logic;
|
68 |
|
|
o_receive_fifo_data : out std_logic_vector(BUSWIDTH-1 downto 0);
|
69 |
|
|
i_receive_fifo_reset : in std_logic;
|
70 |
|
|
o_receive_transfersize : out std_logic_vector(31 downto 0);
|
71 |
|
|
i_receive_transfersize_en : in std_logic_vector((32/SIZE_DBUS_GPIF)-1 downto 0);
|
72 |
|
|
o_receive_transfersize_lsb : out std_logic;
|
73 |
|
|
i_receive_counter_load : in std_logic;
|
74 |
|
|
i_receive_counter_en : in std_logic;
|
75 |
|
|
o_receive_counter_zero : out std_logic;
|
76 |
|
|
o_dev_dep_msg_out : out std_logic;
|
77 |
|
|
o_request_dev_dep_msg_in : out std_logic;
|
78 |
|
|
i_btag_reg_en : in std_logic;
|
79 |
|
|
i_nbtag_reg_en : in std_logic;
|
80 |
|
|
o_btag_correct : out std_logic;
|
81 |
|
|
o_eom_bit_detected : out std_logic;
|
82 |
22 |
nussgipfel |
|
83 |
|
|
i_send_fifo_rd_en : in std_logic;
|
84 |
|
|
i_send_fifo_wr_en : in std_logic;
|
85 |
|
|
o_send_fifo_empty : out std_logic;
|
86 |
|
|
o_send_fifo_full : out std_logic;
|
87 |
|
|
i_send_fifo_data : in std_logic_vector(BUSWIDTH-1 downto 0);
|
88 |
|
|
i_send_fifo_reset : in std_logic;
|
89 |
|
|
i_send_transfersize : in std_logic_vector(31 downto 0);
|
90 |
|
|
i_send_transfersize_en : in std_logic;
|
91 |
23 |
nussgipfel |
i_send_have_more_data : in std_logic;
|
92 |
22 |
nussgipfel |
i_send_counter_load : in std_logic;
|
93 |
|
|
i_send_counter_en : in std_logic;
|
94 |
|
|
o_send_counter_zero : out std_logic;
|
95 |
|
|
i_send_mux_sel : in std_logic_vector(2 downto 0);
|
96 |
|
|
|
97 |
|
|
i_receive_newdata_set : in std_logic;
|
98 |
|
|
o_receive_newdata : out std_logic;
|
99 |
|
|
i_receive_end_of_message_set : in std_logic;
|
100 |
|
|
o_receive_end_of_message : out std_logic;
|
101 |
|
|
i_send_data_request_set : in std_logic;
|
102 |
|
|
o_send_data_request : out std_logic);
|
103 |
|
|
|
104 |
|
|
end GECKO3COM_simple_datapath;
|
105 |
|
|
|
106 |
|
|
architecture behaviour of GECKO3COM_simple_datapath is
|
107 |
|
|
|
108 |
|
|
-----------------------------------------------------------------------------
|
109 |
|
|
-- COMPONENTS
|
110 |
|
|
-----------------------------------------------------------------------------
|
111 |
|
|
|
112 |
|
|
component receive_fifo
|
113 |
|
|
generic (
|
114 |
|
|
BUSWIDTH : integer);
|
115 |
|
|
port (
|
116 |
26 |
nussgipfel |
i_din : in std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
|
117 |
|
|
i_clk : in std_logic;
|
118 |
|
|
i_rd_en : in std_logic;
|
119 |
|
|
i_rst : in std_logic;
|
120 |
|
|
i_wr_en : in std_logic;
|
121 |
|
|
o_dout : out std_logic_vector(BUSWIDTH-1 downto 0);
|
122 |
|
|
o_empty : out std_logic;
|
123 |
|
|
o_full : out std_logic);
|
124 |
22 |
nussgipfel |
end component;
|
125 |
|
|
|
126 |
|
|
component send_fifo
|
127 |
|
|
generic (
|
128 |
|
|
BUSWIDTH : integer);
|
129 |
|
|
port (
|
130 |
26 |
nussgipfel |
i_din : in std_logic_vector(BUSWIDTH-1 downto 0);
|
131 |
|
|
i_clk : in std_logic;
|
132 |
|
|
i_rd_en : in std_logic;
|
133 |
|
|
i_rst : in std_logic;
|
134 |
|
|
i_wr_en : in std_logic;
|
135 |
|
|
o_dout : out std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
|
136 |
|
|
o_empty : out std_logic;
|
137 |
|
|
o_full : out std_logic);
|
138 |
22 |
nussgipfel |
end component;
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
-----------------------------------------------------------------------------
|
142 |
|
|
-- interconection signals
|
143 |
|
|
-----------------------------------------------------------------------------
|
144 |
|
|
|
145 |
26 |
nussgipfel |
signal s_receive_transfersize : std_logic_vector(31 downto 0);
|
146 |
|
|
signal s_send_transfersize_reg : std_logic_vector(31 downto 0);
|
147 |
22 |
nussgipfel |
|
148 |
26 |
nussgipfel |
signal s_receive_transfersize_count : std_logic_vector(30 downto 0);
|
149 |
|
|
signal s_send_transfersize_count : std_logic_vector(30 downto 0);
|
150 |
22 |
nussgipfel |
|
151 |
|
|
signal s_receive_fifo_empty : std_logic;
|
152 |
|
|
|
153 |
26 |
nussgipfel |
signal s_send_fifo_data : std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
|
154 |
|
|
signal s_btag, s_nbtag, s_msg_id : std_logic_vector(7 downto 0);
|
155 |
22 |
nussgipfel |
|
156 |
|
|
begin -- behaviour
|
157 |
|
|
|
158 |
|
|
receive_fifo_1 : receive_fifo
|
159 |
|
|
generic map (
|
160 |
|
|
BUSWIDTH => BUSWIDTH)
|
161 |
|
|
port map (
|
162 |
|
|
i_din => i_rx_data,
|
163 |
|
|
i_clk => i_sysclk,
|
164 |
|
|
i_rd_en => i_receive_fifo_rd_en,
|
165 |
24 |
nussgipfel |
i_rst => i_receive_fifo_reset,
|
166 |
22 |
nussgipfel |
i_wr_en => i_receive_fifo_wr_en,
|
167 |
|
|
o_dout => o_receive_fifo_data,
|
168 |
|
|
o_empty => s_receive_fifo_empty,
|
169 |
|
|
o_full => o_receive_fifo_full);
|
170 |
|
|
|
171 |
|
|
send_fifo_1 : send_fifo
|
172 |
|
|
generic map (
|
173 |
|
|
BUSWIDTH => BUSWIDTH)
|
174 |
|
|
port map (
|
175 |
|
|
i_din => i_send_fifo_data,
|
176 |
|
|
i_clk => i_sysclk,
|
177 |
|
|
i_rd_en => i_send_fifo_rd_en,
|
178 |
24 |
nussgipfel |
i_rst => i_send_fifo_reset,
|
179 |
22 |
nussgipfel |
i_wr_en => i_send_fifo_wr_en,
|
180 |
|
|
o_dout => s_send_fifo_data,
|
181 |
|
|
o_empty => o_send_fifo_empty,
|
182 |
|
|
o_full => o_send_fifo_full);
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
o_receive_fifo_empty <= s_receive_fifo_empty;
|
186 |
|
|
|
187 |
|
|
-- purpose: process to fill the 32 bit receive_transfersize register with 8
|
188 |
|
|
-- or 16 bit wide input data.
|
189 |
|
|
-- type : sequential
|
190 |
|
|
-- inputs : i_sysclk, i_nReset, i_rx_data, i_receive_transfersize_en
|
191 |
26 |
nussgipfel |
receive_transfersize : process (i_sysclk, i_nReset)
|
192 |
22 |
nussgipfel |
begin -- process registers
|
193 |
|
|
if i_nReset = '0' then -- asynchronous reset (active low)
|
194 |
|
|
s_receive_transfersize <= (others => '0');
|
195 |
|
|
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
196 |
|
|
if i_receive_transfersize_en(0) = '1' then
|
197 |
|
|
s_receive_transfersize(15 downto 0) <= i_rx_data;
|
198 |
|
|
end if;
|
199 |
|
|
if i_receive_transfersize_en(1) = '1' then
|
200 |
|
|
s_receive_transfersize(31 downto 16) <= i_rx_data;
|
201 |
|
|
end if;
|
202 |
|
|
end if;
|
203 |
|
|
end process receive_transfersize;
|
204 |
|
|
|
205 |
|
|
o_receive_transfersize <= s_receive_transfersize;
|
206 |
26 |
nussgipfel |
o_receive_transfersize_lsb <= s_receive_transfersize(0);
|
207 |
22 |
nussgipfel |
|
208 |
|
|
|
209 |
|
|
-- purpose: 32 bit send_transfersize register
|
210 |
|
|
-- type : sequential
|
211 |
|
|
-- inputs : i_sysclk, i_nReset, i_send_transfersize, i_receive_transfersize_en
|
212 |
26 |
nussgipfel |
send_transfersize : process (i_sysclk, i_nReset)
|
213 |
22 |
nussgipfel |
begin -- process registers
|
214 |
|
|
if i_nReset = '0' then -- asynchronous reset (active low)
|
215 |
|
|
s_send_transfersize_reg <= (others => '0');
|
216 |
|
|
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
217 |
|
|
if i_send_transfersize_en = '1' then
|
218 |
|
|
s_send_transfersize_reg <= i_send_transfersize;
|
219 |
|
|
end if;
|
220 |
|
|
end if;
|
221 |
|
|
end process send_transfersize;
|
222 |
|
|
|
223 |
26 |
nussgipfel |
|
224 |
22 |
nussgipfel |
-- purpose: down counter for the receive transfer size
|
225 |
|
|
-- type : sequential
|
226 |
|
|
-- inputs : i_sysclk, i_nReset, s_reveive_transfersize,
|
227 |
|
|
-- i_receive_transfersize_en
|
228 |
|
|
-- outputs: s_receive_transfersize_count
|
229 |
|
|
receive_counter : process (i_sysclk, i_nReset)
|
230 |
|
|
begin -- process receive_counter
|
231 |
|
|
if i_nReset = '0' then -- asynchronous reset (active low)
|
232 |
|
|
s_receive_transfersize_count <= (others => '0');
|
233 |
|
|
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
234 |
|
|
if i_receive_counter_load = '1' then
|
235 |
26 |
nussgipfel |
s_receive_transfersize_count <= s_receive_transfersize(31 downto 1);
|
236 |
|
|
elsif i_receive_counter_en = '1' then
|
237 |
22 |
nussgipfel |
s_receive_transfersize_count <= s_receive_transfersize_count - 1;
|
238 |
26 |
nussgipfel |
else
|
239 |
|
|
s_receive_transfersize_count <= s_receive_transfersize_count;
|
240 |
22 |
nussgipfel |
end if;
|
241 |
|
|
end if;
|
242 |
|
|
end process receive_counter;
|
243 |
|
|
|
244 |
|
|
o_receive_counter_zero <=
|
245 |
26 |
nussgipfel |
'1' when s_receive_transfersize_count = "000000000000000000000000000000"
|
246 |
|
|
else '0';
|
247 |
22 |
nussgipfel |
|
248 |
|
|
|
249 |
|
|
-- purpose: down counter for the send transfer size
|
250 |
|
|
-- type : sequential
|
251 |
|
|
-- inputs : i_sysclk, i_nReset, s_send_transfersize_reg,
|
252 |
|
|
-- i_send_transfersize_en
|
253 |
|
|
-- outputs: s_send_transfersize_count
|
254 |
|
|
send_counter : process (i_sysclk, i_nReset)
|
255 |
23 |
nussgipfel |
begin -- process send_counter
|
256 |
22 |
nussgipfel |
if i_nReset = '0' then -- asynchronous reset (active low)
|
257 |
|
|
s_send_transfersize_count <= (others => '0');
|
258 |
|
|
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
259 |
|
|
if i_send_counter_load = '1' then
|
260 |
26 |
nussgipfel |
s_send_transfersize_count <= s_send_transfersize_reg(31 downto 1);
|
261 |
|
|
elsif i_send_counter_en = '1' then
|
262 |
22 |
nussgipfel |
s_send_transfersize_count <= s_send_transfersize_count - 1;
|
263 |
26 |
nussgipfel |
else
|
264 |
|
|
s_send_transfersize_count <= s_send_transfersize_count;
|
265 |
22 |
nussgipfel |
end if;
|
266 |
|
|
end if;
|
267 |
|
|
end process send_counter;
|
268 |
|
|
|
269 |
|
|
o_send_counter_zero <=
|
270 |
26 |
nussgipfel |
'1' when s_send_transfersize_count = "000000000000000000000000000000"
|
271 |
|
|
else '0';
|
272 |
22 |
nussgipfel |
|
273 |
|
|
|
274 |
|
|
-- purpose: registers to store the btag and inverse btag
|
275 |
|
|
-- type : sequential
|
276 |
|
|
-- inputs : i_sysclk, i_nReset, i_btag_reg_en, i_nbtag_reg_en
|
277 |
|
|
-- i_rx_data
|
278 |
|
|
-- outputs: s_btag, s_nbtag
|
279 |
|
|
btag_register : process (i_sysclk, i_nReset)
|
280 |
23 |
nussgipfel |
begin -- process btag_register
|
281 |
22 |
nussgipfel |
if i_nReset = '0' then -- asynchronous reset (active low)
|
282 |
26 |
nussgipfel |
s_btag <= (others => '0');
|
283 |
23 |
nussgipfel |
s_msg_id <= (others => '0');
|
284 |
26 |
nussgipfel |
s_nbtag <= (others => '0');
|
285 |
22 |
nussgipfel |
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
286 |
|
|
if i_btag_reg_en = '1' then
|
287 |
26 |
nussgipfel |
s_btag <= i_rx_data(15 downto 8);
|
288 |
23 |
nussgipfel |
s_msg_id <= i_rx_data(7 downto 0);
|
289 |
22 |
nussgipfel |
end if;
|
290 |
26 |
nussgipfel |
if i_nbtag_reg_en = '1' then
|
291 |
22 |
nussgipfel |
s_nbtag <= i_rx_data(7 downto 0);
|
292 |
|
|
end if;
|
293 |
|
|
end if;
|
294 |
|
|
end process btag_register;
|
295 |
26 |
nussgipfel |
|
296 |
22 |
nussgipfel |
o_btag_correct <=
|
297 |
|
|
'1' when s_btag = not s_nbtag else
|
298 |
|
|
'0';
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
o_dev_dep_msg_out <=
|
302 |
23 |
nussgipfel |
'1' when s_msg_id(7 downto 0) = x"01" else
|
303 |
22 |
nussgipfel |
'0';
|
304 |
|
|
|
305 |
|
|
o_request_dev_dep_msg_in <=
|
306 |
23 |
nussgipfel |
'1' when s_msg_id(7 downto 0) = x"02" else
|
307 |
22 |
nussgipfel |
'0';
|
308 |
|
|
|
309 |
|
|
o_eom_bit_detected <=
|
310 |
26 |
nussgipfel |
'1' when i_rx_data(7 downto 0) = b"00000001" else
|
311 |
22 |
nussgipfel |
'0';
|
312 |
|
|
|
313 |
|
|
|
314 |
|
|
-- purpose: mulitiplexer to construct the tmc header structure
|
315 |
|
|
-- type : combinational
|
316 |
24 |
nussgipfel |
-- inputs : i_send_mux_sel, i_send_have_more_data, s_btag, s_nbtag,
|
317 |
|
|
-- s_send_fifo_data, s_send_transfersize_reg
|
318 |
22 |
nussgipfel |
-- outputs: o_tx_data
|
319 |
26 |
nussgipfel |
tx_data_mux : process (i_send_mux_sel, i_send_have_more_data, s_btag,
|
320 |
27 |
nussgipfel |
s_msg_id, s_nbtag, s_send_fifo_data,
|
321 |
|
|
s_send_transfersize_reg)
|
322 |
22 |
nussgipfel |
begin -- process tx_data_mux
|
323 |
|
|
case i_send_mux_sel is
|
324 |
26 |
nussgipfel |
when "000" => o_tx_data <= s_btag & s_msg_id; -- MsgID and stored bTag
|
325 |
|
|
when "001" => o_tx_data <= x"00" & s_nbtag; -- inverted bTag and Reserved
|
326 |
|
|
when "010" => o_tx_data <= s_send_transfersize_reg(15 downto 0);
|
327 |
|
|
when "011" => o_tx_data <= s_send_transfersize_reg(31 downto 16);
|
328 |
23 |
nussgipfel |
--TransferAttributes EOM bit:
|
329 |
26 |
nussgipfel |
when "100" => o_tx_data <= b"000000000000000" & not i_send_have_more_data;
|
330 |
|
|
when "101" => o_tx_data <= x"0000"; -- Header byte 10 and 11, Reserved
|
331 |
|
|
when "110" => o_tx_data <= s_send_fifo_data; -- message data
|
332 |
|
|
when others => o_tx_data <= s_btag & s_msg_id; -- MsgID and stored bTag
|
333 |
22 |
nussgipfel |
end case;
|
334 |
|
|
end process tx_data_mux;
|
335 |
|
|
|
336 |
|
|
|
337 |
23 |
nussgipfel |
-- purpose: set and reset behavour for the status flags
|
338 |
|
|
-- type : sequential
|
339 |
|
|
-- inputs : i_sysclk, i_nReset, i_receive_newdata_set,
|
340 |
|
|
-- i_receive_end_of_message_set, s_send_data_request_set,
|
341 |
|
|
-- i_receive_fifo_rd_en, s_receive_fifo_empty, i_send_fifo_wr_en
|
342 |
|
|
-- outputs: o_receive_newdata, o_receive_end_of_message, o_send_data_request
|
343 |
|
|
gecko3com_simple_flags : process (i_sysclk, i_nReset)
|
344 |
|
|
variable v_receive_fifo_empty_old : std_logic;
|
345 |
|
|
begin -- process gecko3com_simple_flags
|
346 |
|
|
if i_nReset = '0' then -- asynchronous reset (active low)
|
347 |
|
|
o_receive_newdata <= '0';
|
348 |
22 |
nussgipfel |
o_receive_end_of_message <= '0';
|
349 |
23 |
nussgipfel |
o_send_data_request <= '0';
|
350 |
|
|
v_receive_fifo_empty_old := '0';
|
351 |
|
|
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
352 |
|
|
if i_receive_newdata_set = '1' then
|
353 |
|
|
o_receive_newdata <= '1';
|
354 |
|
|
end if;
|
355 |
|
|
if i_receive_fifo_rd_en = '1' then
|
356 |
|
|
o_receive_newdata <= '0';
|
357 |
|
|
end if;
|
358 |
22 |
nussgipfel |
|
359 |
23 |
nussgipfel |
if i_receive_end_of_message_set = '1' then
|
360 |
|
|
o_receive_end_of_message <= '1';
|
361 |
|
|
end if;
|
362 |
|
|
if s_receive_fifo_empty = '1' and v_receive_fifo_empty_old = '0' then
|
363 |
|
|
o_receive_end_of_message <= '0';
|
364 |
|
|
end if;
|
365 |
|
|
v_receive_fifo_empty_old := s_receive_fifo_empty;
|
366 |
|
|
|
367 |
|
|
if i_send_data_request_set = '1' then
|
368 |
|
|
o_send_data_request <= '1';
|
369 |
|
|
end if;
|
370 |
|
|
if i_send_fifo_wr_en = '1' then
|
371 |
|
|
o_send_data_request <= '0';
|
372 |
|
|
end if;
|
373 |
22 |
nussgipfel |
end if;
|
374 |
23 |
nussgipfel |
end process gecko3com_simple_flags;
|
375 |
22 |
nussgipfel |
|
376 |
26 |
nussgipfel |
|
377 |
22 |
nussgipfel |
end behaviour;
|