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

Subversion Repositories pci32tlite_oc

[/] [pci32tlite_oc/] [trunk/] [rtl/] [pciwbsequ.vhd] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 peio
--+-------------------------------------------------------------------------------------------------+
2
--|                                                                                                                                                                                                     |
3
--|  Fileo:                     pciwbsequ.vhd                                                                           |
4
--|                                                                                                                                                                                                     |
5
--|  Project:           pci32tLite                                                                                                                                              |
6
--|                                                                                                                                                                                                     |
7
--|  Description:       FSM controling pci to whisbone transactions.                                    |
8
--|                                                                                                                                                                                                     |
9
--+-------------------------------------------------------------------------------------------------+
10
--+-----------------------------------------------------------------+
11
--|                                                                                                                             |
12
--|  Copyright (C) 2005-2008 Peio Azkarate, peio.azkarate@gmail.com     | 
13
--|                                                                                                                             |
14
--|  This source file may be used and distributed without               |
15
--|  restriction provided that this copyright statement is not          |
16
--|  removed from the file and that any derivative work contains        |
17
--|  the original copyright notice and the associated disclaimer.       |
18
--|                                                                     |
19
--|  This source file is free software; you can redistribute it     |
20
--|  and/or modify it under the terms of the GNU Lesser General     |
21
--|  Public License as published by the Free Software Foundation;   |
22
--|  either version 2.1 of the License, or (at your option) any     |
23
--|  later version.                                                 |
24
--|                                                                                                                             |
25
--|  This source is distributed in the hope that it will be         |
26
--|  useful, but WITHOUT ANY WARRANTY; without even the implied     |
27
--|  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR        |
28
--|  PURPOSE.  See the GNU Lesser General Public License for more   |
29
--|  details.                                                       |
30
--|                                                                                                                             |
31
--|  You should have received a copy of the GNU Lesser General      |
32
--|  Public License along with this source; if not, download it     |
33
--|  from http://www.opencores.org/lgpl.shtml                       |
34
--|                                                                                                                             |
35
--+-----------------------------------------------------------------+ 
36
 
37
 
38
--+-----------------------------------------------------------------------------+
39
--|                                                                     LIBRARIES                                                                       |
40
--+-----------------------------------------------------------------------------+
41
 
42
library ieee;
43
use ieee.std_logic_1164.all;
44
 
45
library onalib;
46
use onalib.onapackage.all;
47
 
48
--+-----------------------------------------------------------------------------+
49
--|                                                                     ENTITY                                                                          |
50
--+-----------------------------------------------------------------------------+
51
 
52
entity pciwbsequ is
53
generic (
54
        BARS             : string := "1BARMEM";
55
        WBSIZE           : integer := 16;
56
        WBENDIAN         : string := "BIG"
57
);
58
port (
59
        -- General 
60
    clk_i               : in std_logic;
61
        rst_i           : in std_logic;
62
        -- pci 
63
        cmd_i                   : in std_logic_vector(3 downto 0);
64
        cbe_i                   : in std_logic_vector(3 downto 0);
65
        frame_i                 : in std_logic;
66
        irdy_i          : in std_logic;
67
        devsel_o                : out std_logic;
68
        trdy_o          : out std_logic;
69
        stop_o          : out std_logic;
70
        -- control
71
        adrcfg_i                : in std_logic;
72
        adrmem_i                : in std_logic;
73
        pciadrLD_o              : out std_logic;
74
        pcidOE_o                : out std_logic;
75
        parOE_o                 : out std_logic;
76
        wbdatLD_o       : out std_logic;
77
        wrcfg_o                 : out std_logic;
78
        rdcfg_o                 : out std_logic;
79
        -- whisbone
80
        wb_sel_o                : out std_logic_vector(((WBSIZE/8)-1) downto 0);
81
        wb_we_o                 : out std_logic;
82
        wb_stb_o                : out std_logic;
83
        wb_cyc_o                : out std_logic;
84
        wb_ack_i                : in std_logic;
85
        wb_rty_i        : in std_logic;
86
        wb_err_i                : in std_logic
87
 
88
);
89
end pciwbsequ;
90
 
91
 
92
architecture rtl of pciwbsequ is
93
 
94
 
