1 |
27 |
rherveille |
---------------------------------------------------------------------
|
2 |
|
|
---- ----
|
3 |
|
|
---- OpenCores IDE Controller ----
|
4 |
|
|
---- PIO Access Controller (common for OCIDEC 2 and above) ----
|
5 |
|
|
---- ----
|
6 |
|
|
---- Author: Richard Herveille ----
|
7 |
|
|
---- richard@asics.ws ----
|
8 |
|
|
---- www.asics.ws ----
|
9 |
|
|
---- ----
|
10 |
|
|
---------------------------------------------------------------------
|
11 |
|
|
---- ----
|
12 |
|
|
---- Copyright (C) 2001, 2002 Richard Herveille ----
|
13 |
|
|
---- richard@asics.ws ---
|
14 |
|
|
---- ----
|
15 |
|
|
---- This source file may be used and distributed without ----
|
16 |
|
|
---- restriction provided that this copyright statement is not ----
|
17 |
|
|
---- removed from the file and that any derivative work contains ----
|
18 |
|
|
---- the original copyright notice and the associated disclaimer.----
|
19 |
|
|
---- ----
|
20 |
|
|
---- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ----
|
21 |
|
|
---- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ----
|
22 |
|
|
---- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ----
|
23 |
|
|
---- FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ----
|
24 |
|
|
---- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ----
|
25 |
|
|
---- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ----
|
26 |
|
|
---- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ----
|
27 |
|
|
---- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ----
|
28 |
|
|
---- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ----
|
29 |
|
|
---- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ----
|
30 |
|
|
---- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ----
|
31 |
|
|
---- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ----
|
32 |
|
|
---- POSSIBILITY OF SUCH DAMAGE. ----
|
33 |
|
|
---- ----
|
34 |
|
|
---------------------------------------------------------------------
|
35 |
|
|
|
36 |
|
|
-- rev.: 1.0 march 9th, 2001
|
37 |
|
|
-- rev.: 1.0a april 12th, 2001 Removed references to records.vhd
|
38 |
|
|
--
|
39 |
|
|
--
|
40 |
|
|
-- CVS Log
|
41 |
|
|
--
|
42 |
|
|
-- $Id: atahost_pio_actrl.vhd,v 1.1 2002-02-18 14:32:12 rherveille Exp $
|
43 |
|
|
--
|
44 |
|
|
-- $Date: 2002-02-18 14:32:12 $
|
45 |
|
|
-- $Revision: 1.1 $
|
46 |
|
|
-- $Author: rherveille $
|
47 |
|
|
-- $Locker: $
|
48 |
|
|
-- $State: Exp $
|
49 |
|
|
--
|
50 |
|
|
-- Change History:
|
51 |
|
|
-- $Log: not supported by cvs2svn $
|
52 |
|
|
|
53 |
|
|
--
|
54 |
|
|
---------------------------
|
55 |
|
|
-- PIO Access controller --
|
56 |
|
|
---------------------------
|
57 |
|
|
--
|
58 |
|
|
|
59 |
|
|
library ieee;
|
60 |
|
|
use ieee.std_logic_1164.all;
|
61 |
|
|
use ieee.std_logic_arith.all;
|
62 |
|
|
|
63 |
|
|
entity atahost_pio_actrl is
|
64 |
|
|
generic(
|
65 |
|
|
TWIDTH : natural := 8; -- counter width
|
66 |
|
|
|
67 |
|
|
-- PIO mode 0 settings (@100MHz clock)
|
68 |
|
|
PIO_mode0_T1 : natural := 6; -- 70ns
|
69 |
|
|
PIO_mode0_T2 : natural := 28; -- 290ns
|
70 |
|
|
PIO_mode0_T4 : natural := 2; -- 30ns
|
71 |
|
|
PIO_mode0_Teoc : natural := 23 -- 240ns ==> T0 - T1 - T2 = 600 - 70 - 290 = 240
|
72 |
|
|
);
|
73 |
|
|
port(
|
74 |
|
|
clk : in std_logic; -- master clock
|
75 |
|
|
nReset : in std_logic; -- asynchronous active low reset
|
76 |
|
|
rst : in std_logic; -- synchronous active high reset
|
77 |
|
|
|
78 |
|
|
IDEctrl_FATR0,
|
79 |
|
|
IDEctrl_FATR1 : in std_logic;
|
80 |
|
|
|
81 |
|
|
cmdport_T1,
|
82 |
|
|
cmdport_T2,
|
83 |
|
|
cmdport_T4,
|
84 |
|
|
cmdport_Teoc : in unsigned(7 downto 0);
|
85 |
|
|
cmdport_IORDYen : in std_logic; -- PIO command port / non-fast timing
|
86 |
|
|
|
87 |
|
|
dport0_T1,
|
88 |
|
|
dport0_T2,
|
89 |
|
|
dport0_T4,
|
90 |
|
|
dport0_Teoc : in unsigned(7 downto 0);
|
91 |
|
|
dport0_IORDYen : in std_logic; -- PIO mode data-port / fast timing device 0
|
92 |
|
|
|
93 |
|
|
dport1_T1,
|
94 |
|
|
dport1_T2,
|
95 |
|
|
dport1_T4,
|
96 |
|
|
dport1_Teoc : in unsigned(7 downto 0);
|
97 |
|
|
dport1_IORDYen : in std_logic; -- PIO mode data-port / fast timing device 1
|
98 |
|
|
|
99 |
|
|
SelDev : in std_logic; -- Selected device
|
100 |
|
|
|
101 |
|
|
go : in std_logic; -- Start transfer sequence
|
102 |
|
|
done : out std_logic; -- Transfer sequence done
|
103 |
|
|
dir : in std_logic; -- Transfer direction '1'=write, '0'=read
|
104 |
|
|
a : in unsigned(3 downto 0); -- PIO transfer address
|
105 |
|
|
q : out std_logic_vector(15 downto 0); -- Data read from ATA devices
|
106 |
|
|
|
107 |
|
|
DDi : in std_logic_vector(15 downto 0); -- Data from ATA DD bus
|
108 |
|
|
oe : buffer std_logic; -- DDbus output-enable signal
|
109 |
|
|
|
110 |
|
|
DIOR,
|
111 |
|
|
DIOW : buffer std_logic;
|
112 |
|
|
IORDY : in std_logic
|
113 |
|
|
);
|
114 |
|
|
end entity atahost_pio_actrl;
|
115 |
|
|
|
116 |
|
|
architecture structural of atahost_pio_actrl is
|
117 |
|
|
--
|
118 |
|
|
-- Component declarations
|
119 |
|
|
--
|
120 |
|
|
component atahost_pio_tctrl is
|
121 |
|
|
generic(
|
122 |
|
|
TWIDTH : natural := 8; -- counter width
|
123 |
|
|
|
124 |
|
|
-- PIO mode 0 settings (@100MHz clock)
|
125 |
|
|
PIO_mode0_T1 : natural := 6; -- 70ns
|
126 |
|
|
PIO_mode0_T2 : natural := 28; -- 290ns
|
127 |
|
|
PIO_mode0_T4 : natural := 2; -- 30ns
|
128 |
|
|
PIO_mode0_Teoc : natural := 23 -- 240ns ==> T0 - T1 - T2 = 600 - 70 - 290 = 240
|
129 |
|
|
);
|
130 |
|
|
port(
|
131 |
|
|
clk : in std_logic; -- master clock
|
132 |
|
|
nReset : in std_logic; -- asynchronous active low reset
|
133 |
|
|
rst : in std_logic; -- synchronous active high reset
|
134 |
|
|
|
135 |
|
|
-- timing/control register settings
|
136 |
|
|
IORDY_en : in std_logic; -- use IORDY (or not)
|
137 |
|
|
T1 : in unsigned(TWIDTH -1 downto 0); -- T1 time (in clk-ticks)
|
138 |
|
|
T2 : in unsigned(TWIDTH -1 downto 0); -- T2 time (in clk-ticks)
|
139 |
|
|
T4 : in unsigned(TWIDTH -1 downto 0); -- T4 time (in clk-ticks)
|
140 |
|
|
Teoc : in unsigned(TWIDTH -1 downto 0); -- end of cycle time
|
141 |
|
|
|
142 |
|
|
-- control signals
|
143 |
|
|
go : in std_logic; -- PIO controller selected (strobe signal)
|
144 |
|
|
we : in std_logic; -- write enable signal. '0'=read from device, '1'=write to device
|
145 |
|
|
|
146 |
|
|
-- return signals
|
147 |
|
|
oe : buffer std_logic; -- output enable signal
|
148 |
|
|
done : out std_logic; -- finished cycle
|
149 |
|
|
dstrb : out std_logic; -- data strobe, latch data (during read)
|
150 |
|
|
|
151 |
|
|
-- ATA signals
|
152 |
|
|
DIOR, -- IOread signal, active high
|
153 |
|
|
DIOW : buffer std_logic; -- IOwrite signal, active high
|
154 |
|
|
IORDY : in std_logic -- IORDY signal
|
155 |
|
|
);
|
156 |
|
|
end component atahost_pio_tctrl;
|
157 |
|
|
|
158 |
|
|
signal dstrb : std_logic;
|
159 |
|
|
signal T1, T2, T4, Teoc : unsigned(TWIDTH -1 downto 0);
|
160 |
|
|
signal IORDYen : std_logic;
|
161 |
|
|
|
162 |
|
|
begin
|
163 |
|
|
--
|
164 |
|
|
--------------------------
|
165 |
|
|
-- PIO transfer control --
|
166 |
|
|
--------------------------
|
167 |
|
|
--
|
168 |
|
|
-- capture ATA data for PIO access
|
169 |
|
|
gen_PIOq: process(clk)
|
170 |
|
|
begin
|
171 |
|
|
if (clk'event and clk = '1') then
|
172 |
|
|
if (dstrb = '1') then
|
173 |
|
|
q <= DDi;
|
174 |
|
|
end if;
|
175 |
|
|
end if;
|
176 |
|
|
end process gen_PIOq;
|
177 |
|
|
|
178 |
|
|
--
|
179 |
|
|
-- PIO timing controllers
|
180 |
|
|
--
|
181 |
|
|
|
182 |
|
|
-- select timing settings for the addressed port
|
183 |
|
|
sel_port_t: process(clk, a, SelDev, IDEctrl_FATR1, IDEctrl_FATR0,
|
184 |
|
|
cmdport_T1, cmdport_T2, cmdport_T4, cmdport_Teoc, cmdport_IORDYen,
|
185 |
|
|
dport0_T1, dport0_T2, dport0_T4, dport0_Teoc, dport0_IORDYen,
|
186 |
|
|
dport1_T1, dport1_T2, dport1_T4, dport1_Teoc, dport1_IORDYen)
|
187 |
|
|
variable Asel : std_logic; -- address selected
|
188 |
|
|
variable iT1, iT2, iT4, iTeoc : unsigned(TWIDTH -1 downto 0);
|
189 |
|
|
variable iIORDYen : std_logic;
|
190 |
|
|
begin
|
191 |
|
|
-- initially set timing registers to compatible timing
|
192 |
|
|
iT1 := cmdport_T1;
|
193 |
|
|
iT2 := cmdport_T2;
|
194 |
|
|
iT4 := cmdport_T4;
|
195 |
|
|
iTeoc := cmdport_Teoc;
|
196 |
|
|
iIORDYen := cmdport_IORDYen;
|
197 |
|
|
|
198 |
|
|
-- detect data-port access
|
199 |
|
|
Asel := not a(3) and not a(2) and not a(1) and not a(0); -- data port
|
200 |
|
|
if (Asel = '1') then -- data port selected, 16bit transfers
|
201 |
|
|
if ((SelDev = '1') and (IDEctrl_FATR1 = '1')) then -- data port1 selected and enabled ?
|
202 |
|
|
iT1 := dport1_T1;
|
203 |
|
|
iT2 := dport1_T2;
|
204 |
|
|
iT4 := dport1_T4;
|
205 |
|
|
iTeoc := dport1_Teoc;
|
206 |
|
|
iIORDYen := dport1_IORDYen;
|
207 |
|
|
elsif((SelDev = '0') and (IDEctrl_FATR0 = '1')) then -- data port0 selected and enabled ?
|
208 |
|
|
iT1 := dport0_T1;
|
209 |
|
|
iT2 := dport0_T2;
|
210 |
|
|
iT4 := dport0_T4;
|
211 |
|
|
iTeoc := dport0_Teoc;
|
212 |
|
|
iIORDYen := dport0_IORDYen;
|
213 |
|
|
end if;
|
214 |
|
|
end if;
|
215 |
|
|
|
216 |
|
|
if (clk'event and clk = '1') then
|
217 |
|
|
T1 <= iT1;
|
218 |
|
|
T2 <= iT2;
|
219 |
|
|
T4 <= iT4;
|
220 |
|
|
Teoc <= iTeoc;
|
221 |
|
|
IORDYen <= iIORDYen;
|
222 |
|
|
end if;
|
223 |
|
|
end process sel_port_t;
|
224 |
|
|
|
225 |
|
|
--
|
226 |
|
|
-- hookup timing controller
|
227 |
|
|
--
|
228 |
|
|
PIO_timing_controller: atahost_pio_tctrl
|
229 |
|
|
generic map (
|
230 |
|
|
TWIDTH => TWIDTH,
|
231 |
|
|
PIO_mode0_T1 => PIO_mode0_T1,
|
232 |
|
|
PIO_mode0_T2 => PIO_mode0_T2,
|
233 |
|
|
PIO_mode0_T4 => PIO_mode0_T4,
|
234 |
|
|
PIO_mode0_Teoc => PIO_mode0_Teoc
|
235 |
|
|
)
|
236 |
|
|
port map (
|
237 |
|
|
clk => clk,
|
238 |
|
|
nReset => nReset,
|
239 |
|
|
rst => rst,
|
240 |
|
|
IORDY_en => IORDYen,
|
241 |
|
|
T1 => T1,
|
242 |
|
|
T2 => T2,
|
243 |
|
|
T4 => T4,
|
244 |
|
|
Teoc => Teoc,
|
245 |
|
|
go => go,
|
246 |
|
|
we => dir,
|
247 |
|
|
oe => oe,
|
248 |
|
|
done => done,
|
249 |
|
|
dstrb => dstrb,
|
250 |
|
|
DIOR => dior,
|
251 |
|
|
DIOW => diow,
|
252 |
|
|
IORDY => IORDY
|
253 |
|
|
);
|
254 |
|
|
end architecture structural;
|
255 |
|
|
|