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 21

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
 
84
 
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 19 nussgipfel
                      inRQ, inACK, inWait, inTrans, inThrot,
95 20 nussgipfel
                      inThrotBreak,inThrotBreak2, inThrotEnd,
96
                      endInTrans,  -- in com states
97
                      outRQ, outTrans, outACK, outUSBwait, outFIFOwait,
98
                      endOutTrans);  -- out com states
99 11 nussgipfel
 
100 18 nussgipfel
 
101
 
102 11 nussgipfel
  signal pr_state, nx_state : t_fsmState;
103 18 nussgipfel
  -- XST specific synthesize attributes
104
  attribute safe_recovery_state of pr_state : signal is "idle";
105 19 nussgipfel
  attribute safe_implementation of pr_state : signal is "yes";
106 20 nussgipfel
 
107 19 nussgipfel
 
108 11 nussgipfel
 
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 21 nussgipfel
    variable state_number : std_logic_vector(3 downto 0);  -- debug information
153 18 nussgipfel
  begin  -- process transaction
154 11 nussgipfel
 
155 18 nussgipfel
    -- default signal values to avoid latches:
156
    s_FIFOrst       <= '0';
157
    s_bus_trans_dir <= readFromGPIF;
158
    s_U2X_WR_EN     <= '0';
159
    s_X2U_RD_EN     <= '0';
160
    nx_state        <= idle;
161
    s_WRX           <= '0';
162
    s_RDYX          <= '0';
163
    s_ABORT         <= '0';
164
    o_RX            <= '0';
165
    o_TX            <= '0';
166
 
167
    case pr_state is
168
      -- controll
169
 
170
      when rst =>
171 21 nussgipfel
        state_number := x"1";
172 18 nussgipfel
        -- output signal values:
173
        s_FIFOrst   <= '1';
174
        s_WRX       <= '0';
175
        s_RDYX      <= '0';
176
        s_U2X_WR_EN <= '0';
177
        s_X2U_RD_EN <= '0';
178
        s_ABORT     <= '1';
179
        o_RX        <= '0';
180
        o_TX        <= '0';
181
        s_bus_trans_dir <= readFromGPIF;
182
 
183
        -- state decisions
184
        if i_WRU = '1' and i_RDYU = '1' then
185
          nx_state <= rst;
186
        else
187
          nx_state <= idle;
188
        end if;
189 11 nussgipfel
 
190 18 nussgipfel
      when idle =>
191 21 nussgipfel
        state_number := x"2";
192 18 nussgipfel
        -- output signal values:
193
        s_FIFOrst       <= '0';
194
        s_WRX           <= '0';
195
        s_RDYX          <= '0';
196
        s_U2X_WR_EN     <= '0';
197
        s_X2U_RD_EN     <= '0';
198
        s_bus_trans_dir <= readFromGPIF;
199 11 nussgipfel
 
200 18 nussgipfel
        -- state decisions
201
        if i_WRU = '1' and i_RDYU = '1' then
202
          nx_state <= rst;
203
        elsif i_WRU = '1' and i_RDYU = '0' then
204
          nx_state <= inRQ;
205 20 nussgipfel
        elsif i_WRU = '0' and
206
          (i_X2U_FULL_IFCLK = '1' or i_EOM = '1') and i_X2U_EMPTY = '0' then
207 18 nussgipfel
          nx_state <= outRQ;
208
        else
209
          nx_state <= idle;
210
        end if;
211
 
212 20 nussgipfel
        -----------------------------------------------------------------------
213 11 nussgipfel
        -- in trans
214 18 nussgipfel
      when inRQ =>
215 21 nussgipfel
        state_number := x"3";
216 18 nussgipfel
        -- output signal values:
217
        s_WRX  <= '0';
218
        s_RDYX <= '0';
219 19 nussgipfel
        s_U2X_WR_EN <= '0';
220
        o_RX        <= '0';
221
 
222 18 nussgipfel
        -- state decisions
223
        if i_WRU = '1' and i_RDYU = '1' then
224
          nx_state <= rst;
225
        elsif i_U2X_FULL = '0' then
226
          nx_state <= inACK;
227
        else
228
          nx_state <= idle;
229
        end if;
230 11 nussgipfel
 
231 18 nussgipfel
      when inACK =>
232 21 nussgipfel
        state_number := x"4";
233 18 nussgipfel
        -- output signal values:
234
        s_WRX       <= '0';
235
        s_RDYX      <= '1';
236 19 nussgipfel
        s_U2X_WR_EN <= '0';
237 18 nussgipfel
        o_RX        <= '1';
238 11 nussgipfel
 
239 18 nussgipfel
        -- state decisions
240
        if i_WRU = '1' and i_RDYU = '1' then
241
          nx_state <= rst;
242
        elsif i_WRU = '1' then
