OpenCores
URL https://opencores.org/ocsvn/gecko3/gecko3/trunk

Subversion Repositories gecko3

[/] [gecko3/] [trunk/] [GECKO3COM/] [gecko3com-ip/] [core/] [GECKO3COM_simple_datapath.vhd] - Blame information for rev 22

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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
--      Look at GECKO3COM_loopback.vhd for an example how to use it.
37
--
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
    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
    i_receive_counter_load    : in  std_logic;
73
    i_receive_counter_en      : in  std_logic;
74
    o_receive_counter_zero    : out std_logic;
75
    o_dev_dep_msg_out         : out std_logic;
76
    o_request_dev_dep_msg_in  : out std_logic;
77
    i_btag_reg_en             : in  std_logic;
78
    i_nbtag_reg_en            : in  std_logic;
79
    o_btag_correct            : out std_logic;
80
    o_eom_bit_detected        : out std_logic;
81
 
82
    i_send_fifo_rd_en      : in  std_logic;
83
    i_send_fifo_wr_en      : in  std_logic;
84
    o_send_fifo_empty      : out std_logic;
85
    o_send_fifo_full       : out std_logic;
86
    i_send_fifo_data       : in  std_logic_vector(BUSWIDTH-1 downto 0);
87
    i_send_fifo_reset      : in  std_logic;
88
    i_send_transfersize    : in  std_logic_vector(31 downto 0);
89
    i_send_transfersize_en : in  std_logic;
90
    i_send_counter_load    : in  std_logic;
91
    i_send_counter_en      : in  std_logic;
92
    o_send_counter_zero    : out std_logic;
93
    i_send_mux_sel         : in  std_logic_vector(2 downto 0);
94
 
95
    i_receive_newdata_set        : in  std_logic;
96
    o_receive_newdata            : out std_logic;
97
    i_receive_end_of_message_set : in  std_logic;
98
    o_receive_end_of_message     : out std_logic;
99
    i_send_data_request_set      : in  std_logic;
100
    o_send_data_request          : out std_logic);
101
 
102
end GECKO3COM_simple_datapath;
103
 
104
architecture behaviour of GECKO3COM_simple_datapath is
105
 
106
  -----------------------------------------------------------------------------
107
  -- COMPONENTS
108
  -----------------------------------------------------------------------------
109
 
110
  component receive_fifo
111
    generic (
112
      BUSWIDTH : integer);
113
    port (
114
      i_din    : in  std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
115
      i_clk    : in  std_logic;
116
      i_rd_en  : in  std_logic;
117
      i_rst    : in  std_logic;
118
      i_wr_en  : in  std_logic;
119
      o_dout   : out std_logic_vector(BUSWIDTH-1 downto 0);
120
      o_empty  : out std_logic;
121
      o_full   : out std_logic);
122
  end component;
123
 
124
  component send_fifo
125
    generic (
126
      BUSWIDTH : integer);
127
    port (
128
      i_din    : in  std_logic_vector(BUSWIDTH-1 downto 0);
129
      i_clk    : in  std_logic;
130
      i_rd_en  : in  std_logic;
131
      i_rst    : in  std_logic;
132
      i_wr_en  : in  std_logic;
133
      o_dout   : out std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
134
      o_empty  : out std_logic;
135
      o_full   : out std_logic);
136
  end component;
137
 
138
 
139
  -----------------------------------------------------------------------------
140
  -- interconection signals
141
  -----------------------------------------------------------------------------
142
 
143
  signal s_receive_transfersize : std_logic_vector(31 downto 0);
144
  signal s_send_transfersize_reg: std_logic_vector(31 downto 0);
145
 
146
  signal s_receive_transfersize_count: std_logic_vector(31 downto 0);
147
  signal s_send_transfersize_count: std_logic_vector(31 downto 0);
148
 
149
  signal s_receive_fifo_empty : std_logic;
150
 
151
  signal s_send_fifo_data : std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
152
  signal s_btag, s_nbtag : std_logic_vector(7 downto 0);
153
 
154
begin  -- behaviour
155
 
156
  receive_fifo_1 : receive_fifo
157
    generic map (
158
      BUSWIDTH => BUSWIDTH)
159
    port map (
160
      i_din   => i_rx_data,
161
      i_clk   => i_sysclk,
162
      i_rd_en => i_receive_fifo_rd_en,
163
      i_rst   => i_nReset,
164
      i_wr_en => i_receive_fifo_wr_en,
165
      o_dout  => o_receive_fifo_data,
166
      o_empty => s_receive_fifo_empty,
167
      o_full  => o_receive_fifo_full);
