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 28

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 20 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_EOM            : in  std_logic;   -- all data for X2U transfer is in FIFO
58
    i_U2X_FULL       : in  std_logic;
59
    i_U2X_AM_FULL    : in  std_logic;   -- signals for IN FIFO
60
    i_X2U_FULL_IFCLK : in  std_logic;
61
    i_X2U_AM_EMPTY   : in  std_logic;
62
    i_X2U_EMPTY      : in  std_logic;   -- signals for OUT FIFO
63
    o_bus_trans_dir  : out std_logic;
64
    o_U2X_WR_EN      : out std_logic;   -- signals for IN FIFO
65
    o_X2U_RD_EN      : out std_logic;   -- signals for OUT FIFO
66
    o_FIFOrst        : out std_logic;
67
    o_WRX            : out std_logic;   -- To write to GPIF
68
    o_RDYX           : out std_logic;   -- Core is ready
69
    o_ABORT          : out std_logic;  -- abort condition detected. we have to flush the data
70
    o_RX             : out std_logic;
71
    o_TX             : out std_logic    --
72 18 nussgipfel
    );
73
 
74 14 nussgipfel
end gpif_com_fsm;
75 11 nussgipfel
 
76
 
77
 
78 14 nussgipfel
architecture fsm of gpif_com_fsm is
79 11 nussgipfel
 
80 19 nussgipfel
  -- XST specific synthesize attributes
81
  attribute safe_implementation: string;
82
  attribute safe_recovery_state: string;
83 27 nussgipfel
 
84 19 nussgipfel
 
85 18 nussgipfel
  -----------------------------------------------------------------------------
86 11 nussgipfel
  -- FSM
87
  -----------------------------------------------------------------------------
88
 
89 18 nussgipfel
  type   t_busAccess is (readFromGPIF, writeToGPIF);
90 14 nussgipfel
  signal s_bus_trans_dir : t_busAccess;
91
 
92
 
93 18 nussgipfel
  type t_fsmState is (rst, idle,        -- controll states
94 28 nussgipfel
                      -- in com states
95 19 nussgipfel
                      inRQ, inACK, inWait, inTrans, inThrot,
96 28 nussgipfel
                      inThrotBreak, inThrotEnd,
97
                      endInTrans,
98
                      -- out com states
99
                      outRQ, outRQdelay, outTrans, outACK, outACKwait,
100
                      outUSBwait, outUSBwaitEnd, outFIFOwait, endOutTrans);
101 11 nussgipfel
 
102 18 nussgipfel
 
103
 
104 11 nussgipfel
  signal pr_state, nx_state : t_fsmState;
105 18 nussgipfel
  -- XST specific synthesize attributes
106
  attribute safe_recovery_state of pr_state : signal is "idle";
107 19 nussgipfel
  attribute safe_implementation of pr_state : signal is "yes";
108
 
109 18 nussgipfel
 
110 11 nussgipfel
  -- interconection signals
111 18 nussgipfel
  signal s_FIFOrst, s_RDYX, s_WRX, s_ABORT : std_logic;
112 11 nussgipfel
 
113 18 nussgipfel
  -- USB to Xilinx (U2X)
114 12 nussgipfel
  signal s_U2X_WR_EN : std_logic;
115 11 nussgipfel
 
116 18 nussgipfel
  -- Xilinx to USB (X2U)
117
  signal s_X2U_RD_EN : std_logic;
118
 
119 11 nussgipfel
begin
120
 
121 19 nussgipfel
 
122
 
123 18 nussgipfel
  o_FIFOrst       <= s_FIFOrst;
124
  o_X2U_RD_EN     <= s_X2U_RD_EN;
125
  o_WRX           <= s_WRX;
126
  o_RDYX          <= s_RDYX;
127
  o_U2X_WR_EN     <= s_U2X_WR_EN;
128 14 nussgipfel
  o_bus_trans_dir <= '1' when s_bus_trans_dir = writeToGPIF else '0';
129 18 nussgipfel
  o_ABORT         <= s_ABORT;
130 11 nussgipfel
 
131 18 nussgipfel
 
132 11 nussgipfel
  -----------------------------------------------------------------------------
133
  -- FSM GPIF
134
  -----------------------------------------------------------------------------
135
 
136 18 nussgipfel
  -- state reg
137 11 nussgipfel
  action : process(i_IFCLK, i_nReset)
138 18 nussgipfel
  begin
139 11 nussgipfel
 
140 18 nussgipfel
    if i_nReset = '0' then
141
      pr_state <= rst;
142
 
143
    elsif rising_edge(i_IFCLK) then
144
        pr_state <= nx_state;