95
--+-----------------------------------------------------------------------------+
96
--|                                                                     COMPONENTS                                                                      |
97
--+-----------------------------------------------------------------------------+
98
--+-----------------------------------------------------------------------------+
99
--|                                                                     CONSTANTS                                                                       |
100
--+-----------------------------------------------------------------------------+
101
--+-----------------------------------------------------------------------------+
102
--|                                                                     SIGNALS                                                                         |
103
--+-----------------------------------------------------------------------------+
104
 
105
        type PciFSM is ( PCIIDLE, B_BUSY, S_DATA1, S_DATA2, BACKOFF, TURN_ARL, TURN_ARE );
106
        signal pst_pci          : PciFSM;
107
        signal nxt_pci          : PciFSM;
108
 
109
        signal bbusy            : std_logic;
110
        signal idle                     : std_logic;
111
        signal sdata1           : std_logic;
112
        signal sdata2           : std_logic;
113
        signal sdata1NX         : std_logic;
114
        signal sdata2NX         : std_logic;
115
        signal turnarlNX        : std_logic;
116
        signal turnarl          : std_logic;
117
        signal devselNX_n       : std_logic;
118
        signal trdyNX_n         : std_logic;
119
        signal stopNx_n         : std_logic;
120
        signal devsel           : std_logic;
121
        signal trdy                     : std_logic;
122
        signal stop                     : std_logic;
123
        signal adrpci           : std_logic;
124
        signal acking           : std_logic;
125
        signal retrying         : std_logic;
126
        signal rdcfg            : std_logic;
127
        signal targOE           : std_logic;
128
        signal pcidOE           : std_logic;
129
        signal pcidOE_s         : std_logic;
130
 
131
begin
132
 
133
 
134
    --+-------------------------------------------------------------------------+
135
    --|  PCI-Whisbone Sequencer                                                                                                 |
136
    --+-------------------------------------------------------------------------+
137
 
138
    --+-------------------------------------------------------------+
139
        --|  FSM PCI-Whisbone                                                                                   |
140
    --+-------------------------------------------------------------+   
141
        PCIFSM_CLOCKED: process( rst_i, clk_i, nxt_pci )
142
        begin
143
        if( rst_i = '1' ) then
144
                        pst_pci <= PCIIDLE;
145
                elsif( rising_edge(clk_i) ) then
146
                        pst_pci <= nxt_pci;
147
        end if;
148
        end process PCIFSM_CLOCKED;
149
 
150
 
151
        PCIFSM_COMB: process( pst_pci, frame_i, irdy_i, adrcfg_i, adrpci, acking, retrying )
152
        begin
153
 
154
                devselNX_n      <= '1';
155
                trdyNX_n        <= '1';
156
                stopNX_n        <= '1';
157
 
158
        case pst_pci is
159
 
160
                when PCIIDLE =>
161
                        if ( frame_i = '0' ) then
162
                                        nxt_pci <= B_BUSY;
163
                                else
164
                                        nxt_pci <= PCIIDLE;
165
                                end if;
166
 
167
            when B_BUSY =>
168
                                if ( adrpci = '0' ) then
169
                                        nxt_pci <= TURN_ARE;
170
                                else
171
                                        nxt_pci    <= S_DATA1;
172
                                        devselNX_n <= '0';
173
                                end if;
174
 
175
                    when S_DATA1 =>
176
                        if (acking = '1') then
177
                    if (frame_i = '0') then
178
                                            stopNX_n    <= '0';
179
                    end if;
180
                            nxt_pci     <= S_DATA2;
181
                            devselNX_n  <= '0';
182
                            trdyNX_n    <= '0';
183
                                elsif (retrying = '1') then
184
                                        nxt_pci         <= BACKOFF;
185
                                        devselNX_n      <= '0';
186
                                        stopNX_n        <= '0';
187
                else
188
                                        nxt_pci    <= S_DATA1;
189
                                        devselNX_n <= '0';
190
                                end if;
191
 
192
                    when S_DATA2 =>
193
                                        nxt_pci <= TURN_ARL;
194
 
195
                    when BACKOFF =>
196
                                if ( frame_i = '1' and irdy_i = '0' ) then
197
                                        nxt_pci <= TURN_ARL;
198
                                else
199
                                        nxt_pci     <= BACKOFF;
200
                                        devselNX_n      <= '0';
201
                                        stopNX_n        <= '0';
