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

Subversion Repositories gecko3

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

Go to most recent revision | 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
--      FSM that controls the interface between the EZ-USB (and it's internal
31
--      GPIF, General Purpose Interface) and our FPGA. The interface is
32
--      synchronous, where the GPIF provides the clock. This FSM is synchronous
33
--      to the GPIF clock, also this side of the FIFO's.
34 14 nussgipfel
--
35 18 nussgipfel
--    You can find more detailed information how the interface works in the
36
--    ../Doc folder.
37 14 nussgipfel
--
38 18 nussgipfel
--  Target Devices:     general
39
--  Tool versions:      Xilinx ISE 11.1, XST
40 14 nussgipfel
--  Dependencies:
41
--
42 18 nussgipfel
-------------------------------------------------------------------------------
43 14 nussgipfel
 
44 11 nussgipfel
library ieee;
45
use ieee.std_logic_1164.all;
46
use ieee.std_logic_arith.all;
47
 
48
library work;
49 14 nussgipfel
use work.GECKO3COM_defines.all;
50 11 nussgipfel
 
51 14 nussgipfel
entity gpif_com_fsm is
52 11 nussgipfel
  port (
53 18 nussgipfel
    i_nReset        : in  std_logic;
54
    i_IFCLK         : in  std_logic;  -- GPIF CLK (GPIF is Master and provides the clock)
55
    i_WRU           : in  std_logic;    -- write from GPIF
56
    i_RDYU          : in  std_logic;    -- GPIF is ready
57
    i_U2X_FULL      : in  std_logic;
58
    i_U2X_AM_FULL   : in  std_logic;    -- signals for IN FIFO
59
    i_X2U_AM_EMPTY  : in  std_logic;
60
    i_X2U_EMPTY     : in  std_logic;    -- signals for OUT FIFO
61
    o_bus_trans_dir : out std_logic;
62
    o_U2X_WR_EN     : out std_logic;    -- signals for IN FIFO
63
    o_X2U_RD_EN     : out std_logic;    -- signals for OUT FIFO
64
    o_FIFOrst       : out std_logic;
65
    o_WRX           : out std_logic;    -- To write to GPIF
66
    o_RDYX          : out std_logic;    -- Core is ready
67
    o_ABORT         : out std_logic;  -- abort condition detected. we have to flush the data
68
    o_RX            : out std_logic;
69
    o_TX            : out std_logic     --
70
    );
71
 
72
  -- XST specific synthesize attributes
73
  attribute safe_implementation: string;
74
  attribute safe_recovery_state: string;
75
 
76
  attribute safe_implementation of gpif_com_fsm : entity is "yes";
77
 
78 14 nussgipfel
end gpif_com_fsm;
79 11 nussgipfel
 
80
 
81
 
82 14 nussgipfel
architecture fsm of gpif_com_fsm is
83 11 nussgipfel
 
84 18 nussgipfel
  -----------------------------------------------------------------------------
85 11 nussgipfel
  -- FSM
86
  -----------------------------------------------------------------------------
87
 
88 18 nussgipfel
  type   t_busAccess is (readFromGPIF, writeToGPIF);
89 14 nussgipfel
  signal s_bus_trans_dir : t_busAccess;
90
 
91
 
92 18 nussgipfel
  type t_fsmState is (rst, idle,        -- controll states
93
                      inRQ, inACK, inTrans, inThrot,
94
                      inThrotEnd, endInTrans,  -- in com states
95
                      outRQ, outTrans, outWait, endOutTrans);  -- out com states
96 11 nussgipfel
 
97 18 nussgipfel
 
98
 
99 11 nussgipfel
  signal pr_state, nx_state : t_fsmState;
100 18 nussgipfel
  -- XST specific synthesize attributes
101
  attribute safe_recovery_state of pr_state : signal is "idle";
102
  attribute safe_recovery_state of nx_state : signal is "idle";
103 11 nussgipfel
 
104 18 nussgipfel
 
105 11 nussgipfel
  -- interconection signals
106 18 nussgipfel
  signal s_FIFOrst, s_RDYX, s_WRX, s_ABORT : std_logic;
107 11 nussgipfel
 
108 18 nussgipfel
  -- USB to Xilinx (U2X)
109 12 nussgipfel
  signal s_U2X_WR_EN : std_logic;
110 11 nussgipfel
 
111 18 nussgipfel
  -- Xilinx to USB (X2U)
112
  signal s_X2U_RD_EN : std_logic;
113
 
114 11 nussgipfel
begin
115
 
116 18 nussgipfel
  o_FIFOrst       <= s_FIFOrst;
117
  o_X2U_RD_EN     <= s_X2U_RD_EN;
118
  o_WRX           <= s_WRX;
119
  o_RDYX          <= s_RDYX;
120
  o_U2X_WR_EN     <= s_U2X_WR_EN;
