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

Subversion Repositories gecko3

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 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 18 nussgipfel
--------------------------------------------------------------------------------
26 14 nussgipfel
--
27
--  Author:  Andreas Habegger, Christoph Zimmermann
28
--  Date of creation: 8. April 2009
29
--  Description:
30 18 nussgipfel
--    GECKO3COM defines the communication between the GECKO3main and a USB
31
--    Master e.g. a computer.
32 14 nussgipfel
--
33 18 nussgipfel
--    This file is the top module, it instantiates all required submodules and
34
--    connects them together.
35
--
36
--  Target Devices:     Xilinx Spartan3 FPGA's
37
--                      (usage of BlockRam in the Datapath)
38
--  Tool versions:      11.1
39 14 nussgipfel
--  Dependencies:
40
--
41 18 nussgipfel
--------------------------------------------------------------------------------
42 14 nussgipfel
 
43 11 nussgipfel
library ieee;
44
use ieee.std_logic_1164.all;
45
use ieee.std_logic_arith.all;
46
 
47
library work;
48 14 nussgipfel
use work.GECKO3COM_defines.all;
49 11 nussgipfel
 
50
 
51 14 nussgipfel
entity gpif_com is
52 11 nussgipfel
  port (
53 18 nussgipfel
    -- interface signals to higher level
54
    i_nReset  : in  std_logic;          -- asynchronous active low reset
55
    i_SYSCLK  : in  std_logic;          -- FPGA System CLK
56
    o_ABORT   : out std_logic;          -- Abort detected, you have to flush the data
57
    o_RX      : out std_logic;          -- controll LED rx
58
    o_TX      : out std_logic;          -- controll LED tx
59
    i_RD_EN   : in  std_logic;          -- read enable
60
    o_EMPTY   : out std_logic;          -- receive fifo empty
61
    o_RX_DATA : out std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);  -- receive data
62 20 nussgipfel
    i_EOM     : in  std_logic;
63 18 nussgipfel
    i_WR_EN   : in  std_logic;          -- write enable
64
    o_FULL    : out std_logic;          -- send fifo full
65
    i_TX_DATA : in  std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);  -- send data
66
 
67
    -- GPIF connections, to be connected to FPGA pins
68
    i_IFCLK    : in    std_logic;       -- GPIF CLK (GPIF is Master and provides the clock)
69
    i_WRU      : in    std_logic;       -- write from GPIF
70
    i_RDYU     : in    std_logic;       -- GPIF is ready
71
    o_WRX      : out   std_logic;       -- To write to GPIF
72
    o_RDYX     : out   std_logic;       -- IP Core is ready
73
    b_gpif_bus : inout std_logic_vector(SIZE_DBUS_GPIF-1 downto 0));  -- bidirect data bus
74 14 nussgipfel
end gpif_com;
75 11 nussgipfel
 
76
 
77
 
78 14 nussgipfel
architecture structure of gpif_com is
79
 
80 11 nussgipfel
  -- interconection signals
81 29 nussgipfel
  signal s_FIFOrst, s_WRX, s_RDYX         : std_logic;
82 11 nussgipfel
 
83 29 nussgipfel
  signal s_ABORT_FSM, s_ABORT_TMP         : std_logic;
84
  signal s_RX_FSM, s_RX_TMP               : std_logic;
85
  signal s_TX_FSM, s_TX_TMP               : std_logic;
86
  signal s_EOM, s_EOM_TMP, s_EOM_FF       : std_logic;  -- End of message
87 20 nussgipfel
  signal s_X2U_FULL_IFCLK, s_X2U_FULL_TMP : std_logic;
88 14 nussgipfel
 
89 18 nussgipfel
  -- USB to Xilinx (U2X)
90 12 nussgipfel
  signal s_U2X_WR_EN,
91 18 nussgipfel
    s_U2X_RD_EN,
92
    s_U2X_FULL,
93
    s_U2X_AM_FULL,
94
    s_U2X_EMPTY,
