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

Subversion Repositories ata

[/] [ata/] [trunk/] [rtl/] [verilog/] [ocidec-1/] [atahost_pio_tctrl.v] - Blame information for rev 22

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 22 rherveille
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  OCIDEC-1 ATA Controller                                    ////
4
////  PIO Mode timing controller                                 ////
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 15 rherveille
 
36 22 rherveille
//  CVS Log
37 15 rherveille
//
38 22 rherveille
//  $Id: atahost_pio_tctrl.v,v 1.2 2002-02-16 10:42:17 rherveille Exp $
39 15 rherveille
//
40 22 rherveille
//  $Date: 2002-02-16 10:42:17 $
41
//  $Revision: 1.2 $
42
//  $Author: rherveille $
43
//  $Locker:  $
44
//  $State: Exp $
45
//
46
// Change History:
47
//               Rev. 1.0 June 27th, 2001. Initial Verilog release
48
//               Rev. 1.1 July  2nd, 2001. Fixed incomplete port list and some Verilog related issues.
49
//               Rev. 1.2 July 11th, 2001. Changed 'igo' & 'hold_go' generation.
50
//
51
//               $Log: not supported by cvs2svn $
52
//
53 15 rherveille
 
54 22 rherveille
 
55 15 rherveille
//
56
// Timing       PIO mode transfers
57
//--------------------------------------------
58
// T0:  cycle time
59
// T1:  address valid to DIOR-/DIOW-
60
// T2:  DIOR-/DIOW- pulse width
61
// T2i: DIOR-/DIOW- recovery time
62
// T3:  DIOW- data setup
63
// T4:  DIOW- data hold
64
// T5:  DIOR- data setup
65
// T6:  DIOR- data hold
66
// T9:  address hold from DIOR-/DIOW- negated
67
// Trd: Read data valid to IORDY asserted
68
// Ta:  IORDY setup time
69
// Tb:  IORDY pulse width
70
//
71
// Transfer sequence
72
//--------------------------------
73
// 1)   set address (DA, CS0-, CS1-)
74
// 2)   wait for T1
75
// 3)   assert DIOR-/DIOW-
76
//         when write action present Data (timing spec. T3 always honored), enable output enable-signal
77
// 4)   wait for T2
78
// 5)   check IORDY
79
//         when not IORDY goto 5
80
//        when IORDY negate DIOW-/DIOR-, latch data (if read action)
81
//    when write, hold data for T4, disable output-enable signal
82
// 6)   wait end_of_cycle_time. This is T2i or T9 or (T0-T1-T2) whichever takes the longest
83
// 7)   start new cycle
84
 