121 14 nussgipfel
  o_bus_trans_dir <= '1' when s_bus_trans_dir = writeToGPIF else '0';
122 18 nussgipfel
  o_ABORT         <= s_ABORT;
123 11 nussgipfel
 
124 18 nussgipfel
 
125 11 nussgipfel
  -----------------------------------------------------------------------------
126
  -- FSM GPIF
127
  -----------------------------------------------------------------------------
128
 
129 18 nussgipfel
  -- state reg
130 11 nussgipfel
  action : process(i_IFCLK, i_nReset)
131 18 nussgipfel
    variable v_setup : integer range 0 to 15;
132
  begin
133 11 nussgipfel
 
134 18 nussgipfel
    if i_nReset = '0' then
135
      pr_state <= rst;
136
 
137
    elsif rising_edge(i_IFCLK) then
138
        pr_state <= nx_state;
139
    end if;
140
  end process action;
141 11 nussgipfel
 
142
 
143 18 nussgipfel
  -- comb logic
144
  transaction : process(pr_state, i_WRU, i_RDYU, i_U2X_AM_FULL, i_X2U_EMPTY)
145
  begin  -- process transaction
146 11 nussgipfel
 
147 18 nussgipfel
    -- default signal values to avoid latches:
148
    s_FIFOrst       <= '0';
149
    s_bus_trans_dir <= readFromGPIF;
150
    s_U2X_WR_EN     <= '0';
151
    s_X2U_RD_EN     <= '0';
152
    nx_state        <= idle;
153
    s_WRX           <= '0';
154
    s_RDYX          <= '0';
155
    s_ABORT         <= '0';
156
    o_RX            <= '0';
157
    o_TX            <= '0';
158
 
159
    case pr_state is
160
      -- controll
161
 
162
      when rst =>
163
        -- output signal values:
164
        s_FIFOrst   <= '1';
165
        s_WRX       <= '0';
166
        s_RDYX      <= '0';
167
        s_U2X_WR_EN <= '0';
168
        s_X2U_RD_EN <= '0';
169
        s_ABORT     <= '1';
170
        o_RX        <= '0';
171
        o_TX        <= '0';
172
 
173
        s_bus_trans_dir <= readFromGPIF;
174
 
175
        -- state decisions
176
        if i_WRU = '1' and i_RDYU = '1' then
177
          nx_state <= rst;
178
        else
179
          nx_state <= idle;
180
        end if;
181 11 nussgipfel
 
182 18 nussgipfel
      when idle =>
183
        -- output signal values:
184
        s_FIFOrst       <= '0';
185
        s_WRX           <= '0';
186
        s_RDYX          <= '0';
187
        s_U2X_WR_EN     <= '0';
188
        s_X2U_RD_EN     <= '0';
189
        s_bus_trans_dir <= readFromGPIF;
190 11 nussgipfel
 
191 18 nussgipfel
        -- state decisions
192
        if i_WRU = '1' and i_RDYU = '1' then
193
          nx_state <= rst;
194
        elsif i_WRU = '1' and i_RDYU = '0' then
195
          nx_state <= inRQ;
196
        elsif i_WRU = '0' and i_X2U_EMPTY = '0' then
197
          nx_state <= outRQ;
198
        else
199
          nx_state <= idle;
200
        end if;
201
 
202 11 nussgipfel
        -- in trans
203 18 nussgipfel
      when inRQ =>
204
        -- output signal values:
205
        s_WRX  <= '0';
206
        s_RDYX <= '0';
207
        -- state decisions
208
        if i_WRU = '1' and i_RDYU = '1' then
209
          nx_state <= rst;
210
        elsif i_U2X_FULL = '0' then
211
          nx_state <= inACK;
212
        else
213
          nx_state <= idle;
214
        end if;
215 11 nussgipfel
 
216 18 nussgipfel
      when inACK =>
217
        -- output signal values:
218
        s_WRX       <= '0';
219
        s_RDYX      <= '1';
220
        s_U2X_WR_EN <= '1';
221
        o_RX        <= '1';
222 11 nussgipfel
 
223 18 nussgipfel
        -- state decisions
224
        if i_WRU = '1' and i_RDYU = '1' then
225
          nx_state <= rst;
226
        elsif i_WRU = '1' then
227
          nx_state <= inTrans;
228
          --nx_state <= inDummy;
229
        else
230
          nx_state <= endInTrans;
231
        end if;
232
 
233
      when inTrans =>
234
        -- output signal values:
235
        s_WRX       <= '0';
236
        s_RDYX      <= '1';
237
        s_U2X_WR_EN <= '1';
238
        o_RX        <= '1';
239 11 nussgipfel
 
240 18 nussgipfel
        -- state decisions
241
        if i_WRU = '1' and i_RDYU = '1' then
242
          nx_state <= rst;
243
        elsif i_WRU = '0' then
