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 19

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 14 nussgipfel
end gpif_com_fsm;
73 11 nussgipfel
 
74
 
75
 
76 14 nussgipfel
architecture fsm of gpif_com_fsm is
77 11 nussgipfel
 
78 19 nussgipfel
  -- XST specific synthesize attributes
79
  attribute safe_implementation: string;
80
  attribute safe_recovery_state: string;
81
 
82
 
83 18 nussgipfel
  -----------------------------------------------------------------------------
84 11 nussgipfel
  -- FSM
85
  -----------------------------------------------------------------------------
86
 
87 18 nussgipfel
  type   t_busAccess is (readFromGPIF, writeToGPIF);
88 14 nussgipfel
  signal s_bus_trans_dir : t_busAccess;
89
 
90
 
91 18 nussgipfel
  type t_fsmState is (rst, idle,        -- controll states
92 19 nussgipfel
                      inRQ, inACK, inWait, inTrans, inThrot,
93
                      inThrotBreak,inThrotBreak2, inThrotEnd, endInTrans,  -- in com states
94 18 nussgipfel
                      outRQ, outTrans, outWait, endOutTrans);  -- out com states
95 11 nussgipfel
 
96 18 nussgipfel
 
97
 
98 11 nussgipfel
  signal pr_state, nx_state : t_fsmState;
99 18 nussgipfel
  -- XST specific synthesize attributes
100
  attribute safe_recovery_state of pr_state : signal is "idle";
101 19 nussgipfel
  attribute safe_implementation of pr_state : signal is "yes";
102
 
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 19 nussgipfel
 
117
 
118 18 nussgipfel
  o_FIFOrst       <= s_FIFOrst;
119
  o_X2U_RD_EN     <= s_X2U_RD_EN;
120
  o_WRX           <= s_WRX;
121
  o_RDYX          <= s_RDYX;
122
  o_U2X_WR_EN     <= s_U2X_WR_EN;
123 14 nussgipfel
  o_bus_trans_dir <= '1' when s_bus_trans_dir = writeToGPIF else '0';
124 18 nussgipfel
  o_ABORT         <= s_ABORT;
125 11 nussgipfel
 
126 18 nussgipfel
 
127 11 nussgipfel
  -----------------------------------------------------------------------------
128
  -- FSM GPIF
129
  -----------------------------------------------------------------------------
130
 
131 18 nussgipfel
  -- state reg
132 11 nussgipfel
  action : process(i_IFCLK, i_nReset)
133 18 nussgipfel
  begin
134 11 nussgipfel
 
135 18 nussgipfel
    if i_nReset = '0' then
136
      pr_state <= rst;
137
 
138
    elsif rising_edge(i_IFCLK) then
139
        pr_state <= nx_state;
140
    end if;
141
  end process action;
142 11 nussgipfel
 
143
 
144 18 nussgipfel
  -- comb logic
145 19 nussgipfel
  transaction : process(pr_state, i_WRU, i_RDYU, i_U2X_FULL,
146
                        i_U2X_AM_FULL, i_X2U_EMPTY)
147 18 nussgipfel
  begin  -- process transaction
148 11 nussgipfel
 
149 18 nussgipfel
    -- default signal values to avoid latches:
150
    s_FIFOrst       <= '0';
151
    s_bus_trans_dir <= readFromGPIF;
152
    s_U2X_WR_EN     <= '0';
153
    s_X2U_RD_EN     <= '0';
154
    nx_state        <= idle;
155
    s_WRX           <= '0';
156
    s_RDYX          <= '0';
157
    s_ABORT         <= '0';
158
    o_RX            <= '0';
159
    o_TX            <= '0';
160
 
161
    case pr_state is
162
      -- controll
163
 
164
      when rst =>
165
        -- output signal values:
166
        s_FIFOrst   <= '1';
167
        s_WRX       <= '0';
168
        s_RDYX      <= '0';
169
        s_U2X_WR_EN <= '0';
170
        s_X2U_RD_EN <= '0';
171
        s_ABORT     <= '1';
172
        o_RX        <= '0';
173
        o_TX        <= '0';
174
 
175
        s_bus_trans_dir <= readFromGPIF;
176
 
177
        -- state decisions
178
        if i_WRU = '1' and i_RDYU = '1' then
179
          nx_state <= rst;
180
        else
181
          nx_state <= idle;
182
        end if;
183 11 nussgipfel
 
184 18 nussgipfel
      when idle =>
185
        -- output signal values:
