Main Page   Modules   Data Structures   File List   Data Fields   Globals  

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      : 12/29/2000
00009 // Version      : 0.3
00010 // Target MCU   : ATmega103 (should work for Atmel AVR Series)
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 "ataconf.h"
00028 
00029 // constants
00030 #define DRIVE0      0
00031 
00032 #define STANDBY     0
00033 #define SLEEP       1
00034 #define IDLE        2
00035 
00036 // ATA status register bits
00037 #define ATA_SR_BSY      0x80
00038 #define ATA_SR_DRDY     0x40
00039 #define ATA_SR_DF       0x20
00040 #define ATA_SR_DSC      0x10
00041 #define ATA_SR_DRQ      0x08
00042 #define ATA_SR_CORR     0x04
00043 #define ATA_SR_IDX      0x02
00044 #define ATA_SR_ERR      0x01
00045 
00046 // ATA error register bits
00047 #define ATA_ER_UNC      0x40
00048 #define ATA_ER_MC       0x20
00049 #define ATA_ER_IDNF     0x10
00050 #define ATA_ER_MCR      0x08
00051 #define ATA_ER_ABRT     0x04
00052 #define ATA_ER_TK0NF    0x02
00053 #define ATA_ER_AMNF     0x01
00054 
00055 // ATA head register bits
00056 #define ATA_HEAD_USE_LBA    0x40
00057 /*
00058 // ATA registers
00059 #define ATA_REG_BASE        0x8000
00060 #define ATA_REG_DATAL       0x00
00061 #define ATA_REG_ERROR       0x01
00062 #define ATA_REG_SECCOUNT    0x02
00063 #define ATA_REG_STARTSEC    0x03
00064 #define ATA_REG_CYLLO       0x04
00065 #define ATA_REG_CYLHI       0x05
00066 #define ATA_REG_HDDEVSEL    0x06
00067 #define ATA_REG_CMDSTATUS1  0x07
00068 #define ATA_REG_CMDSTATUS2  0x08
00069 #define ATA_REG_ACTSTATUS   0x09
00070 
00071 #define ATA_REG_DATAH       0x10
00072 */
00073 // ATA commands
00074 #define ATA_CMD_READ            0x20
00075 #define ATA_CMD_READNR          0x21
00076 #define ATA_CMD_WRITE           0x30
00077 #define ATA_CMD_WRITENR         0x31
00078 #define ATA_CMD_IDENTIFY        0xEC
00079 #define ATA_CMD_RECALIBRATE     0x10
00080 #define ATA_CMD_SPINDOWN        0xE0    // spin down disk immediately
00081 #define ATA_CMD_SPINUP          0xE1    // spin up disk immediately
00082 #define ATA_CMD_STANDBY_5SU     0xE2    // spin down disk and set auto-power-down timer (sectorcount*5sec)
00083 #define ATA_CMD_IDLE_5SU        0xE3    // keep disk spinning and set auto-power-down timer (sectorcount*5sec)
00084 #define ATA_CMD_SLEEP           0xE6    // sleep disk (wakeup only on HW or SW reset)
00085 #define ATA_CMD_STANDBY_01SU    0xF2    // spin down disk and set auto-power-down timer (sectorcount*0.1sec)
00086 #define ATA_CMD_IDLE_01SU       0xF3    // keep disk spinning and set auto-power-down timer (sectorcount*0.1sec)
00087 
00088 
00089 // ATA CHS disk parameters (examples, now we autodetect)
00090 #define ATA_DISKPARM_CLYS       0x03A6  // number of cylinders per platter
00091 #define ATA_DISKPARM_HEADS      0x10    // number of heads (usable plater sides)
00092 #define ATA_DISKPARM_SECTORS    0x11    // number of sectors per head per cylinder
00093 
00094 // ATA Identity fields
00095 // all offsets refer to word offset (2 byte increments)
00096 #define ATA_IDENT_DEVICETYPE    0       // specifies ATA/ATAPI, removable/non-removable
00097 #define ATA_IDENT_CYLINDERS     1       // number of logical cylinders
00098 #define ATA_IDENT_HEADS         3       // number of logical heads
00099 #define ATA_IDENT_SECTORS       6       // number of sectors per track
00100 #define ATA_IDENT_SERIAL        10      // drive model name (20 characters)
00101 #define ATA_IDENT_MODEL         27      // drive model name (40 characters)
00102 #define ATA_IDENT_FIELDVALID    53      // indicates field validity of higher words (bit0: words54-58, bit1: words 64-70)
00103 #define ATA_IDENT_LBASECTORS    60      // number of sectors in LBA translation mode
00104 
00105 // drive mode defines (for ataSetDrivePowerMode() )
00106 #define ATA_DISKMODE_SPINDOWN   0
00107 #define ATA_DISKMODE_SPINUP     1
00108 #define ATA_DISKMODE_SETTIMEOUT 2
00109 #define ATA_DISKMODE_SLEEP      3
00110 
00111 // typedefs
00112 // drive info structure
00113 typedef struct 
00114 {
00115     unsigned int  cylinders;
00116     unsigned char heads;
00117     unsigned char sectors;
00118     unsigned long sizeinsectors;
00119     unsigned char LBAsupport;
00120     char model[41];
00121 } typeDriveInfo;
00122 
00123 
00124 // Prototypes
00125 void ataInit(void);
00126 void ataDriveInit(void);
00127 void ataDriveSelect(u08 DriveNo);
00128 void ataSetDrivePowerMode(u08 DriveNo, u08 mode, u08 timeout);
00129 u08  ataReadByte(u08 reg);
00130 void ataWriteByte(u08 reg, u08 data);
00131 void ataShowRegisters(unsigned char DriveNo);
00132 u08  ataSWReset(void);
00133 void ataDiskErr(void);
00134 void ataPrintSector( u08 *Buffer);
00135 void ataReadDataBuffer(u08 *Buffer, u16 numBytes);
00136 void ataWriteDataBuffer(u08 *Buffer, u16 numBytes);
00137 u08 ataStatusWait(u08 mask, u08 waitStatus);
00138 
00139 // read and write routines for CHS based drives
00140 unsigned char ataReadSectorsCHS(    unsigned char Drive, 
00141                                     unsigned char Head, 
00142                                     unsigned int Track,
00143                                     unsigned char Sector,
00144                                     unsigned int numsectors,
00145                                     unsigned char *Buffer);
00146 
00147 unsigned char ataWriteSectorsCHS(   unsigned char Drive, 
00148                                     unsigned char Head, 
00149                                     unsigned int Track,
00150                                     unsigned char Sector,
00151                                     unsigned int numsectors,
00152                                     unsigned char *Buffer);
00153 
00154 // read and write routines for LBA based drives
00155 unsigned char ataReadSectorsLBA(    unsigned char Drive, 
00156                                     unsigned long lba,
00157                                     unsigned int numsectors,
00158                                     unsigned char *Buffer);
00159 
00160 unsigned char ataWriteSectorsLBA(   unsigned char Drive, 
00161                                     unsigned long lba,
00162                                     unsigned int numsectors,
00163                                     unsigned char *Buffer);
00164 
00165 // generic read and write routines using LBA
00166 //   uses native or translated LBA addressing
00167 //   given autodetected drive type
00168 unsigned char ataReadSectors(   unsigned char Drive, 
00169                                 unsigned long lba,
00170                                 unsigned int numsectors,
00171                                 unsigned char *Buffer);
00172 
00173 unsigned char ataWriteSectors(  unsigned char Drive, 
00174                                 unsigned long lba,
00175                                 unsigned int numsectors,
00176                                 unsigned char *Buffer);
00177 
00178 //unsigned char IdentifyDrive(unsigned char DriveNo,  unsigned char *Buffer, tdefDriveInfo *DriveInfo);
00179 //unsigned char SetMode(unsigned char DriveNo, unsigned char Mode, unsigned char PwrDown);
00180 //unsigned char ATA_Idle(unsigned char Drive);
00181 
00182 #endif

Generated on Sun Feb 22 19:12:30 2004 for Procyon AVRlib by doxygen1.3-rc2