244
          nx_state <= endInTrans;
245
        elsif i_U2X_FULL = '1' then
246
          nx_state <= inThrot;
247
        else
248
          nx_state <= inTrans;
249
        end if;
250 11 nussgipfel
 
251 18 nussgipfel
      when inThrot =>
252
        -- output signal values:
253
        s_WRX       <= '0';
254
        s_RDYX      <= '0';
255
        s_U2X_WR_EN <= '0';
256
        o_RX        <= '1';
257 11 nussgipfel
 
258 18 nussgipfel
        -- state decisions
259
        if i_WRU = '1' and i_RDYU = '1' then
260
          nx_state <= rst;
261
        elsif i_U2X_FULL = '0' then
262
          --nx_state <= inThrotEnd;
263
          nx_state <= inACK;
264
        elsif i_WRU = '0' then
265
          nx_state <= endInTrans;
266
        else
267
          nx_state <= inThrot;
268
        end if;
269 11 nussgipfel
 
270 18 nussgipfel
      --when inThrotEnd =>
271
      --  -- this is a one clock delay to help the fx2 to see the RDYX signal.
272
 
273
      --  -- output signal values:
274
      --  s_WRX       <= '0';
275
      --  s_RDYX      <= '1';
276
      --  s_U2X_WR_EN <= '0';
277
      --  o_RX        <= '1';
278
 
279
      --  -- state decisions 
280
      --  nx_state <= inACK;
281
 
282
      when endInTrans =>
283
        -- output signal values:
284
        s_WRX       <= '0';
285
        s_RDYX      <= '0';
286
        s_U2X_WR_EN <= '1';
287
 
288
        -- state decisions
289
        nx_state <= idle;
290
 
291
 
292 11 nussgipfel
        -- out trans
293 18 nussgipfel
      when outRQ =>
294
        -- output signal values:
295
        s_WRX  <= '1';
296
        s_RDYX <= '0';
297
 
298
        -- state decisions
299
        if i_WRU = '1' and i_RDYU = '1' then
300
          nx_state <= rst;
301
        elsif i_WRU = '1' and i_RDYU = '0' then
302
          nx_state <= inRQ;
303
        elsif i_WRU = '0' and i_RDYU = '0' then  -- vervollständigt, wenn ez-usb noch beschäfigt mit altem transfer
304
          --s_X2U_RD_EN <= '1';
305
          nx_state    <= outTrans;
306 11 nussgipfel
--            s_bus_trans_dir <= writeToGPIF;
307 18 nussgipfel
        else
308
          nx_state <= outRQ;
309
        end if;
310 11 nussgipfel
 
311
 
312 18 nussgipfel
      when outTrans =>
313
        -- output signal values:
314
        s_WRX           <= '1';
315
        s_RDYX          <= '0';
316
        s_X2U_RD_EN     <= '1';
317
        s_bus_trans_dir <= writeToGPIF;
318
        o_TX            <= '1';
319
 
320
        -- state decisions
321
        if i_WRU = '1' and i_RDYU = '1' then
322
          nx_state        <= rst;
323
        elsif i_X2U_EMPTY = '1' then
324
          nx_state <= endOutTrans;
325
        elsif i_WRU = '0' and i_RDYU = '1' then
326
          nx_state <= outTrans;
327
        else
328
          --s_X2U_RD_EN <= '0';           -- to realise a wait case
329
          nx_state    <= outWait;
330
        end if;
331
 
332
      when outWait =>
333
        -- output signal values:
334
        s_WRX       <= '1';
335
        s_RDYX      <= '0';
336
        s_X2U_RD_EN <= '0';
337
        o_TX        <= '1';
338
        s_bus_trans_dir <= writeToGPIF;
339
 
340
        -- state decisions
341
        if i_WRU = '1' and i_RDYU = '1' then
342
          nx_state <= rst;
343
        elsif i_WRU = '0' and i_RDYU = '1' then
344
          nx_state <= outTrans;
345
        else
346
          nx_state <= outWait;
347
        end if;
348
 
349
      when endOutTrans =>
350
        -- output signal values:
351
        s_RDYX          <= '0';
352
        s_WRX           <= '1';  -- nötig um letzte 16bit an ez-usb zu schreiben
353
        s_X2U_RD_EN     <= '1';  -- nötig da empyte flag schon beim ersten fifo zugriff auftaucht, zweite 16bit müssen noch gelesen werden
354
        s_bus_trans_dir <= writeToGPIF;
355
 
356
        -- state decisions
357
        nx_state        <= idle;
358
 
359 11 nussgipfel
        -- error case
360 18 nussgipfel
      when others =>
361
        nx_state <= idle;
362
    end case;
363 11 nussgipfel
 
364 18 nussgipfel
  end process transaction;
365
 
366
end fsm;

powered by: WebSVN 2.1.0

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