85
`include "timescale.v"
86
 
87
module atahost_pio_tctrl(clk, nReset, rst, IORDY_en, T1, T2, T4, Teoc, go, we, oe, done, dstrb, DIOR, DIOW, IORDY);
88
        // parameter declarations
89
        parameter TWIDTH = 8;
90
        parameter PIO_MODE0_T1   =  6;             // 70ns
91
        parameter PIO_MODE0_T2   = 28;             // 290ns
92
        parameter PIO_MODE0_T4   =  2;             // 30ns
93
        parameter PIO_MODE0_Teoc = 23;             // 240ns
94
 
95
        // inputs & outputs
96
        input clk; // master clock
97
        input nReset; // asynchronous active low reset
98
        input rst; // synchronous active high reset
99
 
100
        // timing & control register settings
101
        input IORDY_en;          // use IORDY (or not)
102
        input [TWIDTH-1:0] T1;   // T1 time (in clk-ticks)
103
        input [TWIDTH-1:0] T2;   // T1 time (in clk-ticks)
104
        input [TWIDTH-1:0] T4;   // T1 time (in clk-ticks)
105
        input [TWIDTH-1:0] Teoc; // T1 time (in clk-ticks)
106
 
107
        // control signals
108
        input go; // PIO controller selected (strobe signal)
109
        input we; // write enable signal. 1'b0 == read, 1'b1 == write
110
 
111
        // return signals
112
        output oe; // output enable signal
113
        reg oe;
114
        output done; // finished cycle
115
        output dstrb; // data strobe, latch data (during read)
116
        reg dstrb;
117
 
118
        // ata signals
119
        output DIOR; // IOread signal, active high
120
        reg DIOR;
121
        output DIOW; // IOwrite signal, active high
122
        reg DIOW;
123
        input  IORDY; // IOrDY signal
124
 
125
 
126
        //
127
        // constant declarations
128
        //
129
        // PIO mode 0 settings (@100MHz clock)
130
        wire [TWIDTH-1:0] T1_m0   = PIO_MODE0_T1;
131
        wire [TWIDTH-1:0] T2_m0   = PIO_MODE0_T2;
132
        wire [TWIDTH-1:0] T4_m0   = PIO_MODE0_T4;
133
        wire [TWIDTH-1:0] Teoc_m0 = PIO_MODE0_Teoc;
134
 
135
        //
136
        // variable declaration
137
        //
138
        reg busy, hold_go;
139
        wire igo;
140
        wire T1done, T2done, T4done, Teoc_done, IORDY_done;
141
        reg hT2done;
142
 
143
        //
144
        // module body
145
        //
146
 
147
        // generate internal go strobe
148
        // strecht go until ready for new cycle
149
        always@(posedge clk or negedge nReset)
150
                if (~nReset)
151
                        begin
152
                                busy <= 1'b0;
153
                                hold_go <= 1'b0;
154
                        end
155
                else if (rst)
156
                        begin
157
                                busy <= 1'b0;
158
                                hold_go <= 1'b0;
159
                        end
160
                else
161
                        begin
162
                                busy <= (igo | busy) & !Teoc_done;
163
                                hold_go <= (go | (hold_go & busy)) & !igo;
164
                        end
165
 
166
        assign igo = (go | hold_go) & !busy;
167
 
168
        // 1)   hookup T1 counter
169 22 rherveille
        ro_cnt #(TWIDTH, 1'b0, PIO_MODE0_T1)
170
                t1_cnt(
171
                        .clk(clk),
172
                        .rst(rst),
173
                        .nReset(nReset),
174
                        .cnt_en(1'b1),
175
                        .go(igo),
176
                        .d(T1),
177
                        .q(),
178
                        .done(T1done)
179
                );
180 15 rherveille
 
181
        // 2)   set (and reset) DIOR-/DIOW-, set output-enable when writing to device
182
        always@(posedge clk or negedge nReset)
183
                if (~nReset)
184
                        begin
185
                                DIOR <= 1'b0;
186
                                DIOW <= 1'b0;
187
                                oe   <= 1'b0;
188
                        end
189
                else if (rst)
190
                        begin
191
                                DIOR <= 1'b0;
192
                                DIOW <= 1'b0;
193
                                oe   <= 1'b0;
194
                        end
195
                else
196
                        begin
197
                                DIOR <= (!we & T1done) | (DIOR & !IORDY_done);
198
                                DIOW <= ( we & T1done) | (DIOW & !IORDY_done);
199
                                oe   <= ( (we & igo) | oe) & !T4done;           // negate oe when t4-done
200
                        end
201
 
202
        // 3)   hookup T2 counter
203 22 rherveille
        ro_cnt #(TWIDTH, 1'b0, PIO_MODE0_T2)
204
                t2_cnt(
205
                        .clk(clk),
206
                        .rst(rst),
207
                        .nReset(nReset),
208
                        .cnt_en(1'b1),
209
                        .go(T1done),
210
                        .d(T2),
211
                        .q(),
212
                        .done(T2done)
213
                );
214 15 rherveille
 
215
        // 4)   check IORDY (if used), generate release_DIOR-/DIOW- signal (ie negate DIOR-/DIOW-)
216
        // hold T2done
217
        always@(posedge clk or negedge nReset)
218
                if (~nReset)
219
                        hT2done <= 1'b0;
220
                else if (rst)
221
                        hT2done <= 1'b0;
222
                else
223
                                hT2done <= (T2done | hT2done) & !IORDY_done;
224
 
225
        assign IORDY_done = (T2done | hT2done) & (IORDY | !IORDY_en);
226
 
227
        // generate datastrobe, capture data at rising DIOR- edge
228
        always@(posedge clk)
229
                dstrb <= IORDY_done;
230
 
231
        // hookup data hold counter
232 22 rherveille
        ro_cnt #(TWIDTH, 1'b0, PIO_MODE0_T4)
233
                dhold_cnt(
234
                        .clk(clk),
235
                        .rst(rst),
236
                        .nReset(nReset),
237
                        .cnt_en(1'b1),
238
                        .go(IORDY_done),
239
                        .d(T4),
240
                        .q(),
241
                        .done(T4done)
242
                );
243
 
244 15 rherveille
        assign done = T4done; // placing done here provides the fastest return possible, 
245
                        // while still guaranteeing data and address hold-times
246
 
247
        // 5)   hookup end_of_cycle counter
248 22 rherveille
        ro_cnt #(TWIDTH, 1'b0, PIO_MODE0_Teoc)
249
                eoc_cnt(
250
                        .clk(clk),
251
                        .rst(rst),
252
                        .nReset(nReset),
253
                        .cnt_en(1'b1),
254
                        .go(IORDY_done),
255
                        .d(Teoc),
256
                        .q(),
257
                        .done(Teoc_done)
258
                );
259 15 rherveille
 
260
endmodule

powered by: WebSVN 2.1.0

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