168
 
169
  send_fifo_1 : send_fifo
170
    generic map (
171
      BUSWIDTH => BUSWIDTH)
172
    port map (
173
      i_din   => i_send_fifo_data,
174
      i_clk   => i_sysclk,
175
      i_rd_en => i_send_fifo_rd_en,
176
      i_rst   => i_nReset,
177
      i_wr_en => i_send_fifo_wr_en,
178
      o_dout  => s_send_fifo_data,
179
      o_empty => o_send_fifo_empty,
180
      o_full  => o_send_fifo_full);
181
 
182
 
183
  o_receive_fifo_empty <= s_receive_fifo_empty;
184
 
185
  -- purpose: process to fill the 32 bit receive_transfersize register with 8
186
  --          or 16 bit wide input data.
187
  -- type   : sequential
188
  -- inputs : i_sysclk, i_nReset, i_rx_data, i_receive_transfersize_en
189
  receive_transfersize: process (i_sysclk, i_nReset)
190
  begin  -- process registers
191
    if i_nReset = '0' then              -- asynchronous reset (active low)
192
      s_receive_transfersize <= (others => '0');
193
    elsif i_sysclk'event and i_sysclk = '1' then  -- rising clock edge
194
      if i_receive_transfersize_en(0) = '1' then
195
        s_receive_transfersize(15 downto 0) <= i_rx_data;
196
      end if;
197
      if i_receive_transfersize_en(1) = '1' then
198
        s_receive_transfersize(31 downto 16) <= i_rx_data;
199
      end if;
200
    end if;
201
  end process receive_transfersize;
202
 
203
  o_receive_transfersize <= s_receive_transfersize;
204
 
205
 
206
  -- purpose: 32 bit send_transfersize register
207
  -- type   : sequential
208
  -- inputs : i_sysclk, i_nReset, i_send_transfersize, i_receive_transfersize_en
209
  send_transfersize: process (i_sysclk, i_nReset)
210
  begin  -- process registers
211
    if i_nReset = '0' then              -- asynchronous reset (active low)
212
      s_send_transfersize_reg <= (others => '0');
213
    elsif i_sysclk'event and i_sysclk = '1' then  -- rising clock edge
214
      if i_send_transfersize_en = '1' then
215
        s_send_transfersize_reg <= i_send_transfersize;
216
      end if;
217
    end if;
218
  end process send_transfersize;
219
 
220
 
221
  -- purpose: down counter for the receive transfer size
222
  -- type   : sequential
223
  -- inputs : i_sysclk, i_nReset, s_reveive_transfersize,
224
  --          i_receive_transfersize_en
225
  -- outputs: s_receive_transfersize_count
226
  receive_counter : process (i_sysclk, i_nReset)
227
  begin  -- process receive_counter
228
    if i_nReset = '0' then              -- asynchronous reset (active low)
229
      s_receive_transfersize_count <= (others => '0');
230
    elsif i_sysclk'event and i_sysclk = '1' then  -- rising clock edge
231
      if i_receive_counter_load = '1' then
232
        s_receive_transfersize_count <= s_receive_transfersize;
233
      end if;
234
      if i_receive_counter_en = '1' then
235
        s_receive_transfersize_count <= s_receive_transfersize_count - 1;
236
      end if;
237
    end if;
238
  end process receive_counter;
239
 
240
  o_receive_counter_zero <=
241
    '1' when s_receive_transfersize_count = x"0000" else
242
    '0';
243
 
244
 
245
  -- purpose: down counter for the send transfer size
246
  -- type   : sequential
247
  -- inputs : i_sysclk, i_nReset, s_send_transfersize_reg,
248
  --          i_send_transfersize_en
249
  -- outputs: s_send_transfersize_count
250
  send_counter : process (i_sysclk, i_nReset)
251
  begin  -- process receive_counter
252
    if i_nReset = '0' then              -- asynchronous reset (active low)
253
      s_send_transfersize_count <= (others => '0');
254
    elsif i_sysclk'event and i_sysclk = '1' then  -- rising clock edge
255
      if i_send_counter_load = '1' then
256
        s_receive_transfersize_count <= s_send_transfersize_reg;
257
      end if;
258
      if i_send_counter_en = '1' then
259
        s_send_transfersize_count <= s_send_transfersize_count - 1;
260
      end if;
261
    end if;
262
  end process send_counter;
263
 
264
  o_send_counter_zero <=
265
    '1' when s_send_transfersize_count = x"0000" else
266
    '0';