186
        s_FIFOrst       <= '0';
187
        s_WRX           <= '0';
188
        s_RDYX          <= '0';
189
        s_U2X_WR_EN     <= '0';
190
        s_X2U_RD_EN     <= '0';
191
        s_bus_trans_dir <= readFromGPIF;
192 11 nussgipfel
 
193 18 nussgipfel
        -- state decisions
194
        if i_WRU = '1' and i_RDYU = '1' then
195
          nx_state <= rst;
196
        elsif i_WRU = '1' and i_RDYU = '0' then
197
          nx_state <= inRQ;
198
        elsif i_WRU = '0' and i_X2U_EMPTY = '0' then
199
          nx_state <= outRQ;
200
        else
201
          nx_state <= idle;
202
        end if;
203
 
204 11 nussgipfel
        -- in trans
205 18 nussgipfel
      when inRQ =>
206
        -- output signal values:
207
        s_WRX  <= '0';
208
        s_RDYX <= '0';
209 19 nussgipfel
        s_U2X_WR_EN <= '0';
210
        o_RX        <= '0';
211
 
212 18 nussgipfel
        -- state decisions
213
        if i_WRU = '1' and i_RDYU = '1' then
214
          nx_state <= rst;
215
        elsif i_U2X_FULL = '0' then
216
          nx_state <= inACK;
217
        else
218
          nx_state <= idle;
219
        end if;
220 11 nussgipfel
 
221 18 nussgipfel
      when inACK =>
222
        -- output signal values:
223
        s_WRX       <= '0';
224
        s_RDYX      <= '1';
225 19 nussgipfel
        s_U2X_WR_EN <= '0';
226 18 nussgipfel
        o_RX        <= '1';
227 11 nussgipfel
 
228 18 nussgipfel
        -- state decisions
229
        if i_WRU = '1' and i_RDYU = '1' then
230
          nx_state <= rst;
231
        elsif i_WRU = '1' then
232 19 nussgipfel
          --nx_state <= inTrans;
233
          nx_state <= inWait;
234 18 nussgipfel
        else
235
          nx_state <= endInTrans;
236
        end if;
237 19 nussgipfel
 
238
        when inWait =>
239
        -- output signal values:
240
        s_WRX       <= '0';
241
        s_RDYX      <= '1';
242
        s_U2X_WR_EN <= '0';
243
        o_RX        <= '1';
244
 
245
        -- state decisions
246
        nx_state <= inTrans;
247 18 nussgipfel
 
248
      when inTrans =>
249
        -- output signal values:
250
        s_WRX       <= '0';
251
        s_RDYX      <= '1';
252
        s_U2X_WR_EN <= '1';
253
        o_RX        <= '1';
254 11 nussgipfel
 
255 18 nussgipfel
        -- state decisions
256
        if i_WRU = '1' and i_RDYU = '1' then
257
          nx_state <= rst;
258
        elsif i_WRU = '0' then
259
          nx_state <= endInTrans;
260
        elsif i_U2X_FULL = '1' then
261
          nx_state <= inThrot;
262
        else
263
          nx_state <= inTrans;
264
        end if;
265 11 nussgipfel
 
266 18 nussgipfel
      when inThrot =>
267
        -- output signal values:
268
        s_WRX       <= '0';
269
        s_RDYX      <= '0';
270
        s_U2X_WR_EN <= '0';
271
        o_RX        <= '1';
272 11 nussgipfel
 
273 18 nussgipfel
        -- state decisions
274
        if i_WRU = '1' and i_RDYU = '1' then
275
          nx_state <= rst;
276
        elsif i_U2X_FULL = '0' then
277 19 nussgipfel
          nx_state <= inThrotBreak;
278
          --nx_state <= inACK;
279 18 nussgipfel
        elsif i_WRU = '0' then
280
          nx_state <= endInTrans;
281
        else
282
          nx_state <= inThrot;
283
        end if;
284 11 nussgipfel
 
285 19 nussgipfel
      when inThrotBreak =>
286
        -- this is a one clock delay to help the fx2 to see the RDYX signal.
287
 
288
        -- output signal values:
289
        s_WRX       <= '0';
290
        s_RDYX      <= '1';
291
        s_U2X_WR_EN <= '0';
292
        o_RX        <= '1';
293
 
294
        -- state decisions 
295
        --nx_state <= inThrotBreak2;
296
        nx_state <= inThrotEnd;
297
 
298
      --when inThrotBreak2 =>