145
    end if;
146
  end process action;
147 11 nussgipfel
 
148
 
149 18 nussgipfel
  -- comb logic
150 20 nussgipfel
  transaction : process(pr_state, i_WRU, i_RDYU, i_U2X_FULL, i_U2X_AM_FULL,
151
                        i_X2U_EMPTY, i_X2U_FULL_IFCLK, i_EOM)
152 18 nussgipfel
  begin  -- process transaction
153 11 nussgipfel
 
154 18 nussgipfel
    -- default signal values to avoid latches:
155
    s_FIFOrst       <= '0';
156
    s_bus_trans_dir <= readFromGPIF;
157
    s_U2X_WR_EN     <= '0';
158
    s_X2U_RD_EN     <= '0';
159
    nx_state        <= idle;
160
    s_WRX           <= '0';
161
    s_RDYX          <= '0';
162
    s_ABORT         <= '0';
163
    o_RX            <= '0';
164
    o_TX            <= '0';
165
 
166
    case pr_state is
167
      -- controll
168
 
169
      when rst =>
170
        -- output signal values:
171
        s_FIFOrst   <= '1';
172
        s_WRX       <= '0';
173
        s_RDYX      <= '0';
174
        s_U2X_WR_EN <= '0';
175
        s_X2U_RD_EN <= '0';
176
        s_ABORT     <= '1';
177
        o_RX        <= '0';
178
        o_TX        <= '0';
179
        s_bus_trans_dir <= readFromGPIF;
180
 
181
        -- state decisions
182
        if i_WRU = '1' and i_RDYU = '1' then
183
          nx_state <= rst;
184
        else
185
          nx_state <= idle;
186
        end if;
187 11 nussgipfel
 
188 18 nussgipfel
      when idle =>
189
        -- output signal values:
190
        s_FIFOrst       <= '0';
191
        s_WRX           <= '0';
192
        s_RDYX          <= '0';
193
        s_U2X_WR_EN     <= '0';
194
        s_X2U_RD_EN     <= '0';
195
        s_bus_trans_dir <= readFromGPIF;
196 11 nussgipfel
 
197 18 nussgipfel
        -- state decisions
198
        if i_WRU = '1' and i_RDYU = '1' then
199
          nx_state <= rst;
200
        elsif i_WRU = '1' and i_RDYU = '0' then
201
          nx_state <= inRQ;
202 20 nussgipfel
        elsif i_WRU = '0' and
203
          (i_X2U_FULL_IFCLK = '1' or i_EOM = '1') and i_X2U_EMPTY = '0' then
204 18 nussgipfel
          nx_state <= outRQ;
205
        else
206
          nx_state <= idle;
207
        end if;
208
 
209 20 nussgipfel
        -----------------------------------------------------------------------
210 11 nussgipfel
        -- in trans
211 28 nussgipfel
      when inRQ =>
212 18 nussgipfel
        -- output signal values:
213 28 nussgipfel
        s_WRX       <= '0';
214
        s_RDYX      <= '0';
215 19 nussgipfel
        s_U2X_WR_EN <= '0';
216
        o_RX        <= '0';
217
 
218 18 nussgipfel
        -- state decisions
219
        if i_WRU = '1' and i_RDYU = '1' then
220
          nx_state <= rst;
221
        elsif i_U2X_FULL = '0' then
222
          nx_state <= inACK;
223
        else
224
          nx_state <= idle;
225
        end if;
226 11 nussgipfel
 
227 18 nussgipfel
      when inACK =>
228
        -- output signal values:
229
        s_WRX       <= '0';
230
        s_RDYX      <= '1';
231 19 nussgipfel
        s_U2X_WR_EN <= '0';
232 18 nussgipfel
        o_RX        <= '1';
233 11 nussgipfel
 
234 18 nussgipfel
        -- state decisions
235
        if i_WRU = '1' and i_RDYU = '1' then
236
          nx_state <= rst;
237
        elsif i_WRU = '1' then
238 19 nussgipfel
          nx_state <= inWait;
239 18 nussgipfel
        else
240
          nx_state <= endInTrans;
241
        end if;
242 19 nussgipfel
 
243
        when inWait =>
244
        -- output signal values:
245
        s_WRX       <= '0';
246
        s_RDYX      <= '1';
247
        s_U2X_WR_EN <= '0';
248
        o_RX        <= '1';
249
 
250
        -- state decisions
251
        nx_state <= inTrans;
252 18 nussgipfel
 
253
      when inTrans =>
254
        -- output signal values:
255
        s_WRX       <= '0';
256
        s_RDYX      <= '1';
