00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00030 #define DRIVE0 0
00031
00032 #define STANDBY 0
00033 #define SLEEP 1
00034 #define IDLE 2
00035
00036
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
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
00056 #define ATA_HEAD_USE_LBA 0x40
00057
00058
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
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
00084 #define ATA_DISKPARM_CLYS 0x03A6
00085 #define ATA_DISKPARM_HEADS 0x10
00086 #define ATA_DISKPARM_SECTORS 0x11
00087
00088
00089
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
00101
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
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
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
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
00154
00155
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
00167
00168
00169
00170 #endif