95 29 nussgipfel
    s_U2X_AM_EMPTY  : std_logic;
96
  signal s_U2X_DATA : std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
97 18 nussgipfel
 
98
  -- Xilinx to USB (X2U)
99 12 nussgipfel
  signal s_X2U_WR_EN,
100 18 nussgipfel
    s_X2U_RD_EN,
101
    s_X2U_FULL,
102
    s_X2U_AM_FULL,
103
    s_X2U_EMPTY,
104 29 nussgipfel
    s_X2U_AM_EMPTY  : std_logic;
105
  signal s_X2U_DATA : std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
106 30 nussgipfel
 
107
  signal s_dbus_out_mux_sel : std_logic;
108 18 nussgipfel
 
109
  -----------------------------------------------------------------------------
110 11 nussgipfel
  -- data bus
111 18 nussgipfel
  -----------------------------------------------------------------------------
112 11 nussgipfel
 
113
  -- data signals
114 29 nussgipfel
  signal s_dbus_trans_dir : std_logic;
115
  signal s_dbus_in        : std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
116
  signal s_dbus_out       : std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
117 30 nussgipfel
 
118
  signal s_fifo_out       : std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
119
  signal s_fifo_old       : std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
120 14 nussgipfel
 
121 11 nussgipfel
  -----------------------------------------------------------------------------
122
  -- COMPONENTS
123
  -----------------------------------------------------------------------------
124
 
125 14 nussgipfel
  -- FSM GPIF
126
  component gpif_com_fsm
127 18 nussgipfel
    port (
128 30 nussgipfel
      i_nReset           : in  std_logic;
129
      i_IFCLK            : in  std_logic;
130
      i_WRU              : in  std_logic;
131
      i_RDYU             : in  std_logic;
132
      i_EOM              : in  std_logic;
133
      i_U2X_FULL         : in  std_logic;
134
      i_U2X_AM_FULL      : in  std_logic;
135
      i_X2U_AM_EMPTY     : in  std_logic;
136
      i_X2U_EMPTY        : in  std_logic;
137
      o_dbus_out_mux_sel : out std_logic;
138
      o_bus_trans_dir    : out std_logic;
139
      o_U2X_WR_EN        : out std_logic;
140
      o_X2U_RD_EN        : out std_logic;
141
      o_FIFOrst          : out std_logic;
142
      o_WRX              : out std_logic;
143
      o_RDYX             : out std_logic;
144
      o_ABORT            : out std_logic;
145
      o_RX               : out std_logic;
146
      o_TX               : out std_logic);
147 14 nussgipfel
  end component;
148 11 nussgipfel
 
149 14 nussgipfel
  -- FIFO dualclock to cross the clock domain between the GPIF and the FPGA
150
  component fifo_dualclock
151 18 nussgipfel
    port (
152
      i_din          : IN  std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
153
      i_rd_clk       : IN  std_logic;
154
      i_rd_en        : IN  std_logic;
155
      i_rst          : IN  std_logic;
156
      i_wr_clk       : IN  std_logic;
157
      i_wr_en        : IN  std_logic;
158
      o_almost_empty : OUT std_logic;
159
      o_almost_full  : OUT std_logic;
160
      o_dout         : OUT std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
161
      o_empty        : OUT std_logic;
162
      o_full         : OUT std_logic);
163 14 nussgipfel
  end component;
164
 
165 11 nussgipfel
 
166
begin
167
 
168
  -----------------------------------------------------------------------------
169
  -- Port map
170
  -----------------------------------------------------------------------------
171
 
172 14 nussgipfel
  F_IN : fifo_dualclock
173 18 nussgipfel
    port map (
174
      i_din          => s_dbus_in,
175
      i_rd_clk       => i_SYSCLK,
176
      i_rd_en        => s_U2X_RD_EN,
177
      i_rst          => s_FIFOrst,
178
      i_wr_clk       => i_IFCLK ,
179
      i_wr_en        => s_U2X_WR_EN,
180
      o_almost_empty => s_U2X_AM_EMPTY,
181
      o_almost_full  => s_U2X_AM_FULL,
182
      o_dout         => s_U2X_DATA,
183
      o_empty        => s_U2X_EMPTY,
184
      o_full         => s_U2X_FULL
185
      );
