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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [opencores/] [ata/] [atahost_pio_controller.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
---------------------------------------------------------------------
2
----                                                             ----
3
----  OpenCores IDE Controller                                   ----
4
----  ATA/ATAPI-5 PIO controller with write PingPong             ----
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 8th, 2001. Initial release
37
--
38
--  CVS Log
39
--
40
--  $Id: atahost_pio_controller.vhd,v 1.1 2002/02/18 14:32:12 rherveille Exp $
41
--
42
--  $Date: 2002/02/18 14:32:12 $
43
--  $Revision: 1.1 $
44
--  $Author: rherveille $
45
--  $Locker:  $
46
--  $State: Exp $
47
--
48
-- Change History:
49
--               $Log: atahost_pio_controller.vhd,v $
50
--               Revision 1.1  2002/02/18 14:32:12  rherveille
51
--               renamed all files to 'atahost_***.vhd'
52
--               broke-up 'counter.vhd' into 'ud_cnt.vhd' and 'ro_cnt.vhd'
53
--               changed resD input to generic RESD in ud_cnt.vhd
54
--               changed ID input to generic ID in ro_cnt.vhd
55
--               changed core to reflect changes in ro_cnt.vhd
56
--               removed references to 'count' library
57
--               changed IO names
58
--               added disclaimer
59
--               added CVS log
60
--               moved registers and wishbone signals into 'atahost_wb_slave.vhd'
61
--
62
--
63
 
64
library ieee;
65
use ieee.std_logic_1164.all;
66
use ieee.std_logic_arith.all;
67
 
68
entity atahost_pio_controller is
69
        generic(
70
                TWIDTH : natural := 8;                        -- counter width
71
 
72
                -- PIO mode 0 settings (@100MHz clock)
73
                PIO_mode0_T1 : natural := 6;                  -- 70ns
74
                PIO_mode0_T2 : natural := 28;                 -- 290ns
75
                PIO_mode0_T4 : natural := 2;                  -- 30ns
76
                PIO_mode0_Teoc : natural := 23                -- 240ns ==> T0 - T1 - T2 = 600 - 70 - 290 = 240
77
        );
78
        port(
79
                clk    : in std_logic;                                            -- master clock in
80
                nReset  : in std_logic;                 -- asynchronous active low reset
81
                rst    : in std_logic;                 -- synchronous active high reset
82
 
83
                -- control / registers
84
                IDEctrl_IDEen,
85
                IDEctrl_ppen,
86
                IDEctrl_FATR0,
87
                IDEctrl_FATR1 : in std_logic;
88
 
89
                -- PIO registers
90
                cmdport_T1,
91
                cmdport_T2,
92
                cmdport_T4,
93
                cmdport_Teoc : in std_logic_vector(7 downto 0);
94
                cmdport_IORDYen : in std_logic;               -- PIO command port / non-fast timing
95
 
96
                dport0_T1,
97
                dport0_T2,
98
                dport0_T4,
99
                dport0_Teoc : in std_logic_vector(7 downto 0);
100
                dport0_IORDYen : in std_logic;                -- PIO mode data-port / fast timing device 0
101
 
102
                dport1_T1,
103
                dport1_T2,
104
                dport1_T4,
105
                dport1_Teoc : in std_logic_vector(7 downto 0);
106
                dport1_IORDYen : in std_logic;                -- PIO mode data-port / fast timing device 1
107
 
108
                sel : in  std_logic;                          -- PIO controller selected
109
                ack : out std_logic;                          -- PIO controller acknowledge
110
                a   : in  std_logic_vector(3 downto 0);               -- lower address bits
111
                we  : in  std_logic;                          -- write enable input
112
                d   : in  std_logic_vector(15 downto 0);
113
                q   : out std_logic_vector(15 downto 0);
114
 
115
                PIOreq : out std_logic;                       -- PIO transfer request
116
                PPFull : out std_logic;                       -- PIO Write PingPong Full
117
                go     : in std_logic;                        -- start PIO transfer
118
                done   : out std_logic;                    -- done with PIO transfer
119
 
120
                PIOa : out std_logic_vector(3 downto 0);              -- PIO address, address lines towards ATA devices
121
                PIOd : out std_logic_vector(15 downto 0);     -- PIO data, data towards ATA devices
122
 
123
                SelDev : out std_logic;                    -- Selected Device, Dev-bit in ATA Device/Head register
124
 
125
                DDi      : in std_logic_vector(15 downto 0);
126
                DDoe : out std_logic;
127
 
128
                DIOR     : out std_logic;
129
                DIOW     : out std_logic;
130
                IORDY   : in std_logic
131
        );
132
end entity atahost_pio_controller;
133
 
134
architecture structural of atahost_pio_controller is
135
        --
136
        -- component declarations
137
        --
138
        component atahost_pio_actrl is
139
        generic(
140
                TWIDTH : natural := 8;                     -- counter width
141
 
142
                -- PIO mode 0 settings (@100MHz clock)
143
                PIO_mode0_T1 : natural := 6;               -- 70ns
144
                PIO_mode0_T2 : natural := 28;              -- 290ns
145
                PIO_mode0_T4 : natural := 2;               -- 30ns
146
                PIO_mode0_Teoc : natural := 23             -- 240ns ==> T0 - T1 - T2 = 600 - 70 - 290 = 240
147
        );
148
        port(
149
                clk    : in std_logic;                     -- master clock
150
                nReset : in std_logic;                     -- asynchronous active low reset
151
                rst    : in std_logic;                     -- synchronous active high reset
152
 
153
                IDEctrl_FATR0,
154
                IDEctrl_FATR1 : in std_logic;
155
 
156
                cmdport_T1,
157
                cmdport_T2,
158
                cmdport_T4,
159
                cmdport_Teoc : in std_logic_vector(7 downto 0);
160
                cmdport_IORDYen : in std_logic;            -- PIO command port / non-fast timing
161
 
162
                dport0_T1,
163
                dport0_T2,
164
                dport0_T4,
165
                dport0_Teoc : in std_logic_vector(7 downto 0);
166
                dport0_IORDYen : in std_logic;             -- PIO mode data-port / fast timing device 0
167
 
168
                dport1_T1,
169
                dport1_T2,
170
                dport1_T4,
171
                dport1_Teoc : in std_logic_vector(7 downto 0);
172
                dport1_IORDYen : in std_logic;             -- PIO mode data-port / fast timing device 1
173
 
174
                SelDev : in std_logic;                     -- Selected device   
175
 
176
                go   : in  std_logic;                      -- Start transfer sequence
177
                done : out std_logic;                      -- Transfer sequence done
178
                dir  : in  std_logic;                      -- Transfer direction '1'=write, '0'=read
179
                a    : in  std_logic_vector(3 downto 0);           -- PIO transfer address
180
                q    : out std_logic_vector(15 downto 0);  -- Data read from ATA devices
181
 
182
                DDi : in std_logic_vector(15 downto 0);    -- Data from ATA DD bus
183
                oe  : out std_logic;                    -- DDbus output-enable signal
184
 
185
                DIOR,
186
                DIOW  : out std_logic;
187
                IORDY : in std_logic
188
        );
189
        end component atahost_pio_actrl;
190
 
191
        --
192
        -- signals
193
        --
194
 
195
        -- PIO pingpong signals
196
        signal pp_d : std_logic_vector(15 downto 0);
197
        signal pp_a : std_logic_vector(3 downto 0);
198
        signal pp_we : std_logic;
199
        signal idone : std_logic;
200
        signal iSelDev : std_logic;
201
 
202
begin
203
        --
204
        -- generate selected device
205
        --
206
        gen_seldev: process(clk, pp_a)
207
                variable Asel : std_logic; -- address selected
208
        begin
209
                Asel := not pp_a(3) and pp_a(2) and pp_a(1) and not pp_a(0); -- header/device register
210
 
211
                if (clk'event and clk = '1') then
212
                        if ( (idone = '1') and (Asel = '1') and (pp_we = '1') ) then
213
                                iSelDev <= pp_d(4);
214
                        end if;
215
                end if;
216
        end process gen_seldev;
217
 
218
        --
219
        -- generate PIO write pingpong system
220
        --
221
        gen_pingpong: block
222
                signal ping_d, pong_d : std_logic_vector(15 downto 0);
223
                signal ping_a, pong_a : std_logic_vector(3 downto 0);
224
                signal ping_we, pong_we : std_logic;
225
                signal ping_valid, pong_valid : std_logic;
226
                signal dping_valid, dpong_valid : std_logic;
227
                signal wpp, rpp : std_logic;
228
 
229
                signal dsel, sel_strb : std_logic;
230
 
231
                signal iack : std_logic;
232
        begin
233
                -- generate PIO acknowledge
234
                gen_ack: process(clk, ping_valid, dping_valid, pong_valid, dpong_valid, we)
235
                        variable ping_re, ping_fe, pong_re, pong_fe : std_logic;
236
                begin
237
                        -- detect rising edge of ping_valid and pong_valid
238
                        ping_re := ping_valid and not dping_valid and we;
239
                        pong_re := pong_valid and not dpong_valid and we;
240
 
241
                        -- detect falling edge of ping_valid and pong_valid
242
                        ping_fe := not ping_valid and dping_valid;
243
                        pong_fe := not pong_valid and dpong_valid;
244
 
245
                        if (clk'event and clk = '1') then
246
                                if ((pp_we = '1') and (IDEctrl_ppen = '1')) then -- write sequence
247
                                        if (wpp = '1') then
248
                                                iack <= ping_re;
249
                                        else
250
                                                iack <= pong_re;
251
                                        end if;
252
                                else                                           -- read sequence
253
                                        if (rpp = '1') then
254
                                                iack <= ping_fe;
255
                                        else
256
                                                iack <= pong_fe;
257
                                        end if;
258
                                end if;
259
                        end if;
260
                end process gen_ack;
261
                ack <= (iack or not IDEctrl_IDEen) and sel; -- acknowledge access when not enabled (discard access)
262
 
263
                -- generate select-strobe, hold sel_strb until pingpong system ready for new data
264
                gen_sel_strb: process(clk, nReset)
265
                begin
266
                        if (nReset = '0') then
267
                                dsel <= '0';
268
                        elsif (clk'event and clk = '1') then
269
                                if (rst = '1') then
270
                                        dsel <= '0';
271
                                else
272
                                        dsel <= sel_strb or (dsel and sel);
273
                                end if;
274
                        end if;
275
                end process gen_sel_strb;
276
                sel_strb <= sel and not dsel and IDEctrl_IDEen and ((wpp and not ping_valid) or (not wpp and not pong_valid));
277
 
278
                -- generate pingpong control
279
                gen_pp : process(clk, nReset)
280
                begin
281
                        if (nReset = '0') then
282
                                wpp <= '0';
283
                                rpp <= '0';
284
                                ping_valid <= '0';
285
                                pong_valid <= '0';
286
                                dping_valid <= '0';
287
                                dpong_valid <= '0';
288
                        elsif (clk'event and clk = '1') then
289
                                if (rst = '1') then
290
                                        wpp <= '0';
291
                                        rpp <= '0';
292
                                        ping_valid <= '0';
293
                                        pong_valid <= '0';
294
                                        dping_valid <= '0';
295
                                        dpong_valid <= '0';
296
                                else
297
                                        wpp <= (wpp xor (iack and we)) and IDEctrl_ppen;
298
                                        rpp <= (rpp xor (idone and pp_we)) and IDEctrl_ppen;
299
                                        ping_valid <= ((    wpp and sel_strb) or ping_valid) and not (    rpp and idone);
300
                                        pong_valid <= ((not wpp and sel_strb) or pong_valid) and not (not rpp and idone);
301
                                        dping_valid <= ping_valid;
302
                                        dpong_valid <= pong_valid;
303
                                end if;
304
                        end if;
305
                end process gen_pp;
306
 
307
                -- generate pingpong full signal
308
                PPFull <= (ping_valid and pong_valid) when (IDEctrl_ppen = '1') else pong_valid;
309
 
310
                -- fill ping/pong registers
311
                fill_pp: process(clk)
312
                begin
313
                        if (clk'event and clk = '1') then
314
                                if (sel = '1') then
315
                                        if (wpp = '1') then
316
                                                if (ping_valid = '0') then
317
                                                        ping_d <= d;
318
                                                        ping_a <= a;
319
                                                        ping_we <= we;
320
                                                end if;
321
                                        else
322
                                                if (pong_valid = '0') then
323
                                                        pong_d <= d;
324
                                                        pong_a <= a;
325
                                                        pong_we <= we;
326
                                                end if;
327
                                        end if;
328
                                end if;
329
                        end if;
330
                end process fill_pp;
331
 
332
                -- multiplex pingpong data to pp_d, pp_a, pp_we
333
                pp_d <= d;
334
                pp_a <= a;
335
                pp_we <= we;
336
 
337
--edit by erik (no pp)
338
--              pp_d <= ping_d when (rpp = '1') else pong_d;
339
--              pp_a <= ping_a when (rpp = '1') else pong_a;
340
--              pp_we <= ping_we when (rpp = '1') else pong_we;
341
                -- generate PIOreq
342
                PIOreq <= (ping_valid and not idone) when (rpp = '1') else (pong_valid and not idone);
343
        end block gen_pingpong;
344
 
345
        --
346
        -- Hookup PIO access controller
347
        --
348
        PIO_access_control: atahost_pio_actrl
349
                generic map(
350
                        TWIDTH => TWIDTH,
351
                        PIO_mode0_T1 => PIO_mode0_T1,
352
                        PIO_mode0_T2 => PIO_mode0_T2,
353
                        PIO_mode0_T4 => PIO_mode0_T4,
354
                        PIO_mode0_Teoc => PIO_mode0_Teoc
355
                )
356
                port map(
357
                        clk    => clk,
358
                        nReset => nReset,
359
                        rst    => rst,
360
                        IDEctrl_FATR0 => IDEctrl_FATR0,
361
                        IDEctrl_FATR1 => IDEctrl_FATR1,
362
                        cmdport_T1   => cmdport_T1,
363
                        cmdport_T2   => cmdport_T2,
364
                        cmdport_T4   => cmdport_T4,
365
                        cmdport_Teoc => cmdport_Teoc,
366
                        cmdport_IORDYen => cmdport_IORDYen,
367
                        dport0_T1   => dport0_T1,
368
                        dport0_T2   => dport0_T2,
369
                        dport0_T4   => dport0_T4,
370
                        dport0_Teoc => dport0_Teoc,
371
                        dport0_IORDYen => dport0_IORDYen,
372
                        dport1_T1   => dport1_T1,
373
                        dport1_T2   => dport1_T2,
374
                        dport1_T4   => dport1_T4,
375
                        dport1_Teoc => dport1_Teoc,
376
                        dport1_IORDYen => dport1_IORDYen,
377
                        SelDev => iSelDev,
378
                        go     => go,
379
                        done   => idone,
380
                        dir    => pp_we,
381
                        a      => pp_a,
382
                        q      => Q,
383
                        DDi    => DDi,
384
                        oe     => DDoe,
385
                        DIOR   => dior,
386
                        DIOW   => diow,
387
                        IORDY  => IORDY
388
                );
389
 
390
        --
391
        -- assign outputs
392
        --
393
        PIOa <= pp_a;
394
        PIOd <= pp_d;
395
        Done <= idone;
396
        SelDev <= iSelDev;
397
end architecture structural;
398
 

powered by: WebSVN 2.1.0

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