Main Page   Data Structures   File List   Data Fields   Globals  

ata_if.h

Go to the documentation of this file.
00001 /*! \file ata_if.h \brief IDE-ATA hard disk interface driver. */
00002 //*****************************************************************************
00003 //
00004 // File Name    : 'ata_if.c'
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_IF_H
00024 #define ATA_IF_H
00025 
00026 #include "global.h"
00027 #include "ata_ifconf.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 error 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
00081 #define ATA_CMD_SPINUP          0xE1
00082 
00083 // ATA CHS disk parameters (examples, now we autodetect)
00084 #define ATA_DISKPARM_CLYS       0x03A6
00085 #define ATA_DISKPARM_HEADS      0x10
00086 #define ATA_DISKPARM_SECTORS    0x11
00087 
00088 // ATA Identity fields
00089 // all offsets refer to word offset (2 byte increments)
00090 #define ATA_IDENT_DEVICETYPE    0       // specifies ATA/ATAPI, removable/non-removable
00091 #define ATA_IDENT_CYLINDERS     1       // number of logical cylinders
00092 #define ATA_IDENT_HEADS         3       // number of logical heads
00093 #define ATA_IDENT_SECTORS       6       // number of sectors per track
00094 #define ATA_IDENT_SERIAL        10      // drive model name (20 characters)
00095 #define ATA_IDENT_MODEL         27      // drive model name (40 characters)
00096 #define ATA_IDENT_FIELDVALID    53      // indicates field validity of higher words (bit0: words54-58, bit1: words 64-70)
00097 #define ATA_IDENT_LBASECTORS    60      // number of sectors in LBA translation mode
00098 
00099 
00100 // typedefs
00101 // drive info structure
00102 typedef struct 
00103 {
00104     unsigned int  cylinders;
00105     unsigned char heads;
00106     unsigned char sectors;
00107     unsigned long sizeinsectors;
00108     unsigned char LBAsupport;
00109     char model[41];
00110 } typeDriveInfo;
00111 
00112 
00113 // Prototypes
00114 void ataInit(void);
00115 void ataDriveInit(void);
00116 void ataDriveSelect(u08 DriveNo);
00117 u08  ataReadByte(u08 reg);
00118 void ataWriteByte(u08 reg, u08 data);
00119 void ataShowRegisters(unsigned char DriveNo);
00120 u08  ataSWReset(void);
00121 void ataDiskErr(void);
00122 void ataPrintSector( u08 *Buffer);
00123 void ataReadDataBuffer(u08 *Buffer, u16 numBytes);
00124 void ataWriteDataBuffer(u08 *Buffer, u16 numBytes);
00125 u08 ataStatusWait(u08 mask, u08 waitStatus);
00126 
00127 // read and write routines for CHS based drives
00128 unsigned char ataReadSectorsCHS(    unsigned char Drive, 
00129                                     unsigned char Head, 
00130                                     unsigned int Track,
00131                                     unsigned char Sector,
00132                                     unsigned int numsectors,
00133                                     unsigned char *Buffer);
00134 
00135 unsigned char ataWriteSectorsCHS(   unsigned char Drive, 
00136                                     unsigned char Head, 
00137                                     unsigned int Track,
00138                                     unsigned char Sector,
00139                                     unsigned int numsectors,
00140                                     unsigned char *Buffer);
00141 
00142 // read and write routines for LBA based drives
00143 unsigned char ataReadSectorsLBA(    unsigned char Drive, 
00144                                     unsigned long lba,
00145                                     unsigned int numsectors,
00146                                     unsigned char *Buffer);
00147 
00148 unsigned char ataWriteSectorsLBA(   unsigned char Drive, 
00149                                     unsigned long lba,
00150                                     unsigned int numsectors,
00151                                     unsigned char *Buffer);
00152 
00153 // generic read and write routines using LBA
00154 //   uses native or translated LBA addressing
00155 //   given autodetected drive type
00156 unsigned char ataReadSectors(   unsigned char Drive, 
00157                                 unsigned long lba,
00158                                 unsigned int numsectors,
00159                                 unsigned char *Buffer);
00160 
00161 unsigned char ataWriteSectors(  unsigned char Drive, 
00162                                 unsigned long lba,
00163                                 unsigned int numsectors,
00164                                 unsigned char *Buffer);
00165 
00166 //unsigned char IdentifyDrive(unsigned char DriveNo,  unsigned char *Buffer, tdefDriveInfo *DriveInfo);
00167 //unsigned char SetMode(unsigned char DriveNo, unsigned char Mode, unsigned char PwrDown);
00168 //unsigned char ATA_Idle(unsigned char Drive);
00169 
00170 #endif

Generated on Tue Feb 4 20:18:36 2003 for Procyon AVRlib by doxygen1.3-rc2