186 11 nussgipfel
 
187
 
188 14 nussgipfel
  F_OUT : fifo_dualclock
189 18 nussgipfel
    port map (
190
      i_din          => s_X2U_DATA,
191
      i_rd_clk       => i_IFCLK,
192
      i_rd_en        => s_X2U_RD_EN,
193
      i_rst          => s_FIFOrst,
194
      i_wr_clk       => i_SYSCLK,
195
      i_wr_en        => s_X2U_WR_EN,
196
      o_almost_empty => s_X2U_AM_EMPTY,
197
      o_almost_full  => s_X2U_AM_FULL,
198 30 nussgipfel
      o_dout         => s_fifo_out,
199 18 nussgipfel
      o_empty        => s_X2U_EMPTY,
200
      o_full         => s_X2U_FULL
201
      );
202 11 nussgipfel
 
203 12 nussgipfel
 
204 14 nussgipfel
  FSM_GPIF : gpif_com_fsm
205 18 nussgipfel
    port map (
206 30 nussgipfel
      i_nReset           => i_nReset,
207
      i_IFCLK            => i_IFCLK,
208
      i_WRU              => i_WRU,
209
      i_RDYU             => i_RDYU,
210 24 nussgipfel
      --i_EOM            => s_EOM,
211 30 nussgipfel
      i_EOM              => s_EOM_FF,
212
      i_U2X_FULL         => s_U2X_FULL,
213
      i_U2X_AM_FULL      => s_U2X_AM_FULL,
214
      i_X2U_AM_EMPTY     => s_X2U_AM_EMPTY,
215
      i_X2U_EMPTY        => s_X2U_EMPTY,
216
      o_U2X_WR_EN        => s_U2X_WR_EN,
217
      o_X2U_RD_EN        => s_X2U_RD_EN,
218
      o_dbus_out_mux_sel => s_dbus_out_mux_sel,
219
      o_FIFOrst          => s_FIFOrst,
220
      o_bus_trans_dir    => s_dbus_trans_dir,
221
      o_WRX              => s_WRX,
222
      o_RDYX             => s_RDYX,
223
      o_ABORT            => s_ABORT_FSM,
224
      o_RX               => s_RX_FSM,
225
      o_TX               => s_TX_FSM
226 18 nussgipfel
      );
227 11 nussgipfel
 
228 18 nussgipfel
 
229
 
230
  s_U2X_RD_EN  <= i_RD_EN;
231
  o_EMPTY   <= s_U2X_EMPTY;
232
  o_RX_DATA <= s_U2X_DATA;
233
 
234
  s_X2U_WR_EN <= i_WR_EN;
235
  o_FULL    <= s_X2U_FULL;
236
  s_X2U_DATA <= i_TX_DATA;
237
 
238
  o_WRX <= s_WRX;
239
  o_RDYX <= s_RDYX;
240
 
241 14 nussgipfel
  -- Double buffer the ABORT, RX and TX signal to avoid metastability
242
  double_buf_sig : process (i_SYSCLK, i_nReset)
243
  begin
244
    if i_nReset = '0' then
245 18 nussgipfel
      o_ABORT     <= '0';
246 14 nussgipfel
      s_ABORT_TMP <= '0';
247 18 nussgipfel
      o_TX        <= '0';
248
      s_TX_TMP    <= '0';
249
      o_RX        <= '0';
250
      s_RX_TMP    <= '0';
251
    elsif rising_edge(i_SYSCLK) then
252
      o_ABORT     <= s_ABORT_TMP;
253 14 nussgipfel
      s_ABORT_TMP <= s_ABORT_FSM;
254 18 nussgipfel
      o_TX        <= s_TX_TMP;
255
      s_TX_TMP    <= s_TX_FSM;
