Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | /*! \file ata.h \brief IDE-ATA hard disk interface driver. */ |
2 | //***************************************************************************** |
||
3 | // |
||
4 | // File Name : 'ata.h' |
||
5 | // Title : IDE-ATA interface driver for hard disks |
||
6 | // Author : Pascal Stang |
||
7 | // Date : 11/22/2000 |
||
8 | // Revised : 12/29/2000 |
||
9 | // Version : 0.3 |
||
10 | // Target MCU : ATmega103 (should work for Atmel AVR Series) |
||
11 | // Editor Tabs : 4 |
||
12 | // |
||
13 | /// \ingroup driver_hw |
||
14 | /// \defgroup ata IDE/ATA Interface Driver (ata.c) |
||
15 | /// \code #include "ata.h" \endcode |
||
16 | /// \par Overview |
||
17 | /// This library provides an interface from AVR processors to IDE/ATA |
||
18 | /// devices. Such devices can include hard disks, CF memory cards, and |
||
19 | /// PCMCIA disks and memory devices. The library supports automatic drive |
||
20 | /// identification and sector-level reading and writing. Some minimal |
||
21 | /// address decoding hardware is required to use this interface. For an |
||
22 | /// example of interface hardware, see the Procyon MP3 Player docs here: |
||
23 | /// http://hubbard.engr.scu.edu/embedded/procyonmp3/index.html. |
||
24 | /// Future revisions if this library may include a direct hardware-less |
||
25 | /// interface option. |
||
26 | /// |
||
27 | /// \note This code is quite old and in some level of disrepair. Nonetheless, |
||
28 | /// it works quite well. |
||
29 | // |
||
30 | // This code is distributed under the GNU Public License |
||
31 | // which can be found at http://www.gnu.org/licenses/gpl.txt |
||
32 | // |
||
33 | //***************************************************************************** |
||
34 | //@{ |
||
35 | |||
36 | #ifndef ATA_H |
||
37 | #define ATA_H |
||
38 | |||
39 | #include "global.h" |
||
40 | #include "ataconf.h" |
||
41 | |||
42 | // constants |
||
43 | #define DRIVE0 0 |
||
44 | |||
45 | #define STANDBY 0 |
||
46 | #define SLEEP 1 |
||
47 | #define IDLE 2 |
||
48 | |||
49 | // ATA status register bits |
||
50 | #define ATA_SR_BSY 0x80 |
||
51 | #define ATA_SR_DRDY 0x40 |
||
52 | #define ATA_SR_DF 0x20 |
||
53 | #define ATA_SR_DSC 0x10 |
||
54 | #define ATA_SR_DRQ 0x08 |
||
55 | #define ATA_SR_CORR 0x04 |
||
56 | #define ATA_SR_IDX 0x02 |
||
57 | #define ATA_SR_ERR 0x01 |
||
58 | |||
59 | // ATA error register bits |
||
60 | #define ATA_ER_UNC 0x40 |
||
61 | #define ATA_ER_MC 0x20 |
||
62 | #define ATA_ER_IDNF 0x10 |
||
63 | #define ATA_ER_MCR 0x08 |
||
64 | #define ATA_ER_ABRT 0x04 |
||
65 | #define ATA_ER_TK0NF 0x02 |
||
66 | #define ATA_ER_AMNF 0x01 |
||
67 | |||
68 | // ATA head register bits |
||
69 | #define ATA_HEAD_USE_LBA 0x40 |
||
70 | /* |
||
71 | // ATA registers |
||
72 | #define ATA_REG_BASE 0x8000 |
||
73 | #define ATA_REG_DATAL 0x00 |
||
74 | #define ATA_REG_ERROR 0x01 |
||
75 | #define ATA_REG_SECCOUNT 0x02 |
||
76 | #define ATA_REG_STARTSEC 0x03 |
||
77 | #define ATA_REG_CYLLO 0x04 |
||
78 | #define ATA_REG_CYLHI 0x05 |
||
79 | #define ATA_REG_HDDEVSEL 0x06 |
||
80 | #define ATA_REG_CMDSTATUS1 0x07 |
||
81 | #define ATA_REG_CMDSTATUS2 0x08 |
||
82 | #define ATA_REG_ACTSTATUS 0x09 |
||
83 | |||
84 | #define ATA_REG_DATAH 0x10 |
||
85 | */ |
||
86 | // ATA commands |
||
87 | #define ATA_CMD_READ 0x20 |
||
88 | #define ATA_CMD_READNR 0x21 |
||
89 | #define ATA_CMD_WRITE 0x30 |
||
90 | #define ATA_CMD_WRITENR 0x31 |
||
91 | #define ATA_CMD_IDENTIFY 0xEC |
||
92 | #define ATA_CMD_RECALIBRATE 0x10 |
||
93 | #define ATA_CMD_SPINDOWN 0xE0 // spin down disk immediately |
||
94 | #define ATA_CMD_SPINUP 0xE1 // spin up disk immediately |
||
95 | #define ATA_CMD_STANDBY_5SU 0xE2 // spin down disk and set auto-power-down timer (sectorcount*5sec) |
||
96 | #define ATA_CMD_IDLE_5SU 0xE3 // keep disk spinning and set auto-power-down timer (sectorcount*5sec) |
||
97 | #define ATA_CMD_SLEEP 0xE6 // sleep disk (wakeup only on HW or SW reset) |
||
98 | #define ATA_CMD_STANDBY_01SU 0xF2 // spin down disk and set auto-power-down timer (sectorcount*0.1sec) |
||
99 | #define ATA_CMD_IDLE_01SU 0xF3 // keep disk spinning and set auto-power-down timer (sectorcount*0.1sec) |
||
100 | |||
101 | |||
102 | // ATA CHS disk parameters (examples, now we autodetect) |
||
103 | #define ATA_DISKPARM_CLYS 0x03A6 // number of cylinders per platter |
||
104 | #define ATA_DISKPARM_HEADS 0x10 // number of heads (usable plater sides) |
||
105 | #define ATA_DISKPARM_SECTORS 0x11 // number of sectors per head per cylinder |
||
106 | |||
107 | // ATA Identity fields |
||
108 | // all offsets refer to word offset (2 byte increments) |
||
109 | #define ATA_IDENT_DEVICETYPE 0 // specifies ATA/ATAPI, removable/non-removable |
||
110 | #define ATA_IDENT_CYLINDERS 1 // number of logical cylinders |
||
111 | #define ATA_IDENT_HEADS 3 // number of logical heads |
||
112 | #define ATA_IDENT_SECTORS 6 // number of sectors per track |
||
113 | #define ATA_IDENT_SERIAL 10 // drive model name (20 characters) |
||
114 | #define ATA_IDENT_MODEL 27 // drive model name (40 characters) |
||
115 | #define ATA_IDENT_FIELDVALID 53 // indicates field validity of higher words (bit0: words54-58, bit1: words 64-70) |
||
116 | #define ATA_IDENT_LBASECTORS 60 // number of sectors in LBA translation mode |
||
117 | |||
118 | // drive mode defines (for ataSetDrivePowerMode() ) |
||
119 | #define ATA_DISKMODE_SPINDOWN 0 |
||
120 | #define ATA_DISKMODE_SPINUP 1 |
||
121 | #define ATA_DISKMODE_SETTIMEOUT 2 |
||
122 | #define ATA_DISKMODE_SLEEP 3 |
||
123 | |||
124 | // typedefs |
||
125 | // drive info structure |
||
126 | typedef struct |
||
127 | { |
||
128 | unsigned int cylinders; |
||
129 | unsigned char heads; |
||
130 | unsigned char sectors; |
||
131 | unsigned long sizeinsectors; |
||
132 | unsigned char LBAsupport; |
||
133 | char model[41]; |
||
134 | } typeDriveInfo; |
||
135 | |||
136 | |||
137 | // Prototypes |
||
138 | void ataInit(void); |
||
139 | void ataDriveInit(void); |
||
140 | void ataDriveSelect(u08 DriveNo); |
||
141 | void ataSetDrivePowerMode(u08 DriveNo, u08 mode, u08 timeout); |
||
142 | u08 ataReadByte(u08 reg); |
||
143 | void ataWriteByte(u08 reg, u08 data); |
||
144 | void ataShowRegisters(unsigned char DriveNo); |
||
145 | u08 ataSWReset(void); |
||
146 | void ataDiskErr(void); |
||
147 | void ataPrintSector( u08 *Buffer); |
||
148 | void ataReadDataBuffer(u08 *Buffer, u16 numBytes); |
||
149 | void ataWriteDataBuffer(u08 *Buffer, u16 numBytes); |
||
150 | u08 ataStatusWait(u08 mask, u08 waitStatus); |
||
151 | |||
152 | // read and write routines for CHS based drives |
||
153 | unsigned char ataReadSectorsCHS( unsigned char Drive, |
||
154 | unsigned char Head, |
||
155 | unsigned int Track, |
||
156 | unsigned char Sector, |
||
157 | unsigned int numsectors, |
||
158 | unsigned char *Buffer); |
||
159 | |||
160 | unsigned char ataWriteSectorsCHS( unsigned char Drive, |
||
161 | unsigned char Head, |
||
162 | unsigned int Track, |
||
163 | unsigned char Sector, |
||
164 | unsigned int numsectors, |
||
165 | unsigned char *Buffer); |
||
166 | |||
167 | // read and write routines for LBA based drives |
||
168 | unsigned char ataReadSectorsLBA( unsigned char Drive, |
||
169 | unsigned long lba, |
||
170 | unsigned int numsectors, |
||
171 | unsigned char *Buffer); |
||
172 | |||
173 | unsigned char ataWriteSectorsLBA( unsigned char Drive, |
||
174 | unsigned long lba, |
||
175 | unsigned int numsectors, |
||
176 | unsigned char *Buffer); |
||
177 | |||
178 | // generic read and write routines using LBA |
||
179 | // uses native or translated LBA addressing |
||
180 | // given autodetected drive type |
||
181 | unsigned char ataReadSectors( unsigned char Drive, |
||
182 | unsigned long lba, |
||
183 | unsigned int numsectors, |
||
184 | unsigned char *Buffer); |
||
185 | |||
186 | unsigned char ataWriteSectors( unsigned char Drive, |
||
187 | unsigned long lba, |
||
188 | unsigned int numsectors, |
||
189 | unsigned char *Buffer); |
||
190 | |||
191 | //unsigned char IdentifyDrive(unsigned char DriveNo, unsigned char *Buffer, tdefDriveInfo *DriveInfo); |
||
192 | //unsigned char SetMode(unsigned char DriveNo, unsigned char Mode, unsigned char PwrDown); |
||
193 | //unsigned char ATA_Idle(unsigned char Drive); |
||
194 | |||
195 | #endif |
||
196 | //@} |
Powered by WebSVN v2.8.3