1 --+-------------------------------------------------------------------------------------------------+
3 --| File: pciwbsequ.vhd |
5 --| Project: pci32tlite_oc |
7 --| Description: FSM controlling PCI to Whisbone sequence. |
9 --+-------------------------------------------------------------------------------------------------+
11 --| Revision history : |
12 --| Date Version Author Description |
13 --| 2005-05-13 R00A00 PAU First alfa revision (eng) |
14 --| 2006-01-09 MS added debug signals debug_init, debug_access | |
18 --+-------------------------------------------------------------------------------------------------+
19 --+-----------------------------------------------------------------+
21 --| Copyright (C) 2005 Peio Azkarate, peio@opencores.org |
23 --| This source file may be used and distributed without |
24 --| restriction provided that this copyright statement is not |
25 --| removed from the file and that any derivative work contains |
26 --| the original copyright notice and the associated disclaimer. |
28 --| This source file is free software; you can redistribute it |
29 --| and/or modify it under the terms of the GNU Lesser General |
30 --| Public License as published by the Free Software Foundation; |
31 --| either version 2.1 of the License, or (at your option) any |
34 --| This source is distributed in the hope that it will be |
35 --| useful, but WITHOUT ANY WARRANTY; without even the implied |
36 --| warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
37 --| PURPOSE. See the GNU Lesser General Public License for more |
40 --| You should have received a copy of the GNU Lesser General |
41 --| Public License along with this source; if not, download it |
42 --| from http://www.opencores.org/lgpl.shtml |
44 --+-----------------------------------------------------------------+
47 --+-----------------------------------------------------------------------------+
49 --+-----------------------------------------------------------------------------+
52 use ieee.std_logic_1164.all;
55 --+-----------------------------------------------------------------------------+
57 --+-----------------------------------------------------------------------------+
64 nrst_i : in std_logic;
67 cmd_i : in std_logic_vector(3 downto 0);
68 cbe_i : in std_logic_vector(3 downto 0);
69 frame_i : in std_logic;
70 irdy_i : in std_logic;
71 devsel_o : out std_logic;
72 trdy_o : out std_logic;
74 adrcfg_i : in std_logic;
75 adrmem_i : in std_logic;
76 pciadrLD_o : out std_logic;
77 pcidOE_o : out std_logic;
78 parOE_o : out std_logic;
79 wbdatLD_o : out std_logic;
80 wbrgdMX_o : out std_logic;
81 wbd16MX_o : out std_logic;
82 wrcfg_o : out std_logic;
83 rdcfg_o : out std_logic;
85 wb_sel_o : out std_logic_vector(1 downto 0);
86 wb_we_o : out std_logic;
87 wb_stb_o : inout std_logic;
88 wb_cyc_o : out std_logic;
89 wb_ack_i : in std_logic;
90 wb_err_i : in std_logic;
92 debug_init : out std_logic;
93 debug_access : out std_logic
98 architecture rtl of pciwbsequ is
101 --+-----------------------------------------------------------------------------+
103 --+-----------------------------------------------------------------------------+
104 --+-----------------------------------------------------------------------------+
106 --+-----------------------------------------------------------------------------+
107 --+-----------------------------------------------------------------------------+
109 --+-----------------------------------------------------------------------------+
111 type PciFSM is ( PCIIDLE, B_BUSY, S_DATA1, S_DATA2, TURN_AR );
112 signal pst_pci : PciFSM;
113 signal nxt_pci : PciFSM;
115 signal sdata1 : std_logic;
116 signal sdata2 : std_logic;
117 signal idleNX : std_logic;
118 signal sdata1NX : std_logic;
119 signal sdata2NX : std_logic;
120 signal turnarNX : std_logic;
121 signal idle : std_logic;
122 signal devselNX_n : std_logic;
123 signal trdyNX_n : std_logic;
124 signal devsel : std_logic;
125 signal trdy : std_logic;
126 signal adrpci : std_logic;
127 signal acking : std_logic;
128 signal rdcfg : std_logic;
129 signal targOE : std_logic;
130 signal pcidOE : std_logic;
135 --+-------------------------------------------------------------------------+
136 --| PCI-Whisbone Sequencer |
137 --+-------------------------------------------------------------------------+
140 --+-------------------------------------------------------------+
141 --| FSM PCI-Whisbone |
142 --+-------------------------------------------------------------+
144 PCIFSM_CLOCKED: process( nrst_i, clk_i, nxt_pci )
147 if( nrst_i = '0' ) then
149 elsif( rising_edge(clk_i) ) then
153 end process PCIFSM_CLOCKED;
156 PCIFSM_COMB: process( pst_pci, frame_i, irdy_i, adrcfg_i, adrpci, acking )
164 if ( frame_i = '0' ) then
171 if ( adrpci = '0' ) then
179 if ( acking = '1' ) then
189 if ( frame_i = '1' and irdy_i = '0' ) then
198 if ( frame_i = '1' ) then
206 end process PCIFSM_COMB;
209 --+-------------------------------------------------------------+
210 --| FSM control signals |
211 --+-------------------------------------------------------------+
213 adrpci <= adrmem_i or adrcfg_i;
214 acking <= '1' when ( wb_ack_i = '1' or wb_err_i = '1' ) or ( adrcfg_i = '1' and irdy_i = '0')
218 --+-------------------------------------------------------------+
219 --| FSM derived Control signals |
220 --+-------------------------------------------------------------+
221 idle <= '1' when ( pst_pci = PCIIDLE ) else '0';
222 sdata1 <= '1' when ( pst_pci = S_DATA1 ) else '0';
223 sdata2 <= '1' when ( pst_pci = S_DATA2 ) else '0';
224 idleNX <= '1' when ( nxt_pci = PCIIDLE ) else '0';
225 sdata1NX <= '1' when ( nxt_pci = S_DATA1 ) else '0';
226 sdata2NX <= '1' when ( nxt_pci = S_DATA2 ) else '0';
227 turnarNX <= '1' when ( nxt_pci = TURN_AR ) else '0';
231 --+-------------------------------------------------------------+
232 --| PCI Data Output Enable |
233 --+-------------------------------------------------------------+
235 PCIDOE_P: process( nrst_i, clk_i, cmd_i(0), sdata1NX, turnarNX )
238 if ( nrst_i = '0' ) then
240 elsif ( rising_edge(clk_i) ) then
242 if ( sdata1NX = '1' and cmd_i(0) = '0' ) then
244 elsif ( turnarNX = '1' ) then
250 end process PCIDOE_P;
255 --+-------------------------------------------------------------+
256 --| PAR Output Enable |
257 --| PCI Read data phase |
258 --| PAR is valid 1 cicle after data is valid |
259 --+-------------------------------------------------------------+
261 PAROE_P: process( nrst_i, clk_i, cmd_i(0), sdata2NX, turnarNX )
264 if ( nrst_i = '0' ) then
266 elsif ( rising_edge(clk_i) ) then
268 if ( ( sdata2NX = '1' or turnarNX = '1' ) and cmd_i(0) = '0' ) then
279 --+-------------------------------------------------------------+
280 --| Target s/t/s signals OE control |
281 --+-------------------------------------------------------------+
283 -- targOE <= '1' when ( idle = '0' and adrpci = '1' ) else '0';
284 TARGOE_P: process( nrst_i, clk_i, sdata1NX, idleNX )
287 if ( nrst_i = '0' ) then
289 elsif ( rising_edge(clk_i) ) then
291 if ( sdata1NX = '1' ) then
293 elsif ( idleNX = '1' ) then
299 end process TARGOE_P;
302 --+-------------------------------------------------------------------------+
304 --+-------------------------------------------------------------------------+
306 wb_cyc_o <= '1' when ( adrmem_i = '1' and sdata1 = '1' ) else '0';
307 wb_stb_o <= '1' when ( adrmem_i = '1' and sdata1 = '1' and irdy_i = '0' ) else '0';
309 -- PCI(Little endian) to WB(Big endian)
310 wb_sel_o(1) <= (not cbe_i(0)) or (not cbe_i(2));
311 wb_sel_o(0) <= (not cbe_i(1)) or (not cbe_i(3));
316 --+-------------------------------------------------------------------------+
317 --| Syncronized PCI outs |
318 --+-------------------------------------------------------------------------+
320 PCISIG: process( nrst_i, clk_i, devselNX_n, trdyNX_n)
323 if( nrst_i = '0' ) then
326 elsif( rising_edge(clk_i) ) then
328 devsel <= devselNX_n;
335 devsel_o <= devsel when ( targOE = '1' ) else 'Z';
336 trdy_o <= trdy when ( targOE = '1' ) else 'Z';
339 --+-------------------------------------------------------------------------+
341 --+-------------------------------------------------------------------------+
343 -- rd/wr Configuration Space Registers
344 wrcfg_o <= '1' when ( adrcfg_i = '1' and cmd_i(0) = '1' and sdata2 = '1' ) else '0';
345 rdcfg <= '1' when ( adrcfg_i = '1' and cmd_i(0) = '0' and ( sdata1 = '1' or sdata2 = '1' ) ) else '0';
348 -- LoaD enable signals
349 pciadrLD_o <= not frame_i;
350 wbdatLD_o <= wb_ack_i;
352 -- Mux control signals
353 wbrgdMX_o <= not rdcfg;
354 wbd16MX_o <= '1' when ( cbe_i(3) = '0' or cbe_i(2) = '0' ) else '0';
356 --+-------------------------------------------------------------------------+
358 --+-------------------------------------------------------------------------+
360 process (nrst_i, clk_i)
362 if ( nrst_i = '0' ) then
364 elsif clk_i'event and clk_i = '1' then
371 process (nrst_i, clk_i)
373 if ( nrst_i = '0' ) then
375 elsif clk_i'event and clk_i = '1' then
376 if wb_stb_o = '1' then