243 19 nussgipfel
          --nx_state <= inTrans;
244
          nx_state <= inWait;
245 18 nussgipfel
        else
246
          nx_state <= endInTrans;
247
        end if;
248 19 nussgipfel
 
249
        when inWait =>
250 21 nussgipfel
        state_number := x"5";
251 19 nussgipfel
        -- output signal values:
252
        s_WRX       <= '0';
253
        s_RDYX      <= '1';
254
        s_U2X_WR_EN <= '0';
255
        o_RX        <= '1';
256
 
257
        -- state decisions
258
        nx_state <= inTrans;
259 18 nussgipfel
 
260
      when inTrans =>
261 21 nussgipfel
        state_number := x"6";
262 18 nussgipfel
        -- output signal values:
263
        s_WRX       <= '0';
264
        s_RDYX      <= '1';
265
        s_U2X_WR_EN <= '1';
266
        o_RX        <= '1';
267 11 nussgipfel
 
268 18 nussgipfel
        -- state decisions
269
        if i_WRU = '1' and i_RDYU = '1' then
270
          nx_state <= rst;
271
        elsif i_WRU = '0' then
272
          nx_state <= endInTrans;
273 20 nussgipfel
        elsif i_U2X_AM_FULL = '1' then
274 18 nussgipfel
          nx_state <= inThrot;
275
        else
276
          nx_state <= inTrans;
277
        end if;
278 11 nussgipfel
 
279 18 nussgipfel
      when inThrot =>
280 21 nussgipfel
        state_number := x"7";
281 18 nussgipfel
        -- output signal values:
282
        s_WRX       <= '0';
283
        s_RDYX      <= '0';
284
        s_U2X_WR_EN <= '0';
285
        o_RX        <= '1';
286 11 nussgipfel
 
287 18 nussgipfel
        -- state decisions
288
        if i_WRU = '1' and i_RDYU = '1' then
289
          nx_state <= rst;
290 20 nussgipfel
        elsif i_U2X_AM_FULL = '0' then
291 19 nussgipfel
          nx_state <= inThrotBreak;
292 20 nussgipfel
          --nx_state <= inThrotEnd;
293 18 nussgipfel
        elsif i_WRU = '0' then
294
          nx_state <= endInTrans;
295
        else
296
          nx_state <= inThrot;
297
        end if;
298 11 nussgipfel
 
299 19 nussgipfel
      when inThrotBreak =>
300 21 nussgipfel
        state_number := x"8";
301 19 nussgipfel
        -- this is a one clock delay to help the fx2 to see the RDYX signal.
302
 
303
        -- output signal values:
304
        s_WRX       <= '0';
305
        s_RDYX      <= '1';
306
        s_U2X_WR_EN <= '0';
307
        o_RX        <= '1';
308
 
309
        -- state decisions 
310
        --nx_state <= inThrotBreak2;
311
        nx_state <= inThrotEnd;
312
 
313
      --when inThrotBreak2 =>
314 18 nussgipfel
      --  -- this is a one clock delay to help the fx2 to see the RDYX signal.
315 19 nussgipfel
 
316 18 nussgipfel
      --  -- output signal values:
317
      --  s_WRX       <= '0';
318
      --  s_RDYX      <= '1';
319
      --  s_U2X_WR_EN <= '0';
320
      --  o_RX        <= '1';
321
 
322
      --  -- state decisions 
323 19 nussgipfel
      --  nx_state <= inThrotEnd;
324 18 nussgipfel
 
325 19 nussgipfel
      when inThrotEnd =>
326 21 nussgipfel
        state_number := x"9";
327 19 nussgipfel
        -- this is a one clock delay to help the fx2 to see the RDYX signal.
328
 
329
        -- output signal values:
330
        s_WRX       <= '0';
331
        s_RDYX      <= '1';
332
        s_U2X_WR_EN <= '0';
333
        o_RX        <= '1';
334
 
335
        -- state decisions 
336
        nx_state <= inTrans;
337
 
338 18 nussgipfel
      when endInTrans =>
339 21 nussgipfel
        state_number := x"A";
340 18 nussgipfel
        -- output signal values:
341
        s_WRX       <= '0';
342
        s_RDYX      <= '0';
343 19 nussgipfel
        s_U2X_WR_EN <= '0';
344
        o_RX        <= '0';
345 18 nussgipfel
 
346
        -- state decisions
347
        nx_state <= idle;
348
 
349 20 nussgipfel
        -----------------------------------------------------------------------
350 11 nussgipfel
        -- out trans
351 18 nussgipfel
      when outRQ =>
352 21 nussgipfel
        state_number := x"B";
353 18 nussgipfel
        -- output signal values:
354 20 nussgipfel
        s_WRX       <= '1';
355
        s_RDYX      <= '0';
