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 17

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

powered by: WebSVN 2.1.0

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