257
        s_U2X_WR_EN <= '1';
258
        o_RX        <= '1';
259 11 nussgipfel
 
260 18 nussgipfel
        -- state decisions
261
        if i_WRU = '1' and i_RDYU = '1' then
262
          nx_state <= rst;
263
        elsif i_WRU = '0' then
264
          nx_state <= endInTrans;
265 20 nussgipfel
        elsif i_U2X_AM_FULL = '1' then
266 18 nussgipfel
          nx_state <= inThrot;
267
        else
268
          nx_state <= inTrans;
269
        end if;
270 11 nussgipfel
 
271 18 nussgipfel
      when inThrot =>
272
        -- output signal values:
273
        s_WRX       <= '0';
274
        s_RDYX      <= '0';
275
        s_U2X_WR_EN <= '0';
276
        o_RX        <= '1';
277 11 nussgipfel
 
278 18 nussgipfel
        -- state decisions
279
        if i_WRU = '1' and i_RDYU = '1' then
280
          nx_state <= rst;
281 20 nussgipfel
        elsif i_U2X_AM_FULL = '0' then
282 19 nussgipfel
          nx_state <= inThrotBreak;
283 20 nussgipfel
          --nx_state <= inThrotEnd;
284 18 nussgipfel
        elsif i_WRU = '0' then
285
          nx_state <= endInTrans;
286
        else
287
          nx_state <= inThrot;
288
        end if;
289 11 nussgipfel
 
290 19 nussgipfel
      when inThrotBreak =>
291
        -- this is a one clock delay to help the fx2 to see the RDYX signal.
292
 
293
        -- output signal values:
294
        s_WRX       <= '0';
295
        s_RDYX      <= '1';
296
        s_U2X_WR_EN <= '0';
297
        o_RX        <= '1';
298
 
299
        -- state decisions 
300
        nx_state <= inThrotEnd;
301 18 nussgipfel
 
302 19 nussgipfel
      when inThrotEnd =>
303
        -- this is a one clock delay to help the fx2 to see the RDYX signal.
304
 
305
        -- output signal values:
306
        s_WRX       <= '0';
307
        s_RDYX      <= '1';
308
        s_U2X_WR_EN <= '0';
309
        o_RX        <= '1';
310
 
311
        -- state decisions 
312
        nx_state <= inTrans;
313
 
314 18 nussgipfel
      when endInTrans =>
315
        -- output signal values:
316
        s_WRX       <= '0';
317
        s_RDYX      <= '0';
318 19 nussgipfel
        s_U2X_WR_EN <= '0';
319
        o_RX        <= '0';
320 18 nussgipfel
 
321
        -- state decisions
322
        nx_state <= idle;
323
 
324 20 nussgipfel
        -----------------------------------------------------------------------
325 11 nussgipfel
        -- out trans
326 18 nussgipfel
      when outRQ =>
327
        -- output signal values:
328 20 nussgipfel
        s_WRX       <= '1';
329
        s_RDYX      <= '0';
330
        s_X2U_RD_EN <= '0';
331 18 nussgipfel
 
332
        -- state decisions
333
        if i_WRU = '1' and i_RDYU = '1' then
334
          nx_state <= rst;
335
        elsif i_WRU = '1' and i_RDYU = '0' then
336
          nx_state <= inRQ;
337
        else
338 27 nussgipfel
          nx_state <= outRQdelay;
339 18 nussgipfel
        end if;
340 11 nussgipfel
 
341 27 nussgipfel
      when outRQdelay =>
342
        -- output signal values:
343
        s_WRX       <= '1';
344
        s_RDYX      <= '0';
345
        s_X2U_RD_EN <= '0';
346
 
347
        -- state decisions
348
        if i_WRU = '1' and i_RDYU = '1' then
349
          nx_state <= rst;
350
        elsif i_WRU = '1' and i_RDYU = '0' then
351
          nx_state <= inRQ;
352
        else
353
          nx_state <= outACK;
354
        end if;
355
 
356 28 nussgipfel
      when outACK =>
357 20 nussgipfel
        -- output signal values:
358
        s_WRX       <= '1';
359
        s_RDYX      <= '0';
360
        s_X2U_RD_EN <= '1';
361
        o_TX        <= '1';
362 11 nussgipfel
 
363 20 nussgipfel
        -- state decisions
364
        if i_WRU = '1' and i_RDYU = '1' then
365
          nx_state <= rst;
366
        elsif i_WRU = '0' and i_RDYU = '1' then
367
          nx_state <= outTrans;
368
        else
369 28 nussgipfel
          nx_state <= outACKwait;
370
        end if;
371
 
372
      when outACKwait =>