256
      o_RX        <= s_RX_TMP;
257
      s_RX_TMP    <= s_RX_FSM;
258 14 nussgipfel
    end if;
259
  end process double_buf_sig;
260 11 nussgipfel
 
261 22 nussgipfel
  -- Double buffer the s_EOM and s_X2U_FULL_IFCLK signal to avoid metastability
262 20 nussgipfel
  double_buf_ifclk : process (i_IFCLK, i_nReset)
263
  begin
264
    if i_nReset = '0' then
265 30 nussgipfel
      s_EOM <= '0';
266 20 nussgipfel
    elsif rising_edge(i_IFCLK) then
267
      s_EOM     <= s_EOM_TMP;
268
      s_EOM_TMP <= i_EOM;
269
    end if;
270
  end process double_buf_ifclk;
271 11 nussgipfel
 
272 24 nussgipfel
  --purpose: EOM bit flip-flop
273
  --type   : sequential
274
  --inputs : i_IFCLK, i_nReset, s_EOM, s_X2U_EMPTY
275
  --outputs: s_EOM_FF
276 22 nussgipfel
  EOM_FF: process (i_IFCLK, i_nReset)
277
  begin  -- process EOM_FF
278
    if i_nReset = '0' then                -- asynchronous reset (active low)
279
      s_EOM_FF <= '0';
280
    elsif i_IFCLK'event and i_IFCLK = '1' then  -- rising clock edge
281
      if s_EOM = '1' then
282
        s_EOM_FF <= '1';
283
      end if;
284 28 nussgipfel
      if s_X2U_EMPTY = '1' and s_TX_FSM = '0' then
285 22 nussgipfel
        s_EOM_FF <= '0';
286
      end if;
287
    end if;
288
  end process EOM_FF;
289
 
290
  -----------------------------------------------------------------------------
291
  -- Data bus access
292
  -----------------------------------------------------------------------------
293 20 nussgipfel
 
294 22 nussgipfel
  -- purpose: to handle the access on the bidirectional bus
295
  -- type   : combinational
296
  -- inputs : s_bus_trans_dir
297
  -- outputs: 
298 14 nussgipfel
  bus_access : process (s_dbus_trans_dir, s_dbus_out)
299
  begin  -- process bus_access
300
    if s_dbus_trans_dir = '1' then
301 18 nussgipfel
      b_gpif_bus <= s_dbus_out;
302 14 nussgipfel
    else
303 18 nussgipfel
      b_gpif_bus <= (others => 'Z');
304 14 nussgipfel
    end if;
305
  end process bus_access;
306 18 nussgipfel
 
307 19 nussgipfel
  -- buffer the gpif bus input signals to avoid that the last word in the
308
  -- usb to xilinx transfer is read twice.
309
  buf_input : process (i_IFCLK)
310
  begin
311
    if rising_edge(i_IFCLK) then
312
      s_dbus_in <= b_gpif_bus;
313 29 nussgipfel
 
314
      if s_X2U_RD_EN = '1' then
315 30 nussgipfel
        s_fifo_old <= s_fifo_out;
316 29 nussgipfel
      end if;
317 19 nussgipfel
    end if;
318
  end process buf_input;
319 30 nussgipfel
 
320
  -- purpose: multiplexer to select two older copies of fifo data
321
  -- type   : combinational
322
  -- inputs : s_dbus_out_mux_sel, s_fifo_old, s_fifo_out
323
  -- outputs: s_dbus_out
324
  dbus_out_mux: process (s_dbus_out_mux_sel, s_fifo_old, s_fifo_out)
325
  begin  -- process dbus_out_mux
326
    case s_dbus_out_mux_sel is
327
      when '0' => s_dbus_out <= s_fifo_out;
328
      when '1' => s_dbus_out <= s_fifo_old;
329
      when others => s_dbus_out <= s_fifo_out;
330
    end case;
331
  end process dbus_out_mux;
332 19 nussgipfel
 
333 14 nussgipfel
end structure;

powered by: WebSVN 2.1.0

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