Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

ata.h

Go to the documentation of this file.
00001 /*! \file ata.h \brief IDE-ATA hard disk interface driver. */
00002 //*****************************************************************************
00003 //
00004 // File Name    : 'ata.h'
00005 // Title        : IDE-ATA interface driver for hard disks
00006 // Author       : Pascal Stang
00007 // Date         : 11/22/2000
00008 // Revised      : 4/2/2004
00009 // Version      : 0.1
00010 // Target MCU   : any
00011 // Editor Tabs  : 4
00012 //
00013 // NOTE: This code is currently below version 1.0, and therefore is considered
00014 // to be lacking in some functionality or documentation, or may not be fully
00015 // tested.  Nonetheless, you can expect most functions to work.
00016 //
00017 // This code is distributed under the GNU Public License
00018 //      which can be found at http://www.gnu.org/licenses/gpl.txt
00019 //
00020 //*****************************************************************************
00021 
00022 
00023 #ifndef ATA_H
00024 #define ATA_H
00025 
00026 #include "global.h"
00027 #include "atadev.h"
00028 #include "ataconf.h"
00029 
00030 // constants
00031 #define DRIVE0      0
00032 
00033 #define STANDBY     0
00034 #define SLEEP       1
00035 #define IDLE        2
00036 
00037 // ATA status register bits
00038 #define ATA_SR_BSY      0x80
00039 #define ATA_SR_DRDY     0x40
00040 #define ATA_SR_DF       0x20
00041 #define ATA_SR_DSC      0x10
00042 #define ATA_SR_DRQ      0x08
00043 #define ATA_SR_CORR     0x04
00044 #define ATA_SR_IDX      0x02
00045 #define ATA_SR_ERR      0x01
00046 
00047 // ATA error register bits
00048 #define ATA_ER_UNC      0x40
00049 #define ATA_ER_MC       0x20
00050 #define ATA_ER_IDNF     0x10
00051 #define ATA_ER_MCR      0x08
00052 #define ATA_ER_ABRT     0x04
00053 #define ATA_ER_TK0NF    0x02
00054 #define ATA_ER_AMNF     0x01
00055 
00056 // ATA head register bits
00057 #define ATA_HEAD_USE_LBA    0x40
00058 
00059 // ATA commands
00060 #define ATA_CMD_READ            0x20
00061 #define ATA_CMD_READNR          0x21
00062 #define ATA_CMD_WRITE           0x30
00063 #define ATA_CMD_WRITENR         0x31
00064 #define ATA_CMD_IDENTIFY        0xEC
00065 #define ATA_CMD_RECALIBRATE     0x10
00066 #define ATA_CMD_SPINDOWN        0xE0    // spin down disk immediately
00067 #define ATA_CMD_SPINUP          0xE1    // spin up disk immediately
00068 #define ATA_CMD_STANDBY_5SU     0xE2    // spin down disk and set auto-power-down timer (sectorcount*5sec)
00069 #define ATA_CMD_IDLE_5SU        0xE3    // keep disk spinning and set auto-power-down timer (sectorcount*5sec)
00070 #define ATA_CMD_SLEEP           0xE6    // sleep disk (wakeup only on HW or SW reset)
00071 #define ATA_CMD_STANDBY_01SU    0xF2    // spin down disk and set auto-power-down timer (sectorcount*0.1sec)
00072 #define ATA_CMD_IDLE_01SU       0xF3    // keep disk spinning and set auto-power-down timer (sectorcount*0.1sec)
00073 
00074 
00075 // ATA CHS disk parameters (examples, now we autodetect)
00076 #define ATA_DISKPARM_CLYS       0x03A6  // number of cylinders per platter
00077 #define ATA_DISKPARM_HEADS      0x10    // number of heads (usable plater sides)
00078 #define ATA_DISKPARM_SECTORS    0x11    // number of sectors per head per cylinder
00079 
00080 // ATA Identity fields
00081 // all offsets refer to word offset (2 byte increments)
00082 #define ATA_IDENT_DEVICETYPE    0       // specifies ATA/ATAPI, removable/non-removable
00083 #define ATA_IDENT_CYLINDERS     1       // number of logical cylinders
00084 #define ATA_IDENT_HEADS         3       // number of logical heads
00085 #define ATA_IDENT_SECTORS       6       // number of sectors per track
00086 #define ATA_IDENT_SERIAL        10      // drive serial number (20 characters)
00087 #define ATA_IDENT_FIRMWAREREV   23      // drive firmware revision (8 characters)
00088 #define ATA_IDENT_MODEL         27      // drive model name (40 characters)
00089 #define ATA_IDENT_FIELDVALID    53      // indicates field validity of higher words (bit0: words54-58, bit1: words 64-70)
00090 #define ATA_IDENT_LBASECTORS    60      // number of sectors in LBA translation mode
00091 
00092 // drive mode defines (for ataSetDrivePowerMode() )
00093 #define ATA_DISKMODE_SPINDOWN   0
00094 #define ATA_DISKMODE_SPINUP     1
00095 #define ATA_DISKMODE_SETTIMEOUT 2
00096 #define ATA_DISKMODE_SLEEP      3
00097 
00098 // typedefs
00099 // drive info structure
00100 struct DiskInfo
00101 {
00102     DevBlock_t ataif;
00103     unsigned long sizeinsectors;
00104     unsigned short cylinders;
00105     unsigned char heads;
00106     unsigned char sectors;
00107     unsigned char LBAsupport;
00108     unsigned char driveno;
00109     char model[41];
00110 } GNUC_PACKED;
00111 
00112 typedef struct DiskInfo DiskInfo_t;
00113 
00114 // Prototypes
00115 void ataInit(DiskInfo_t* disk, DevBlock_t ataif, unsigned char driveno);
00116 void ataDriveInit(DiskInfo_t* disk);
00117 
00118 void ataDriveSelect(DiskInfo_t* disk);
00119 void ataSetDrivePowerMode(DiskInfo_t* disk, u08 mode, u08 timeout);
00120 
00121 void ataShowRegisters(DiskInfo_t* disk);
00122 u08  ataSWReset(DiskInfo_t* disk);
00123 void ataDiskErr(DiskInfo_t* disk);
00124 u08 ataStatusWait(DiskInfo_t* disk, u08 mask, u08 waitStatus);
00125 
00126 // read and write routines for CHS based drives
00127 unsigned char ataReadSectorsCHS(    DiskInfo_t* disk,
00128                                     unsigned char Head, 
00129                                     unsigned int Track,
00130                                     unsigned char Sector,
00131                                     unsigned int numsectors,
00132                                     unsigned char *Buffer);
00133 
00134 unsigned char ataWriteSectorsCHS(   DiskInfo_t* disk,
00135                                     unsigned char Head, 
00136                                     unsigned int Track,
00137                                     unsigned char Sector,
00138                                     unsigned int numsectors,
00139                                     unsigned char *Buffer);
00140 
00141 // read and write routines for LBA based drives
00142 unsigned char ataReadSectorsLBA(    DiskInfo_t* disk,
00143                                     unsigned long lba,
00144                                     unsigned int numsectors,
00145                                     unsigned char *Buffer);
00146 
00147 unsigned char ataWriteSectorsLBA(   DiskInfo_t* disk,
00148                                     unsigned long lba,
00149                                     unsigned int numsectors,
00150                                     unsigned char *Buffer);
00151 
00152 // generic read and write routines using LBA
00153 //   uses native or translated LBA addressing
00154 //   given autodetected drive type
00155 unsigned char ataReadSectors(   DiskInfo_t* disk, 
00156                                 unsigned long lba,
00157                                 unsigned int numsectors,
00158                                 unsigned char *Buffer);
00159 
00160 unsigned char ataWriteSectors(  DiskInfo_t* disk, 
00161                                 unsigned long lba,
00162                                 unsigned int numsectors,
00163                                 unsigned char *Buffer);
00164 
00165 #endif

Generated on Mon Nov 6 23:36:58 2006 for Procyon ARMlib by  doxygen 1.4.2