?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3 <title>Procyon AVRlib: ata.c Source File</title>
4 <link href="dox.css" rel="stylesheet" type="text/css">
5 </head><body>
6 <!-- Generated by Doxygen 1.4.2 -->
7 <div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
8 <h1>ata.c</h1><a href="ata_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file ata.c \brief IDE-ATA hard disk interface driver. */</span>
9 00002 <span class="comment">//*****************************************************************************</span>
10 00003 <span class="comment">//</span>
11 00004 <span class="comment">// File Name : 'ata.c'</span>
12 00005 <span class="comment">// Title : IDE-ATA interface driver for hard disks</span>
13 00006 <span class="comment">// Author : Pascal Stang</span>
14 00007 <span class="comment">// Date : 11/22/2000</span>
15 00008 <span class="comment">// Revised : 4/19/2003</span>
16 00009 <span class="comment">// Version : 0.3</span>
17 00010 <span class="comment">// Target MCU : Atmel AVR Series</span>
18 00011 <span class="comment">// Editor Tabs : 4</span>
19 00012 <span class="comment">//</span>
20 00013 <span class="comment">// NOTE: This code is currently below version 1.0, and therefore is considered</span>
21 00014 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span>
22 00015 <span class="comment">// tested. Nonetheless, you can expect most functions to work.</span>
23 00016 <span class="comment">//</span>
24 00017 <span class="comment">// This code is distributed under the GNU Public License</span>
25 00018 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>
26 00019 <span class="comment">//</span>
27 00020 <span class="comment">//*****************************************************************************</span>
28 00021
29 00022 <span class="preprocessor">#ifndef WIN32</span>
30 00023 <span class="preprocessor"></span><span class="preprocessor"> #include &lt;avr/io.h&gt;</span>
31 00024 <span class="preprocessor"> #include &lt;avr/interrupt.h&gt;</span>
32 00025 <span class="preprocessor"> #include &lt;avr/pgmspace.h&gt;</span>
33 00026 <span class="comment">// #include &lt;stdio.h&gt;</span>
34 00027 <span class="preprocessor">#endif</span>
35 00028 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>
36 00029 <span class="preprocessor">#include "<a class="code" href="timer_8h.html">timer.h</a>"</span>
37 00030 <span class="preprocessor">#include "<a class="code" href="rprintf_8h.html">rprintf.h</a>"</span>
38 00031
39 00032 <span class="preprocessor">#include "<a class="code" href="ata_8h.html">ata.h</a>"</span>
40 00033
41 00034 <span class="comment">//#define DEBUG_ATA 1</span>
42 00035
43 00036 <span class="comment">// global variables</span>
44 00037
45 00038 <span class="comment">// drive information</span>
46 00039 typeDriveInfo ataDriveInfo;
47 00040
48 00041
49 00042 <span class="keywordtype">void</span> ataInit(<span class="keywordtype">void</span>)
50 00043 {
51 00044
52 00045 }
53 00046
54 00047 <span class="keywordtype">void</span> ataDriveInit(<span class="keywordtype">void</span>)
55 00048 {
56 00049 u08 i;
57 00050 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buffer = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) SECTOR_BUFFER_ADDR;
58 00051
59 00052 <span class="comment">// read drive identity</span>
60 00053 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"\r\nScanning IDE interface...\r\n"</span>);
61 00054 <span class="comment">// Wait for drive to be ready</span>
62 00055 ataStatusWait(ATA_SR_BSY, ATA_SR_BSY);
63 00056 <span class="comment">// issue identify command</span>
64 00057 ataWriteByte(ATA_REG_CMDSTATUS1, 0xEC);
65 00058 <span class="comment">// wait for drive to request data transfer</span>
66 00059 ataStatusWait(ATA_SR_DRQ, ATA_SR_DRQ);
67 00060 <a class="code" href="group__timer.html#ga10">timerPause</a>(200);
68 00061 <span class="comment">// read in the data</span>
69 00062 ataReadDataBuffer(buffer, 512);
70 00063
71 00064 <span class="comment">// set local drive info parameters</span>
72 00065 ataDriveInfo.cylinders = *( ((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>*) buffer) + ATA_IDENT_CYLINDERS );
73 00066 ataDriveInfo.heads = *( ((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>*) buffer) + ATA_IDENT_HEADS );
74 00067 ataDriveInfo.sectors = *( ((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>*) buffer) + ATA_IDENT_SECTORS );
75 00068 ataDriveInfo.LBAsupport = *( ((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>*) buffer) + ATA_IDENT_FIELDVALID );
76 00069 ataDriveInfo.sizeinsectors = *( (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>*) (buffer + ATA_IDENT_LBASECTORS*2) );
77 00070 <span class="comment">// copy model string</span>
78 00071 <span class="keywordflow">for</span>(i=0; i&lt;40; i+=2)
79 00072 {
80 00073 <span class="comment">// correct for byte order</span>
81 00074 ataDriveInfo.model[i ] = buffer[(ATA_IDENT_MODEL*2) + i + 1];
82 00075 ataDriveInfo.model[i+1] = buffer[(ATA_IDENT_MODEL*2) + i ];
83 00076 }
84 00077 <span class="comment">// terminate string</span>
85 00078 ataDriveInfo.model[40] = 0;
86 00079
87 00080 <span class="comment">// process and print info</span>
88 00081 <span class="keywordflow">if</span>(ataDriveInfo.LBAsupport)
89 00082 {
90 00083 <span class="comment">// LBA support</span>
91 00084 rprintf(<span class="stringliteral">"Drive 0: %dMB "</span>, ataDriveInfo.sizeinsectors/(1000000/512) );
92 00085 rprintf(<span class="stringliteral">"LBA mode -- MODEL: "</span>);
93 00086 }
94 00087 <span class="keywordflow">else</span>
95 00088 {
96 00089 <span class="comment">// CHS, no LBA support</span>
97 00090 <span class="comment">// calculate drive size</span>
98 00091 ataDriveInfo.sizeinsectors = (<span class="keywordtype">unsigned</span> long) ataDriveInfo.cylinders*
99 00092 ataDriveInfo.heads*ataDriveInfo.sectors;
100 00093 rprintf(<span class="stringliteral">"Drive 0: %dMB "</span>, ataDriveInfo.sizeinsectors/(1000000/512) );
101 00094 rprintf(<span class="stringliteral">"CHS mode C=%d H=%d S=%d -- MODEL: "</span>, ataDriveInfo.cylinders, ataDriveInfo.heads, ataDriveInfo.sectors );
102 00095 }
103 00096 <span class="comment">// print model information </span>
104 00097 <a class="code" href="group__rprintf.html#ga2">rprintfStr</a>(ataDriveInfo.model); <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>();
105 00098
106 00099 <span class="comment">// initialize local disk parameters</span>
107 00100 <span class="comment">//ataDriveInfo.cylinders = ATA_DISKPARM_CLYS;</span>
108 00101 <span class="comment">//ataDriveInfo.heads = ATA_DISKPARM_HEADS;</span>
109 00102 <span class="comment">//ataDriveInfo.sectors = ATA_DISKPARM_SECTORS;</span>
110 00103
111 00104 }
112 00105
113 00106 <span class="keywordtype">void</span> ataDiskErr(<span class="keywordtype">void</span>)
114 00107 {
115 00108 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> b;
116 00109
117 00110 b = ataReadByte(ATA_REG_ERROR);
118 00111 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"ATA Error: "</span>);
119 00112 <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(b);
120 00113 <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>();
121 00114 }
122 00115
123 00116 <span class="keywordtype">void</span> ataSetDrivePowerMode(u08 DriveNo, u08 mode, u08 timeout)
124 00117 {
125 00118 <span class="comment">// select drive</span>
126 00119 ataDriveSelect(DriveNo);
127 00120 <span class="comment">// Wait for drive to be ready</span>
128 00121 ataStatusWait(ATA_SR_BSY, ATA_SR_BSY);
129 00122
130 00123 <span class="comment">// set mode</span>
131 00124 <span class="keywordflow">switch</span>(mode)
132 00125 {
133 00126 <span class="keywordflow">case</span> ATA_DISKMODE_SPINDOWN: ataWriteByte(ATA_REG_CMDSTATUS1, ATA_CMD_SPINDOWN); <span class="keywordflow">break</span>;
134 00127 <span class="keywordflow">case</span> ATA_DISKMODE_SPINUP: ataWriteByte(ATA_REG_CMDSTATUS1, ATA_CMD_SPINUP); <span class="keywordflow">break</span>;
135 00128 <span class="keywordflow">case</span> ATA_DISKMODE_SETTIMEOUT:
136 00129 ataWriteByte(ATA_REG_SECCOUNT, timeout);
137 00130 ataWriteByte(ATA_REG_CMDSTATUS1, ATA_CMD_IDLE_5SU);
138 00131 <span class="keywordflow">break</span>;
139 00132 <span class="keywordflow">case</span> ATA_DISKMODE_SLEEP: ataWriteByte(ATA_REG_CMDSTATUS1, ATA_CMD_SLEEP); <span class="keywordflow">break</span>;
140 00133 <span class="keywordflow">default</span>:
141 00134 <span class="keywordflow">break</span>;
142 00135 }
143 00136 }
144 00137
145 00138 <span class="keywordtype">void</span> ataPrintSector( u08 *Buffer)
146 00139 {
147 00140 u08 i;
148 00141 u16 j;
149 00142 u08 *buf;
150 00143 u08 s;
151 00144
152 00145 buf = Buffer;
153 00146
154 00147 <span class="comment">// print the low order address indicies</span>
155 00148 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\r\n"</span>);
156 00149 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" ----------------------------------------------- ---- ASCII -----\r\n"</span>);
157 00150
158 00151 <span class="comment">// print the data</span>
159 00152 <span class="keywordflow">for</span>(j=0; j&lt;0x20; j++)
160 00153 {
161 00154 <span class="comment">// print the high order address index for this line</span>
162 00155 <a class="code" href="group__rprintf.html#ga8">rprintfu16</a>(j&lt;&lt;4);
163 00156 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" "</span>);
164 00157
165 00158 <span class="comment">// print the hex data</span>
166 00159 <span class="keywordflow">for</span>(i=0; i&lt;0x10; i++)
167 00160 {
168 00161 <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(buf[(j&lt;&lt;4)+i]);
169 00162 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" "</span>);
170 00163 }
171 00164
172 00165 <span class="comment">// leave some space</span>
173 00166 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" "</span>);
174 00167
175 00168 <span class="comment">// print the ascii data</span>
176 00169 <span class="keywordflow">for</span>(i=0; i&lt;0x10; i++)
177 00170 {
178 00171 s = buf[(j&lt;&lt;4)+i];
179 00172 <span class="comment">// make sure character is printable</span>
180 00173 <span class="keywordflow">if</span>(s &gt;= 0x20)
181 00174 {
182 00175 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(s);
183 00176 }
184 00177 <span class="keywordflow">else</span>
185 00178 {
186 00179 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(0x20);
187 00180 }
188 00181
189 00182 }
190 00183 <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>();
191 00184 }
192 00185 }
193 00186
194 00187 <span class="keywordtype">void</span> ataReadDataBuffer(u08 *Buffer, u16 numBytes)
195 00188 {
196 00189 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;
197 00190
198 00191 <span class="comment">//sbi(MCUCR, SRW); // enable RAM waitstate</span>
199 00192
200 00193 <span class="comment">// read data from drive</span>
201 00194 <span class="keywordflow">for</span> (i=0; i&lt;(numBytes/16); i++)
202 00195 {
203 00196 <span class="comment">// optimize by reading 16 bytes in-line before looping</span>
204 00197 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL);
205 00198 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH);
206 00199 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL);
207 00200 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH);
208 00201 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL);
209 00202 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH);
210 00203 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL);
211 00204 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH);
212 00205 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL);
213 00206 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH);
214 00207 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL);
215 00208 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH);
216 00209 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL);
217 00210 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH);
218 00211 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL);
219 00212 *Buffer++ = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH);
220 00213 }
221 00214 <span class="comment">//cbi(MCUCR, SRW); // disable RAM waitstate</span>
222 00215
223 00216 }
224 00217
225 00218 <span class="keywordtype">void</span> ataWriteDataBuffer(u08 *Buffer, u16 numBytes)
226 00219 {
227 00220 <span class="keyword">register</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> temp;
228 00221 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;
229 00222
230 00223 <span class="comment">//sbi(MCUCR, SRW); // enable RAM waitstate</span>
231 00224
232 00225 <span class="comment">// write data to drive</span>
233 00226 <span class="keywordflow">for</span> (i=0; i&lt;(numBytes/16); i++)
234 00227 {
235 00228 <span class="comment">// optimize by writing 16 bytes in-line before looping</span>
236 00229 <span class="comment">// keep byte order correct by using temp register</span>
237 00230 temp = *Buffer++;
238 00231 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH) = *Buffer++;
239 00232 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL) = temp;
240 00233 temp = *Buffer++;
241 00234 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH) = *Buffer++;
242 00235 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL) = temp;
243 00236 temp = *Buffer++;
244 00237 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH) = *Buffer++;
245 00238 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL) = temp;
246 00239 temp = *Buffer++;
247 00240 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH) = *Buffer++;
248 00241 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL) = temp;
249 00242 temp = *Buffer++;
250 00243 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH) = *Buffer++;
251 00244 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL) = temp;
252 00245 temp = *Buffer++;
253 00246 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH) = *Buffer++;
254 00247 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL) = temp;
255 00248 temp = *Buffer++;
256 00249 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH) = *Buffer++;
257 00250 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL) = temp;
258 00251 temp = *Buffer++;
259 00252 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAH) = *Buffer++;
260 00253 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + ATA_REG_DATAL) = temp;
261 00254 }
262 00255 <span class="comment">//cbi(MCUCR, SRW); // disable RAM waitstate</span>
263 00256
264 00257 }
265 00258
266 00259 u08 ataStatusWait(u08 mask, u08 waitStatus)
267 00260 {
268 00261 <span class="keyword">register</span> u08 status;
269 00262
270 00263 delay(100);
271 00264
272 00265 <span class="comment">// wait for desired status</span>
273 00266 <span class="keywordflow">while</span>( ((status = ataReadByte(ATA_REG_CMDSTATUS1)) &amp; mask) == waitStatus );
274 00267
275 00268 <span class="keywordflow">return</span> status;
276 00269 }
277 00270
278 00271
279 00272 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ataReadSectorsCHS( <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> Drive,
280 00273 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> Head,
281 00274 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Track,
282 00275 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> Sector,
283 00276 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> numsectors,
284 00277 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *Buffer)
285 00278 {
286 00279 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> temp;
287 00280
288 00281 <span class="comment">// Wait for drive to be ready</span>
289 00282 temp = ataStatusWait(ATA_SR_BSY, ATA_SR_BSY);
290 00283
291 00284 <span class="comment">// Prepare parameters...</span>
292 00285 ataWriteByte(ATA_REG_HDDEVSEL, 0xA0+(Drive ? 0x10:00)+Head); <span class="comment">// CHS mode/Drive/Head</span>
293 00286 ataWriteByte(ATA_REG_CYLHI, Track&gt;&gt;8); <span class="comment">// MSB of track</span>
294 00287 ataWriteByte(ATA_REG_CYLLO, Track); <span class="comment">// LSB of track</span>
295 00288 ataWriteByte(ATA_REG_STARTSEC, Sector); <span class="comment">// sector</span>
296 00289 ataWriteByte(ATA_REG_SECCOUNT, numsectors); <span class="comment">// # of sectors</span>
297 00290
298 00291 <span class="comment">// Issue read sector command...</span>
299 00292 ataWriteByte(ATA_REG_CMDSTATUS1, 0x21);
300 00293
301 00294 <span class="comment">// Wait for drive to be ready</span>
302 00295 temp = ataStatusWait(ATA_SR_BSY, ATA_SR_BSY);
303 00296
304 00297 <span class="keywordflow">if</span> (temp &amp; ATA_SR_ERR)
305 00298 {
306 00299 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"RD ERR\r\n"</span>);
307 00300 <span class="keywordflow">return</span> 1;
308 00301 }
309 00302
310 00303 <span class="comment">// Wait for drive to request data transfer</span>
311 00304 ataStatusWait(ATA_SR_DRQ, 0);
312 00305
313 00306 <span class="comment">// read data from drive</span>
314 00307 ataReadDataBuffer(Buffer, 512*numsectors);
315 00308
316 00309 <span class="comment">// Return the error bit from the status register...</span>
317 00310 temp = ataReadByte(ATA_REG_CMDSTATUS1); <span class="comment">// read status register</span>
318 00311
319 00312 <span class="keywordflow">return</span> (temp &amp; ATA_SR_ERR) ? 1:0;
320 00313 }
321 00314
322 00315
323 00316 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ataWriteSectorsCHS(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> Drive,
324 00317 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> Head,
325 00318 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Track,
326 00319 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> Sector,
327 00320 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> numsectors,
328 00321 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *Buffer)
329 00322 {
330 00323 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> temp;
331 00324
332 00325 <span class="comment">// Wait for drive to be ready</span>
333 00326 temp = ataStatusWait(ATA_SR_BSY, ATA_SR_BSY);
334 00327
335 00328 <span class="comment">// Prepare parameters...</span>
336 00329 ataWriteByte(ATA_REG_HDDEVSEL, 0xA0+(Drive ? 0x10:00)+Head); <span class="comment">// CHS mode/Drive/Head</span>
337 00330 ataWriteByte(ATA_REG_CYLHI, Track&gt;&gt;8); <span class="comment">// MSB of track</span>
338 00331 ataWriteByte(ATA_REG_CYLLO, Track); <span class="comment">// LSB of track</span>
339 00332 ataWriteByte(ATA_REG_STARTSEC, Sector); <span class="comment">// sector</span>
340 00333 ataWriteByte(ATA_REG_SECCOUNT, numsectors); <span class="comment">// # of sectors</span>
341 00334
342 00335 <span class="comment">// Issue write sector command</span>
343 00336 ataWriteByte(ATA_REG_CMDSTATUS1, 0x31);
344 00337
345 00338 <span class="comment">//delay(100);</span>
346 00339
347 00340 <span class="comment">// Wait for drive to request data transfer</span>
348 00341 ataStatusWait(ATA_SR_DRQ, 0);
349 00342
350 00343 <span class="comment">// write data to drive</span>
351 00344 ataWriteDataBuffer(Buffer, 512*numsectors);
352 00345
353 00346 <span class="comment">// Wait for drive to finish write</span>
354 00347 temp = ataStatusWait(ATA_SR_BSY, ATA_SR_BSY);
355 00348
356 00349 <span class="comment">// check for errors</span>
357 00350 <span class="keywordflow">if</span> (temp &amp; ATA_SR_ERR)
358 00351 {
359 00352 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"WR ERR\r\n"</span>);
360 00353 <span class="keywordflow">return</span> 1;
361 00354 }
362 00355
363 00356 <span class="comment">// Return the error bit from the status register...</span>
364 00357 <span class="keywordflow">return</span> (temp &amp; ATA_SR_ERR) ? 1:0;
365 00358 }
366 00359
367 00360 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ataReadSectorsLBA( <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> Drive,
368 00361 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> lba,
369 00362 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> numsectors,
370 00363 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *Buffer)
371 00364 {
372 00365 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> cyl, head, sect;
373 00366 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> temp;
374 00367
375 00368 <span class="preprocessor">#ifdef DEBUG_ATA</span>
376 00369 <span class="preprocessor"></span> <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"ATA LBA read "</span>);
377 00370 <a class="code" href="group__rprintf.html#ga9">rprintfu32</a>(lba); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" "</span>);
378 00371 <a class="code" href="group__rprintf.html#ga8">rprintfu16</a>(numsectors); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" "</span>);
379 00372 <a class="code" href="group__rprintf.html#ga8">rprintfu16</a>((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)Buffer);
380 00373 <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>();
381 00374 <span class="preprocessor">#endif</span>
382 00375 <span class="preprocessor"></span>
383 00376 sect = (int) ( lba &amp; 0x000000ffL );
384 00377 lba = lba &gt;&gt; 8;
385 00378 cyl = (int) ( lba &amp; 0x0000ffff );
386 00379 lba = lba &gt;&gt; 16;
387 00380 head = ( (int) ( lba &amp; 0x0fL ) ) | ATA_HEAD_USE_LBA;
388 00381
389 00382 temp = ataReadSectorsCHS( Drive, head, cyl, sect, numsectors, Buffer );
390 00383
391 00384 <span class="keywordflow">if</span>(temp)
392 00385 ataDiskErr();
393 00386 <span class="keywordflow">return</span> temp;
394 00387 }
395 00388
396 00389 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ataWriteSectorsLBA( <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> Drive,
397 00390 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> lba,
398 00391 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> numsectors,
399 00392 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *Buffer)
400 00393 {
401 00394 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> cyl, head, sect;
402 00395 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> temp;
403 00396
404 00397 <span class="preprocessor">#ifdef DEBUG_ATA</span>
405 00398 <span class="preprocessor"></span> <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"ATA LBA write "</span>);
406 00399 <a class="code" href="group__rprintf.html#ga9">rprintfu32</a>(lba); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" "</span>);
407 00400 <a class="code" href="group__rprintf.html#ga8">rprintfu16</a>(numsectors); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" "</span>);
408 00401 <a class="code" href="group__rprintf.html#ga8">rprintfu16</a>((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)Buffer);
409 00402 <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>();
410 00403 <span class="preprocessor">#endif</span>
411 00404 <span class="preprocessor"></span>
412 00405 sect = (int) ( lba &amp; 0x000000ffL );
413 00406 lba = lba &gt;&gt; 8;
414 00407 cyl = (int) ( lba &amp; 0x0000ffff );
415 00408 lba = lba &gt;&gt; 16;
416 00409 head = ( (int) ( lba &amp; 0x0fL ) ) | ATA_HEAD_USE_LBA;
417 00410
418 00411 temp = ataWriteSectorsCHS( Drive, head, cyl, sect, numsectors, Buffer );
419 00412
420 00413 <span class="keywordflow">if</span>(temp)
421 00414 ataDiskErr();
422 00415 <span class="keywordflow">return</span> temp;
423 00416 }
424 00417
425 00418
426 00419 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ataReadSectors( <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> Drive,
427 00420 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> lba,
428 00421 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> numsectors,
429 00422 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *Buffer)
430 00423 {
431 00424 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> cyl, head, sect;
432 00425 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> temp;
433 00426
434 00427 <span class="comment">// check if drive supports native LBA mode</span>
435 00428 <span class="keywordflow">if</span>(ataDriveInfo.LBAsupport)
436 00429 {
437 00430 <span class="comment">// drive supports using native LBA</span>
438 00431 temp = ataReadSectorsLBA(Drive, lba, numsectors, Buffer);
439 00432 }
440 00433 <span class="keywordflow">else</span>
441 00434 {
442 00435 <span class="comment">// drive required CHS access</span>
443 00436 <span class="preprocessor"> #ifdef DEBUG_ATA</span>
444 00437 <span class="preprocessor"></span> <span class="comment">// do this defore destroying lba</span>
445 00438 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"ATA LBA for CHS read: "</span>);
446 00439 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"LBA="</span>); <a class="code" href="group__rprintf.html#ga9">rprintfu32</a>(lba); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" "</span>);
447 00440 <span class="preprocessor"> #endif</span>
448 00441 <span class="preprocessor"></span>
449 00442 <span class="comment">// convert LBA to pseudo CHS</span>
450 00443 <span class="comment">// remember to offset the sector count by one</span>
451 00444 sect = (u08) (lba % ataDriveInfo.sectors)+1;
452 00445 lba = lba / ataDriveInfo.sectors;
453 00446 head = (u08) (lba % ataDriveInfo.heads);
454 00447 lba = lba / ataDriveInfo.heads;
455 00448 cyl = (u16) lba;
456 00449
457 00450 <span class="preprocessor"> #ifdef DEBUG_ATA</span>
458 00451 <span class="preprocessor"></span> <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"C:H:S="</span>);
459 00452 <a class="code" href="group__rprintf.html#ga8">rprintfu16</a>(cyl); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">":"</span>);
460 00453 <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(head); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">":"</span>);
461 00454 <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(sect); <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>();
462 00455 <span class="preprocessor"> #endif</span>
463 00456 <span class="preprocessor"></span>
464 00457 temp = ataReadSectorsCHS( Drive, head, cyl, sect, numsectors, Buffer );
465 00458 }
466 00459
467 00460 <span class="keywordflow">if</span>(temp)
468 00461 ataDiskErr();
469 00462 <span class="keywordflow">return</span> temp;
470 00463 }
471 00464
472 00465
473 00466 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ataWriteSectors(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> Drive,
474 00467 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> lba,
475 00468 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> numsectors,
476 00469 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *Buffer)
477 00470 {
478 00471 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> cyl, head, sect;
479 00472 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> temp;
480 00473
481 00474 <span class="comment">// check if drive supports native LBA mode</span>
482 00475 <span class="keywordflow">if</span>(ataDriveInfo.LBAsupport)
483 00476 {
484 00477 <span class="comment">// drive supports using native LBA</span>
485 00478 temp = ataWriteSectorsLBA(Drive, lba, numsectors, Buffer);
486 00479 }
487 00480 <span class="keywordflow">else</span>
488 00481 {
489 00482 <span class="comment">// drive required CHS access</span>
490 00483 <span class="preprocessor"> #ifdef DEBUG_ATA</span>
491 00484 <span class="preprocessor"></span> <span class="comment">// do this defore destroying lba</span>
492 00485 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"ATA LBA for CHS write: "</span>);
493 00486 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"LBA="</span>); <a class="code" href="group__rprintf.html#ga9">rprintfu32</a>(lba); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" "</span>);
494 00487 <span class="preprocessor"> #endif</span>
495 00488 <span class="preprocessor"></span>
496 00489 <span class="comment">// convert LBA to pseudo CHS</span>
497 00490 <span class="comment">// remember to offset the sector count by one</span>
498 00491 sect = (u08) (lba % ataDriveInfo.sectors)+1;
499 00492 lba = lba / ataDriveInfo.sectors;
500 00493 head = (u08) (lba % ataDriveInfo.heads);
501 00494 lba = lba / ataDriveInfo.heads;
502 00495 cyl = (u16) lba;
503 00496
504 00497 <span class="preprocessor"> #ifdef DEBUG_ATA</span>
505 00498 <span class="preprocessor"></span> <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"C:H:S="</span>);
506 00499 <a class="code" href="group__rprintf.html#ga8">rprintfu16</a>(cyl); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">":"</span>);
507 00500 <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(head); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">":"</span>);
508 00501 <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(sect); <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>();
509 00502 <span class="preprocessor"> #endif</span>
510 00503 <span class="preprocessor"></span>
511 00504 temp = ataWriteSectorsCHS( Drive, head, cyl, sect, numsectors, Buffer );
512 00505 }
513 00506
514 00507 <span class="keywordflow">if</span>(temp)
515 00508 ataDiskErr();
516 00509 <span class="keywordflow">return</span> temp;
517 00510 }
518 00511
519 00512 <span class="keywordtype">void</span> ataDriveSelect(u08 DriveNo)
520 00513 {
521 00514 ataWriteByte(ATA_REG_HDDEVSEL, 0xA0+(DriveNo ? 0x10:00)); <span class="comment">// Drive selection</span>
522 00515 }
523 00516
524 00517 <span class="comment">//----------------------------------------------------------------------------</span>
525 00518 <span class="comment">// Set drive mode (STANDBY, IDLE)</span>
526 00519 <span class="comment">//----------------------------------------------------------------------------</span>
527 00520 <span class="comment">/*#define STANDBY 0</span>
528 00521 <span class="comment">#define IDLE 1</span>
529 00522 <span class="comment">#define SLEEP 2 </span>
530 00523 <span class="comment">*/</span>
531 00524
532 00525 <span class="comment">/*</span>
533 00526 <span class="comment">unsigned char SetMode(unsigned char DriveNo, unsigned char Mode, unsigned char PwrDown) </span>
534 00527 <span class="comment">{</span>
535 00528 <span class="comment"> WriteBYTE(CMD, 6, 0xA0 + (DriveNo ? 0x10:0x00)); // Select drive</span>
536 00529 <span class="comment"> WriteBYTE(CMD, 2, (PwrDown ? 0x01:0x00)); // Enable automatic power down</span>
537 00530 <span class="comment"> switch (Mode) </span>
538 00531 <span class="comment"> {</span>
539 00532 <span class="comment"> case STANDBY: WriteBYTE(CMD,7, 0xE2); break;</span>
540 00533 <span class="comment"> case IDLE: WriteBYTE(CMD,7, 0xE3); break;</span>
541 00534 <span class="comment"> // NOTE: To recover from sleep, either issue a soft or hardware reset !</span>
542 00535 <span class="comment"> // (But not on all drives, f.ex seagate ST3655A it's not nessecary to reset</span>
543 00536 <span class="comment"> // but only to go in Idle mode, But on a Conner CFA170A it's nessecary with</span>
544 00537 <span class="comment"> // a reset)</span>
545 00538 <span class="comment"> case SLEEP: WriteBYTE(CMD,7, 0xE6); break;</span>
546 00539 <span class="comment"> }</span>
547 00540 <span class="comment"> Timer10mSec=10000;</span>
548 00541 <span class="comment"> while ((ReadBYTE(CMD,7) &amp; 0xC0)!=0x40 &amp;&amp; Timer10mSec); // Wait for DRDY &amp; NOT BUSY </span>
549 00542 <span class="comment"> if (Timer10mSec==0) return 0xFF; // or timeout</span>
550 00543 <span class="comment"> </span>
551 00544 <span class="comment"> // Return the error register...</span>
552 00545 <span class="comment"> return ReadBYTE(CMD, 1);</span>
553 00546 <span class="comment">}</span>
554 00547 <span class="comment"></span>
555 00548 <span class="comment">*/</span>
556 00549
557 00550 u08 ataReadByte(u08 reg)
558 00551 {
559 00552 <span class="keyword">register</span> u08 ret;
560 00553 <span class="comment">//sbi(MCUCR, SRW); // enable RAM waitstate</span>
561 00554 ret = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + reg);
562 00555 <span class="comment">//cbi(MCUCR, SRW); // disable RAM waitstate</span>
563 00556 <span class="keywordflow">return</span> ret;
564 00557 }
565 00558
566 00559 <span class="keywordtype">void</span> ataWriteByte(u08 reg, u08 data)
567 00560 {
568 00561 <span class="comment">//sbi(MCUCR, SRW); // enable RAM waitstate</span>
569 00562 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) ATA_REG_BASE + reg) = data;
570 00563 <span class="comment">//cbi(MCUCR, SRW); // disable RAM waitstate</span>
571 00564 }
572 00565
573 00566
574 00567 <span class="keywordtype">void</span> ataShowRegisters(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> DriveNo)
575 00568 {
576 00569 ataWriteByte(ATA_REG_HDDEVSEL, 0xA0 + (DriveNo ? 0x10:0x00)); <span class="comment">// Select drive</span>
577 00570
578 00571 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"R0: DATALOW = 0x"</span>); <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(ataReadByte(ATA_REG_DATAL )); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" \r\n"</span>);
579 00572 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"R1: ERROR = 0x"</span>); <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(ataReadByte(ATA_REG_ERROR )); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" \r\n"</span>);
580 00573 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"R2: SECT CNT = 0x"</span>); <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(ataReadByte(ATA_REG_SECCOUNT)); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" \r\n"</span>);
581 00574 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"R3: SECT NUM = 0x"</span>); <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(ataReadByte(ATA_REG_STARTSEC)); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" \r\n"</span>);
582 00575 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"R4: CYL LOW = 0x"</span>); <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(ataReadByte(ATA_REG_CYLLO )); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" \r\n"</span>);
583 00576 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"R5: CYL HIGH = 0x"</span>); <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(ataReadByte(ATA_REG_CYLHI )); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" \r\n"</span>);
584 00577 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"R6: HEAD/DEV = 0x"</span>); <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(ataReadByte(ATA_REG_HDDEVSEL)); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">" \r\n"</span>);
585 00578 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"R7: CMD/STA = 0x"</span>); <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(ataReadByte(ATA_REG_CMDSTATUS1)); <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"\r\n"</span>);
586 00579 }
587 00580
588 00581 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ataSWReset(<span class="keywordtype">void</span>)
589 00582 {
590 00583 ataWriteByte(ATA_REG_HDDEVSEL, 0x06); <span class="comment">// SRST and nIEN bits</span>
591 00584 delay(10); <span class="comment">// 10uS delay</span>
592 00585 ataWriteByte(ATA_REG_HDDEVSEL, 0x02); <span class="comment">// nIEN bits</span>
593 00586 delay(10); <span class="comment">// 10 uS delay</span>
594 00587
595 00588 <span class="keywordflow">while</span>( (ataReadByte(ATA_REG_CMDSTATUS1) &amp; 0xC0) != 0x40 ); <span class="comment">// Wait for DRDY and not BSY</span>
596 00589
597 00590 <span class="keywordflow">return</span> ataReadByte(ATA_REG_CMDSTATUS1) + ataReadByte(ATA_REG_ERROR);
598 00591 }
599 00592
600 00593 <span class="comment">/*</span>
601 00594 <span class="comment">unsigned char ATA_Idle(unsigned char Drive)</span>
602 00595 <span class="comment">{</span>
603 00596 <span class="comment"></span>
604 00597 <span class="comment"> WriteBYTE(CMD, 6, 0xA0 + (Drive ? 0x10:0x00)); // Select drive</span>
605 00598 <span class="comment"> WriteBYTE(CMD,7, 0xE1);</span>
606 00599 <span class="comment"></span>
607 00600 <span class="comment"> while ((ReadBYTE(CMD,7) &amp; 0xC0)!=0x40); // Wait for DRDY &amp; NOT BUSY </span>
608 00601 <span class="comment"></span>
609 00602 <span class="comment"> // Return the error register...</span>
610 00603 <span class="comment"> return ReadBYTE(CMD, 1);</span>
611 00604 <span class="comment">}</span>
612 00605 <span class="comment">*/</span>
613 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:06 2006 for Procyon AVRlib by&nbsp;
614 <a href="http://www.doxygen.org/index.html">
615 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
616 </body>
617 </html>
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3