299 18 nussgipfel
      --  -- this is a one clock delay to help the fx2 to see the RDYX signal.
300 19 nussgipfel
 
301 18 nussgipfel
      --  -- output signal values:
302
      --  s_WRX       <= '0';
303
      --  s_RDYX      <= '1';
304
      --  s_U2X_WR_EN <= '0';
305
      --  o_RX        <= '1';
306
 
307
      --  -- state decisions 
308 19 nussgipfel
      --  nx_state <= inThrotEnd;
309 18 nussgipfel
 
310 19 nussgipfel
      when inThrotEnd =>
311
        -- this is a one clock delay to help the fx2 to see the RDYX signal.
312
 
313
        -- output signal values:
314
        s_WRX       <= '0';
315
        s_RDYX      <= '1';
316
        s_U2X_WR_EN <= '0';
317
        o_RX        <= '1';
318
 
319
        -- state decisions 
320
        nx_state <= inTrans;
321
 
322 18 nussgipfel
      when endInTrans =>
323
        -- output signal values:
324
        s_WRX       <= '0';
325
        s_RDYX      <= '0';
326 19 nussgipfel
        s_U2X_WR_EN <= '0';
327
        o_RX        <= '0';
328 18 nussgipfel
 
329
        -- state decisions
330
        nx_state <= idle;
331
 
332
 
333 11 nussgipfel
        -- out trans
334 18 nussgipfel
      when outRQ =>
335
        -- output signal values:
336
        s_WRX  <= '1';
337
        s_RDYX <= '0';
338
 
339
        -- state decisions
340
        if i_WRU = '1' and i_RDYU = '1' then
341
          nx_state <= rst;
342
        elsif i_WRU = '1' and i_RDYU = '0' then
343
          nx_state <= inRQ;
344
        elsif i_WRU = '0' and i_RDYU = '0' then  -- vervollständigt, wenn ez-usb noch beschäfigt mit altem transfer
345
          --s_X2U_RD_EN <= '1';
346
          nx_state    <= outTrans;
347 11 nussgipfel
--            s_bus_trans_dir <= writeToGPIF;
348 18 nussgipfel
        else
349
          nx_state <= outRQ;
350
        end if;
351 11 nussgipfel
 
352
 
353 18 nussgipfel
      when outTrans =>
354
        -- output signal values:
355
        s_WRX           <= '1';
356
        s_RDYX          <= '0';
357
        s_X2U_RD_EN     <= '1';
358
        s_bus_trans_dir <= writeToGPIF;
359
        o_TX            <= '1';
360
 
361
        -- state decisions
362
        if i_WRU = '1' and i_RDYU = '1' then
363
          nx_state        <= rst;
364
        elsif i_X2U_EMPTY = '1' then
365
          nx_state <= endOutTrans;
366
        elsif i_WRU = '0' and i_RDYU = '1' then
367
          nx_state <= outTrans;
368
        else
369
          --s_X2U_RD_EN <= '0';           -- to realise a wait case
370
          nx_state    <= outWait;
371
        end if;
372
 
373
      when outWait =>
374
        -- output signal values:
375
        s_WRX       <= '1';
376
        s_RDYX      <= '0';
377
        s_X2U_RD_EN <= '0';
378
        o_TX        <= '1';
379
        s_bus_trans_dir <= writeToGPIF;
380
 
381
        -- state decisions
382
        if i_WRU = '1' and i_RDYU = '1' then
383
          nx_state <= rst;
384
        elsif i_WRU = '0' and i_RDYU = '1' then
385
          nx_state <= outTrans;
386
        else
387
          nx_state <= outWait;
388
        end if;
389
 
390
      when endOutTrans =>
391
        -- output signal values:
392
        s_RDYX          <= '0';
393
        s_WRX           <= '1';  -- nötig um letzte 16bit an ez-usb zu schreiben
394
        s_X2U_RD_EN     <= '1';  -- nötig da empyte flag schon beim ersten fifo zugriff auftaucht, zweite 16bit müssen noch gelesen werden
395
        s_bus_trans_dir <= writeToGPIF;
396
 
397
        -- state decisions
398
        nx_state        <= idle;
399
 
400 11 nussgipfel
        -- error case
401 18 nussgipfel
      when others =>
402
        nx_state <= idle;
403
    end case;
404 11 nussgipfel
 
405 18 nussgipfel
  end process transaction;
406
 
407
end fsm;

powered by: WebSVN 2.1.0

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