373
        -- output signal values:
374
        s_WRX       <= '1';
375
        s_RDYX      <= '0';
376
        s_X2U_RD_EN <= '0';
377
        o_TX        <= '1';
378
 
379
        -- state decisions
380
        if i_WRU = '1' and i_RDYU = '1' then
381
          nx_state <= rst;
382
        elsif i_WRU = '0' and i_RDYU = '1' then
383
          nx_state <= outTrans;
384
        else
385
          nx_state <= outACKwait;
386 20 nussgipfel
        end if;
387 28 nussgipfel
 
388 18 nussgipfel
      when outTrans =>
389
        -- output signal values:
390
        s_WRX           <= '1';
391
        s_RDYX          <= '0';
392
        s_X2U_RD_EN     <= '1';
393 20 nussgipfel
        o_TX            <= '1';
394 18 nussgipfel
        s_bus_trans_dir <= writeToGPIF;
395
 
396
        -- state decisions
397
        if i_WRU = '1' and i_RDYU = '1' then
398
          nx_state        <= rst;
399 20 nussgipfel
        elsif i_X2U_EMPTY = '1' and i_EOM = '1' then
400 18 nussgipfel
          nx_state <= endOutTrans;
401 20 nussgipfel
        elsif i_X2U_EMPTY = '1' and i_EOM = '0' then
402
          nx_state <= outFIFOwait;
403 18 nussgipfel
        elsif i_WRU = '0' and i_RDYU = '1' then
404
          nx_state <= outTrans;
405
        else
406 28 nussgipfel
          nx_state <= outUSBwait;
407 18 nussgipfel
        end if;
408
 
409 20 nussgipfel
      when outUSBwait =>
410 18 nussgipfel
        -- output signal values:
411
        s_WRX       <= '1';
412
        s_RDYX      <= '0';
413
        s_X2U_RD_EN <= '0';
414
        o_TX        <= '1';
415
        s_bus_trans_dir <= writeToGPIF;
416
 
417
        -- state decisions
418
        if i_WRU = '1' and i_RDYU = '1' then
419
          nx_state <= rst;
420 27 nussgipfel
        elsif i_X2U_EMPTY = '1' and i_EOM = '1' then
421
          nx_state <= endOutTrans;
422 18 nussgipfel
        elsif i_WRU = '0' and i_RDYU = '1' then
423 28 nussgipfel
          nx_state <= outUSBwaitEnd;
424 18 nussgipfel
        else
425 20 nussgipfel
          nx_state <= outUSBwait;
426 18 nussgipfel
        end if;
427 28 nussgipfel
 
428
      when outUSBwaitEnd =>
429
        -- output signal values:
430
        s_WRX       <= '1';
431
        s_RDYX      <= '1';
432
        s_X2U_RD_EN <= '0';
433
        o_TX        <= '1';
434
        s_bus_trans_dir <= writeToGPIF;
435
 
436
        -- state decisions
437
        nx_state <= outTrans;
438 18 nussgipfel
 
439 20 nussgipfel
      when outFIFOwait =>
440
        -- output signal values:
441
        s_WRX       <= '1';
442
        s_RDYX      <= '1';
443
        s_X2U_RD_EN <= '0';
444
        o_TX        <= '1';
445
        s_bus_trans_dir <= writeToGPIF;
446
 
447
        -- state decisions
448
        if i_WRU = '1' and i_RDYU = '1' then
449
          nx_state <= rst;
450
        elsif i_X2U_EMPTY = '1' and i_EOM = '1' then
451
          nx_state <= endOutTrans;
452 27 nussgipfel
        elsif i_X2U_EMPTY = '0' then
453 20 nussgipfel
          nx_state <= outTrans;
454
        else
455
          nx_state <= outFIFOwait;
456
        end if;
457
 
458 18 nussgipfel
      when endOutTrans =>
459
        -- output signal values:
460
        s_RDYX          <= '0';
461 20 nussgipfel
        s_WRX           <= '0';
462
        s_X2U_RD_EN     <= '0';
463 18 nussgipfel
        s_bus_trans_dir <= writeToGPIF;
464
 
465
        -- state decisions
466 20 nussgipfel
        if i_RDYU = '0' then
467
          nx_state <= idle;
468
        else
469
          nx_state <= endOutTrans;
470
        end if;
471 18 nussgipfel
 
472 11 nussgipfel
        -- error case
473 18 nussgipfel
      when others =>
474
        nx_state <= idle;
475
    end case;
476 11 nussgipfel
 
477 18 nussgipfel
  end process transaction;
478
 
479
end fsm;

powered by: WebSVN 2.1.0

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