267
 
268
 
269
  -- purpose: registers to store the btag and inverse btag
270
  -- type   : sequential
271
  -- inputs : i_sysclk, i_nReset, i_btag_reg_en, i_nbtag_reg_en
272
  --          i_rx_data
273
  -- outputs: s_btag, s_nbtag
274
  btag_register : process (i_sysclk, i_nReset)
275
  begin  -- process receive_counter
276
    if i_nReset = '0' then              -- asynchronous reset (active low)
277
      s_btag <= (others => '0');
278
      s_nbtag <= (others => '0');
279
    elsif i_sysclk'event and i_sysclk = '1' then  -- rising clock edge
280
      if i_btag_reg_en = '1' then
281
        s_btag <= i_rx_data(15 downto 8);
282
      end if;
283
      if   i_nbtag_reg_en = '1' then
284
        s_nbtag <= i_rx_data(7 downto 0);
285
      end if;
286
    end if;
287
  end process btag_register;
288
 
289
  o_btag_correct <=
290
    '1' when s_btag = not s_nbtag else
291
    '0';
292
 
293
 
294
  o_dev_dep_msg_out <=
295
    '1' when i_rx_data(7 downto 0) = x"01" else
296
    '0';
297
 
298
  o_request_dev_dep_msg_in <=
299
    '1' when i_rx_data(7 downto 0) = x"02" else
300
    '0';
301
 
302
  o_eom_bit_detected <=
303
    '1' when i_rx_data(15 downto 8) = b"00000001" else
304
    '0';
305
 
306
 
307
  -- purpose: mulitiplexer to construct the tmc header structure
308
  -- type   : combinational
309
  -- inputs : i_send_mux_sel, s_btag, s_nbtag, s_send_fifo_data,
310
  --          s_send_transfersize_reg
311
  -- outputs: o_tx_data
312
  tx_data_mux: process (i_send_mux_sel, s_btag, s_nbtag, s_send_fifo_data,
313
                        s_send_transfersize_reg)
314
  begin  -- process tx_data_mux
315
    case i_send_mux_sel is
316
      when "000" => o_tx_data <= x"02" & s_btag;  -- MsgID and stored bTag
317
      when "001" => o_tx_data <= s_nbtag & x"00"; -- inverted bTag and Reserved
318
      when "010" => o_tx_data <= s_send_transfersize_reg(15 downto 0);
319
      when "011" => o_tx_data <= s_send_transfersize_reg(31 downto 16);
320
      when "100" => o_tx_data <= x"0001";  -- TransferAttributes: EOM = 1
321
      when "101" => o_tx_data <= x"0000";  -- Header byte 10 and 11, Reserved
322
      when "110" => o_tx_data <= s_send_fifo_data;  -- message data
323
      when others => o_tx_data <= s_send_fifo_data;
324
    end case;
325
  end process tx_data_mux;
326
 
327
 
328
-- purpose: set and reset behavour for the status flags
329
-- type   : sequential
330
-- inputs : i_sysclk, i_nReset, i_receive_newdata_set,
331
--          i_receive_end_of_message_set, s_send_data_request_set,
332
--          i_receive_fifo_rd_en, s_receive_fifo_empty, i_send_fifo_wr_en
333
-- outputs: o_receive_newdata, o_receive_end_of_message, o_send_data_request
334
gecko3com_simple_flags: process (i_sysclk, i_nReset)
335
begin  -- process gecko3com_simple_flags
336
  if i_nReset = '0' then                -- asynchronous reset (active low)
337
    o_receive_newdata <= '0';
338
    o_receive_end_of_message <= '0';
339
    o_send_data_request <= '0';
340
  elsif i_sysclk'event and i_sysclk = '1' then  -- rising clock edge
341
    if i_receive_newdata_set = '1' then
342
      o_receive_newdata <= '1';
343
    end if;
344
    if i_receive_fifo_rd_en = '1' then
345
      o_receive_newdata <= '0';
346
    end if;
347
 
348
    if i_receive_end_of_message_set = '1' then
349
      o_receive_end_of_message <= '1';
350
    end if;
351
    if s_receive_fifo_empty = '1' then
352
      o_receive_end_of_message <= '0';
353
    end if;
354
 
355
    if i_send_data_request_set = '1' then
356
      o_send_data_request <= '1';
357
    end if;
358
    if i_send_fifo_wr_en = '1' then
359
      o_send_data_request <= '0';
360
    end if;
361
  end if;
362
end process gecko3com_simple_flags;
363
 
364
 
365
end behaviour;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.