202
                                end if;
203
 
204
                        when TURN_ARL =>
205
                                if (frame_i = '0') then
206
                                        nxt_pci <= B_BUSY;
207
                                else
208
                                        nxt_pci <= PCIIDLE;
209
                                end if;
210
 
211
                        when TURN_ARE =>
212
                                if (frame_i = '0') then
213
                                        nxt_pci <= TURN_ARE;
214
                                else
215
                                        nxt_pci <= PCIIDLE;
216
                                end if;
217
 
218
            end case;
219
 
220
        end process PCIFSM_COMB;
221
 
222
 
223
    --+-------------------------------------------------------------+
224
        --|  FSM control signals                                                                                |
225
    --+-------------------------------------------------------------+
226
 
227
        adrpci  <= adrmem_i or adrcfg_i;
228
        acking  <= '1' when ( wb_ack_i = '1' or wb_err_i = '1' ) or ( adrcfg_i = '1' and  irdy_i = '0')
229
                                   else '0';
230
        retrying <= '1' when ( wb_rty_i = '1' )  else '0';
231
 
232
 
233
    --+-------------------------------------------------------------+
234
        --|  FSM derived Control signals                                                                |
235
    --+-------------------------------------------------------------+
236
        idle            <= '1' when ( pst_pci = PCIIDLE ) else '0';
237
        bbusy           <= '1' when ( pst_pci = B_BUSY  ) else '0';
238
        sdata1          <= '1' when ( pst_pci = S_DATA1 ) else '0';
239
        sdata2          <= '1' when ( pst_pci = S_DATA2 ) else '0';
240
        --turnar                <= '1' when ( pst_pci = TURN_AR ) else '0';
241
        turnarl         <= '1' when ( pst_pci = TURN_ARL ) else '0';
242
        sdata1NX        <= '1' when ( nxt_pci = S_DATA1 ) else '0';
243
        sdata2NX        <= '1' when ( nxt_pci = S_DATA2 ) else '0';
244
        --turnarNX      <= '1' when ( nxt_pci = TURN_AR ) else '0';
245
        turnarlNX       <= '1' when ( nxt_pci = TURN_ARL ) else '0';
246
 
247
 
248
    --+-------------------------------------------------------------+
249
        --|  PCI Data Output Enable                                                                             |
250
    --+-------------------------------------------------------------+
251
 
252
        PCIDOE_P: process( rst_i, clk_i, cmd_i(0), sdata1NX, turnarlNX )
253
        begin
254
 
255
        if ( rst_i = '1' ) then
256
                        pcidOE <= '0';
257
                elsif ( rising_edge(clk_i) ) then
258
 
259
                        if ( sdata1NX = '1' and cmd_i(0) = '0' ) then
260
                                pcidOE <= '1';
261
                        elsif ( turnarlNX = '1' ) then
262
                                pcidOE <= '0';
263
                        end if;
264
 
265
        end if;
266
 
267
        end process PCIDOE_P;
268
 
269
        pcidOE_o <= pcidOE;
270
 
271
 
272
    --+-------------------------------------------------------------+
273
        --|  PAR Output Enable                                                                                  |
274
        --|  PCI Read data phase                                                                                |
275
        --|  PAR is valid 1 cicle after data is valid                                   |
276
    --+-------------------------------------------------------------+
277
    uu1: syncl port map ( clk => clk_i, rst => rst_i, d => pcidOE, q => pcidOE_s );
278
        parOE_o <= pcidOE_s;
279
 
280
 
281
    --+-------------------------------------------------------------+
282
        --|  Target s/t/s signals OE control                                                    |
283
    --+-------------------------------------------------------------+
284
 
285
        TARGOE_P: process( rst_i, clk_i, sdata1NX, turnarl )
286
        begin
287
 
288
        if ( rst_i = '1' ) then
289
                        targOE <= '0';
290
                elsif ( rising_edge(clk_i) ) then
291
 
292
                        if ( sdata1NX = '1' ) then
293
                                targOE <= '1';
294
                        elsif ( turnarl = '1' ) then
295
                                targOE <= '0';
296
                        end if;
297
 
298
        end if;
299
 
300
        end process TARGOE_P;
301
 
302
 
303
    --+-------------------------------------------------------------------------+
304
    --|  WHISBONE outs                                                                                                                  |