356
        s_X2U_RD_EN <= '0';
357 18 nussgipfel
 
358
        -- state decisions
359
        if i_WRU = '1' and i_RDYU = '1' then
360
          nx_state <= rst;
361
        elsif i_WRU = '1' and i_RDYU = '0' then
362
          nx_state <= inRQ;
363
        else
364 20 nussgipfel
          nx_state <= outACK;
365 18 nussgipfel
        end if;
366 11 nussgipfel
 
367 20 nussgipfel
     when outACK =>
368 21 nussgipfel
        state_number := x"C";
369 20 nussgipfel
        -- output signal values:
370
        s_WRX       <= '1';
371
        s_RDYX      <= '0';
372
        s_X2U_RD_EN <= '1';
373
        o_TX        <= '1';
374 11 nussgipfel
 
375 20 nussgipfel
        -- state decisions
376
        if i_WRU = '1' and i_RDYU = '1' then
377
          nx_state <= rst;
378
        elsif i_WRU = '0' and i_RDYU = '1' then
379
          nx_state <= outTrans;
380
        else
381
          nx_state <= outUSBwait;
382
        end if;
383
 
384 18 nussgipfel
      when outTrans =>
385 21 nussgipfel
        state_number := x"D";
386 18 nussgipfel
        -- output signal values:
387
        s_WRX           <= '1';
388
        s_RDYX          <= '0';
389
        s_X2U_RD_EN     <= '1';
390 20 nussgipfel
        o_TX            <= '1';
391 18 nussgipfel
        s_bus_trans_dir <= writeToGPIF;
392
 
393
        -- state decisions
394
        if i_WRU = '1' and i_RDYU = '1' then
395
          nx_state        <= rst;
396 20 nussgipfel
        elsif i_X2U_EMPTY = '1' and i_EOM = '1' then
397 18 nussgipfel
          nx_state <= endOutTrans;
398 20 nussgipfel
        elsif i_X2U_EMPTY = '1' and i_EOM = '0' then
399
          nx_state <= outFIFOwait;
400 18 nussgipfel
        elsif i_WRU = '0' and i_RDYU = '1' then
401
          nx_state <= outTrans;
402
        else
403 20 nussgipfel
          nx_state    <= outUSBwait;
404 18 nussgipfel
        end if;
405
 
406 20 nussgipfel
      when outUSBwait =>
407 21 nussgipfel
        state_number := x"E";
408 18 nussgipfel
        -- output signal values:
409
        s_WRX       <= '1';
410
        s_RDYX      <= '0';
411
        s_X2U_RD_EN <= '0';
412
        o_TX        <= '1';
413
        s_bus_trans_dir <= writeToGPIF;
414
 
415
        -- state decisions
416
        if i_WRU = '1' and i_RDYU = '1' then
417
          nx_state <= rst;
418
        elsif i_WRU = '0' and i_RDYU = '1' then
419
          nx_state <= outTrans;
420
        else
421 20 nussgipfel
          nx_state <= outUSBwait;
422 18 nussgipfel
        end if;
423
 
424 20 nussgipfel
      when outFIFOwait =>
425 21 nussgipfel
        state_number := x"F";
426 20 nussgipfel
        -- output signal values:
427
        s_WRX       <= '1';
428
        s_RDYX      <= '1';
429
        s_X2U_RD_EN <= '0';
430
        o_TX        <= '1';
431
        s_bus_trans_dir <= writeToGPIF;
432
 
433
        -- state decisions
434
        if i_WRU = '1' and i_RDYU = '1' then
435
          nx_state <= rst;
436
        elsif i_X2U_EMPTY = '1' and i_EOM = '1' then
437
          nx_state <= endOutTrans;
438
        elsif i_X2U_EMPTY = '0' and i_EOM = '0' then
439
          nx_state <= outTrans;
440
        else
441
          nx_state <= outFIFOwait;
442
        end if;
443
 
444 18 nussgipfel
      when endOutTrans =>
445 21 nussgipfel
        state_number := x"9";
446 18 nussgipfel
        -- output signal values:
447
        s_RDYX          <= '0';
448 20 nussgipfel
        s_WRX           <= '0';
449
        s_X2U_RD_EN     <= '0';
450 18 nussgipfel
        s_bus_trans_dir <= writeToGPIF;
451
 
452
        -- state decisions
453 20 nussgipfel
        if i_RDYU = '0' then
454
          nx_state <= idle;
455
        else
456
          nx_state <= endOutTrans;
457
        end if;
458 18 nussgipfel
 
459 11 nussgipfel
        -- error case
460 18 nussgipfel
      when others =>
461
        nx_state <= idle;
462
    end case;
463 11 nussgipfel
 
464 18 nussgipfel
  end process transaction;
465
 
466
end fsm;

powered by: WebSVN 2.1.0

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