305
    --+-------------------------------------------------------------------------+
306
 
307
        cyc_p: process(rst_i, clk_i, adrmem_i, bbusy, acking, retrying, frame_i)
308
        begin
309
        if ( rst_i = '1' ) then
310
                        wb_cyc_o <= '0';
311
                elsif ( rising_edge(clk_i) ) then
312
                        if (adrmem_i = '1' and bbusy = '1' ) then
313
                                wb_cyc_o <= '1';
314
                        elsif ((acking = '1' or retrying = '1') and frame_i = '1') then
315
                                wb_cyc_o <= '0';
316
                        end if;
317
        end if;
318
        end process cyc_p;
319
 
320
    wb_stb_o <= '1' when ( adrmem_i = '1' and sdata1 = '1' and irdy_i = '0' ) else '0';
321
        wb_we_o <= cmd_i(0);
322
 
323
        --+-----------------------------------------+
324
        --| wb_sel_o generation depending on WBSIZE     |
325
        --|  and WBENDIAN "generics" configuration      |
326
    --+-----------------------------------------+
327
        sel32: if (WBSIZE = 32) generate
328
                wb_sel_o(3) <= not cbe_i(3);
329
                wb_sel_o(2) <= not cbe_i(2);
330
                wb_sel_o(1) <= not cbe_i(1);
331
                wb_sel_o(0) <= not cbe_i(0);
332
        end generate;
333
 
334
        sel16b: if (WBSIZE = 16 and WBENDIAN = "BIG") generate
335
                wb_sel_o(1) <= (not cbe_i(0)) or (not cbe_i(2));
336
                wb_sel_o(0) <= (not cbe_i(1)) or (not cbe_i(3));
337
        end generate;
338
 
339
        sel16l: if (WBSIZE = 16 and WBENDIAN = "LITTLE") generate
340
                wb_sel_o(1) <= (not cbe_i(1)) or (not cbe_i(3));
341
                wb_sel_o(0) <= (not cbe_i(0)) or (not cbe_i(2));
342
        end generate;
343
 
344
        sel8: if (WBSIZE = 8) generate
345
                wb_sel_o(0) <= not (cbe_i(0) and cbe_i(1) and cbe_i(2) and cbe_i(3));
346
        end generate;
347
 
348
 
349
    --+-------------------------------------------------------------------------+
350
        --|  Syncronized PCI outs                                                                                                       |
351
    --+-------------------------------------------------------------------------+
352
 
353
        PCISIG: process( rst_i, clk_i, devselNX_n, trdyNX_n, stopNX_n)
354
        begin
355
                if( rst_i = '1' ) then
356
                        devsel          <= '1';
357
                        trdy            <= '1';
358
                        stop            <= '1';
359
                elsif( rising_edge(clk_i) ) then
360
                        devsel          <= devselNX_n;
361
                        trdy            <= trdyNX_n;
362
                        stop            <= stopNX_n;
363
                end if;
364
        end process PCISIG;
365
 
366
        devsel_o <= devsel when ( targOE = '1' ) else 'Z';
367
        trdy_o   <= trdy   when ( targOE = '1' ) else 'Z';
368
        stop_o   <= stop   when ( targOE = '1' ) else 'Z';
369
 
370
 
371
    --+-------------------------------------------------------------------------+
372
        --|  Other outs                                                                                                                         |
373
    --+-------------------------------------------------------------------------+
374
 
375
        --  rd/wr Configuration Space Registers
376
        wrcfg_o <= '1' when ( adrcfg_i = '1' and cmd_i(0) = '1' and sdata2 = '1' ) else '0';
377
        rdcfg <= '1' when ( adrcfg_i = '1' and cmd_i(0) = '0' and ( sdata1 = '1' or sdata2 = '1' ) ) else '0';
378
        rdcfg_o <= rdcfg;
379
 
380
        -- LoaD enable signals
381
        --pciadrLD_o <= '1' when(frame_i = '0' and idle = '1') else '0';
382
        -- added turnarl to support Fast Back to Back
383
        pciadrLD_o <= '1' when(frame_i = '0' and (idle = '1' or turnarl = '1')) else '0';
384
        wbdatLD_o  <= wb_ack_i;
385
 
386
end rtl;

powered by: WebSVN 2.1.0

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