- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

ata.h

    00001 /*
    00002 *  Copyright 2004 by Texas Instruments Incorporated.
    00003 *  All rights reserved. Property of Texas Instruments Incorporated.
    00004 *  Restricted rights to use, duplicate or disclose this code are
    00005 *  granted through contract.
    00006 *
    00007 */
    00008 /********************************************************************************/
    00009 /* $Id: ata.h,2.4+ $                                                            */
    00010 /*                                                                              */
    00011 /* This is proprietary information, not to be published -- TI INTERNAL DATA     */
    00012 /* Copyright (C) 2000, Texas Instruments, Inc.  All Rights Reserved.            */
    00013 /*                                                                              */
    00014 /* Author: Susmit Pal                                                           */
    00015 /* Date: November 6, 2002                                                       */
    00016 /* Modified Date: November 28, 2002                                             */
    00017 /* Last Modified Date: February 11, 2003                                        */
    00018 /* Mar 21, 2010 - added AtaReadNextWord1 routine to AtaState  KR032110          */
    00019 /* Apr 26, 2010 - added NULL definition                       KR042610          */
    00020 /********************************************************************************/
    00021 /*SUSMIT - ATA-FS2.4+ Customized */
    00022
    00023
    00024 #ifndef _ata_h
    00025 #define _ata_h 1
    00026
    00027 #include <tistdtypes.h>
    00028
    00029 #define ATA_MAX_LONG_NAME_SIZE    261
    00030 #define ATA_MEDIA_ID_WORDS        16
    00031
    00032 #define ATA_ATTR_READ_ONLY        0x01
    00033 #define ATA_ATTR_HIDDEN           0x02
    00034 #define ATA_ATTR_SYSTEM           0x04
    00035 #define ATA_ATTR_VOLUME           0x08
    00036 #define ATA_ATTR_DIRECTORY        0x10
    00037 #define ATA_ATTR_ARCHIVE          0x20
    00038
    00039 #define ATA_ERROR_NONE            0x0000
    00040 #define ATA_ERROR_UNSUPPORTED     0x0001
    00041 #define ATA_ERROR_NESTED          0x0002
    00042 #define ATA_ERROR_TIMEOUT         0x0004
    00043 #define ATA_ERROR_BAD_MEDIA       0x0008
    00044 #define ATA_ERROR_EOF             0x0010
    00045 #define ATA_ERROR_FILE_NOT_FOUND  0x0020
    00046 #define ATA_ERROR_ID_NOT_FOUND    0x0040
    00047 #define ATA_ERROR_MEDIA_NOT_FOUND 0x0080
    00048 #define ATA_ERROR_MEDIA_REMOVED   0x0100
    00049 #define ATA_ERROR_DISK_FULL       0x0200
    00050
    00051 /* Added for checking invalid parameters: PR Mistral */
    00052 #define ATA_ERROR_INVALID_PARAM   0x0300
    00053 #define ATA_ERROR_INVALID_MODE    0x0301
    00054
    00055 /*ADD NEW MEDIA ID HERE*/
    00056 #define MMC     1
    00057 #define SD      2
    00058 #define NAND    3
    00059 #define CF      4
    00060 #define IDE     5
    00061 #define MEMSTICK 6 /* Renamed from MS, as it clashes with RTC's MilliSecond Reg.*/
    00062
    00063 // added for check null pointer KR042110
    00064 #ifndef NULL
    00065 #define NULL ((void*)0)
    00066 #endif
    00067
    00068 #if 0
    00069 typedef unsigned int  AtaUint16;
    00070 typedef unsigned long AtaUint32;
    00071 typedef AtaUint32    AtaSector;
    00072 typedef AtaUint32    AtaFileSize;
    00073 #endif
    00074
    00075 /*typedef changed by ra*/
    00076 typedef Uint16      AtaUint16;
    00077 typedef Uint32      AtaUint32;
    00078 typedef Uint32      AtaSector;
    00079 typedef Uint32      AtaFileSize;
    00080
    00081
    00082 #ifndef DISABLE_FAT32
    00083 typedef AtaUint32    AtaCluster;
    00084 typedef AtaUint32    AtaDirEntry;
    00085 #else
    00086 typedef AtaUint16    AtaCluster;
    00087 typedef AtaUint16    AtaDirEntry;
    00088 #endif
    00089 /*typedef int          AtaError;*//*SUSMIT - This should be unsigned int*/
    00090 typedef AtaUint16    AtaError;
    00091 typedef AtaUint16    AtaSerialID[ATA_MEDIA_ID_WORDS];
    00092
    00093 #define ATA_FAT_TYPE_12           0x01
    00094 #define ATA_FAT_TYPE_16           0x04         /* 16-bit FAT. Partitions smaller than 32MB */
    00095 #define ATA_FAT_TYPE_32           0x0B         /* 32-bit FAT. Partitions up to 2047GB */
    00096
    00097
    00098 typedef struct AtaStateStruct
    00099 {
    00100   AtaSector BootPhySector;
    00101   AtaUint16 FatType;
    00102   AtaUint16 WordsPerLogSector;
    00103   AtaUint16 LogSectorsPerCluster;
    00104   AtaUint16 RootDirEntries;
    00105   AtaUint32 LogSectorsPerFat;
    00106   AtaSector FirstFatSector;
    00107   AtaSector RootDirSector;
    00108   AtaSector FirstDataSector;
    00109   AtaSector TotalSectors;
    00110   AtaUint16 Data;
    00111   AtaUint16 CurrentWord;
    00112   AtaSector CurrentPhySector;
    00113   AtaUint16 WordsPerCluster;
    00114   AtaUint16 NumberOfFats;
    00115   AtaUint16 MFWFlag;
    00116   AtaError  Err_Status;
    00117 #ifdef ATA_HDD
    00118 /*SUSMIT - Support for media which can support multi-block operations, user configurable*/
    00119   AtaUint16 Multi_block_Flag;
    00120 /*SUSMIT - Support for media which can support multi-block operations, user configurable*/
    00121 #endif /* ATA_HDD */
    00122   void    *pAtaMediaState;
    00123   AtaError  (*AtaReset)(void *pAtaMediaState);
    00124   int      (*AtaCommandReadyStatusCheck)(void *pAtaMediaState);
    00125   AtaError  (*AtaBusyStatusCheck)(void *pAtaMediaState);
    00126   AtaUint16 (*AtaGetSerialID)(void *pAtaMediaState, AtaSerialID *pID);
    00127   AtaError  (*AtaIssueReadCommand)(AtaSector PhySector, void *pAtaMediaState, AtaUint16 SectorCount);
    00128   AtaError  (*AtaDataReadyStatusCheck)(void *pAtaMediaState);
    00129   AtaError  (*AtaReadNextWord)(void *pAtaMediaState, AtaUint16 *pWord);
    00130
    00131   AtaError  (*AtaReadNextWord1)(void *pAtaMediaState, AtaUint16 *pWord,AtaUint16 word_delta); //KR032110
    00132
    00133   AtaError  (*AtaReadNextNWords)(void *pAtaMediaState, AtaUint16 *pWord, AtaUint16 Count);
    00134   AtaError  (*AtaWriteSector)(AtaSector PhySector, void *pAtaMediaState, AtaUint16 *pWord, int ByteSwap);
    00135   AtaError  (*AtaWriteSectorFlush)(void *pAtaMediaState);
    00136   AtaError  (*AtaInitAtaMediaState)(void *pAtaState1);
    00137   AtaError   (*AtaFlushFat)(void *pAtaMediaState);
    00138   void    (*AtaErrorCallback)(unsigned short Error);
    00139 /*SUSMIT - Support for media which has floppy like filesystem with only a bootsector but no MBR*/
    00140   AtaUint16 (*AtaFileSystemType)(void *pAtaMediaState);
    00141 /*SUSMIT - Support for media which has floppy like filesystem with only a bootsector but no MBR*/
    00142 #ifdef ATA_HDD
    00143 /*SUSMIT - Support for media which can support multi-block operations, user configurable*/
    00144   AtaError  (*AtaReadSectorB)(AtaSector PhySector, void *pAtaMediaState, AtaUint16 *pWord, AtaUint16 ByteSwap);
    00145   AtaError  (*AtaWriteSectorB)(AtaSector PhySector, void *pAtaMediaState, AtaUint16 *pWord, AtaUint16 ByteSwap);
    00146   AtaError  (*AtaWriteFlushB)(void *pAtaMediaState);
    00147   AtaUint16 (*AtaReadWordB)(AtaSector PhySector, void *pAtaMediaState, AtaUint16 ByteOffset);
    00148 /*SUSMIT - Support for media which can support multi-block operations, user configurable*/
    00149 #endif /* ATA_HDD */
    00150   /*-----------------2002-08-20 1:02PM----------------
    00151    * The following globals should be referenced
    00152    * through the state structure
    00153    * Also, it should be noted which functions use these
    00154    * so that they can be sure to be initialized before
    00155    * those functions are called.
    00156    * These will anyway be initilized before ATA_systemInit
    00157    * --------------------------------------------------*/
    00158   AtaUint16 (*get_mod_time)();
    00159   AtaUint16 (*get_mod_date)();
    00160   AtaUint16 (*get_time)();
    00161   AtaUint16 (*get_date)();
    00162   AtaUint16 *_AtaWriteBuffer;
    00163   AtaSector _AtaWriteCurrentPhySector;
    00164 } AtaState;
    00165
    00166 /* File Descriptor */
    00167 typedef struct AtaFileStruct
    00168 {
    00169   char Filename[9];            /* unpacked characters for filename (00XX, where XX is the ASCII character */
    00170                                   /* null terminated (last character is 0000) */
    00171   char Ext[4];                  /* unpacked characters for extension (00XX, where XX is the ASCII character */
    00172                                   /* null terminated (last character is 0000) */
    00173   AtaUint16 Attributes;     /* file attribute byte in LSB */
    00174   AtaUint16 Time;             /* time record from FDB */
    00175   AtaUint16 Date;             /* date record from FDB */
    00176   AtaUint16 reserved1;       /* was unsigned int ByteSwap; byte swap mode for AtaRead and AtaWrite */
    00177   AtaCluster   StartCluster;      /* starting cluster number */
    00178   AtaFileSize  Size;              /* current file size in bytes */
    00179   AtaCluster   Cluster;        /* current cluster number (initialized to StartCluster) */
    00180   AtaUint16 WordInCluster;   /* current byte offset from start of cluster (initialized to 0) */
    00181   AtaCluster   NextBrokenCluster; /* next cluster where fragment occurs (for Read and Write) */
    00182   AtaCluster   PrevBrokenCluster; /* first cluster where contiguous cluster chain started (used for Write) */
    00183   AtaSector CurrentDirSector;  /* sector of start of current directory entries  (only used for root dir)*/
    00184   AtaDirEntry  CurrentDirEntry;   /* entry number in current directory */
    00185   AtaDirEntry CurrentDirSectorTag; /* number of clusters from start of dir of CurrentDirSector */
    00186   AtaCluster StartDirCluster;   /* directory starting cluster number */
    00187 /*  AtaCluster   CurrentDirCluster;*/ /* cluster where current directory is located */
    00188  /*SUSMIT_ DIRECTORY BRWOSING BUGFIX*/
    00189   AtaFileSize  CurrentByte;    /* current byte in the file */
    00190   AtaState   *pDrive;          /* pointer to drive state structure */
    00191 } AtaFile;
    00192
    00193
    00194 /*-----------------2002-08-20 4:14PM----------------
    00195  * These file names are no longer valid.  I created
    00196  * several new files to aide with the vector.
    00197  * --------------------------------------------------*/
    00198 /* -----------------5/16/2000 4:18PM-----------------
    00199 Ata.c (included in ldknl)
    00200  --------------------------------------------------*/
    00201 /* SUSMIT - 25 FEB 2003 */
    00202 /*AtaError ATA_systemInit(AtaState *pAtaDrive);*/
    00203 AtaError ATA_systemInit(AtaState *pAtaDrive, AtaUint16 disk_type);
    00204 /* SUSMIT - 25 FEB 2003 */
    00205 AtaUint16 ATA_getSerialID(AtaState *pAtaDrive, AtaSerialID *pID);
    00206
    00207 /* -----------------5/16/2000 4:19PM-----------------
    00208 AtaRead.c (included in ldknl)
    00209  --------------------------------------------------*/
    00210 AtaError ATA_read(AtaFile *pAtaFile, AtaUint16 *Data, AtaUint16 Words);
    00211 AtaError ATA_readLittleEndian(AtaFile *pAtaFile, AtaUint16 *Data, AtaUint16 Words);
    00212 /*SUSMIT - Absolute Seek*/
    00213 AtaError ATA_seek(AtaFile *pAtaFile, AtaFileSize OffsetFromStart);
    00214 /*SUSMIT - Relative Seek*/
    00215 AtaError ATA_seek_relative(AtaFile *pAtaFile, long OffsetFromCurrent);
    00216 AtaError ATA_sleep(AtaState *pAtaDrive);
    00217
    00218 /* -----------------5/16/2000 4:19PM-----------------
    00219 AtaDir.c
    00220  --------------------------------------------------*/
    00221 AtaError ATA_fileInit(AtaState *pAtaDrive, AtaFile *pAtaFile);
    00222 AtaError ATA_cdRoot(AtaFile *pAtaFile);
    00223 AtaError ATA_cd(AtaFile *pAtaFile);
    00224 AtaError ATA_findFirst(AtaFile *pAtaFile);
    00225 AtaError ATA_findNext(AtaFile *pAtaFile);
    00226 int ATA_isDir(AtaFile *pAtaFile);
    00227 void     ATA_errorCallback(unsigned short Error);
    00228
    00229 /* -----------------5/16/2000 4:19PM-----------------
    00230 AtaLong.c
    00231  --------------------------------------------------*/
    00232 AtaError ATA_getLongName(AtaFile *pAtaFile, char *LongName, AtaUint16 StartOffset, AtaUint16 Length);
    00233
    00234 /* -----------------5/16/2000 4:19PM-----------------
    00235 AtaTell.c
    00236  --------------------------------------------------*/
    00237 AtaError ATA_tell(AtaFile *pAtaFile, AtaFileSize *pOffsetInFile);
    00238
    00239 /* -----------------5/16/2000 4:20PM-----------------
    00240 AtaWrite.c
    00241  --------------------------------------------------*/
    00242 AtaError ATA_create(AtaFile *pAtaFile);
    00243 AtaError ATA_createDirectory(AtaFile *pAtaFile);
    00244 AtaError ATA_delete(AtaFile *pAtaFile);
    00245 AtaError ATA_rename(AtaFile *pAtaFile);
    00246 AtaError ATA_write(AtaFile *pAtaFile, AtaUint16 *Data, AtaUint16 Words);
    00247 AtaError ATA_close(AtaFile *pAtaFile);
    00248
    00249 /* -----------------07/27/2000 10:53PM---------------
    00250 AtaFormat.c (Does exist now! - Susmit)
    00251  --------------------------------------------------*/
    00252 AtaError ATA_format(AtaState *pDrive, int flag);
    00253
    00254 /*SUSMIT_UPDATE
    00255 Adding some more user level APIs.
    00256 Added in AtaDir.c*/
    00257 AtaError ATA_setFileName(AtaFile *pAtaFile, char *name, char *ext);
    00258 AtaError ATA_setDirectoryName(AtaFile *pAtaFile, char *dirname);
    00259 /*Added in AtaDisk.c*/
    00260 AtaUint32 ATA_diskSize(AtaState *pAtaState, AtaError *ret_stat);
    00261 AtaUint32 ATA_diskUsed(AtaState *pAtaState, AtaError *ret_stat);
    00262 AtaUint32 ATA_diskFree(AtaState *pAtaState, AtaError *ret_stat);
    00263
    00264 /*SUSMIT - new requirements*/
    00265 AtaError ATA_setDateTime(AtaFile *pAtaFile);
    00266 AtaError ATA_setAttr(AtaFile *pAtaFile, AtaUint16 Attr);
    00267 AtaError ATA_vol(AtaState *pAtaDrive, char *volname);
    00268 AtaError ATA_label(AtaState *pAtaDrive, char *volname);
    00269 AtaError ATA_setLongFileName( AtaFile *pAtaFile, char *LongName );
    00270 AtaError ATA_createLong(AtaFile *pAtaFile, char *longname);
    00271 AtaError ATA_deleteLong(AtaFile *pAtaFile);
    00272 AtaError ATA_renameLong(AtaFile *pAtaFile, char *longnamenew);
    00273 AtaError ATA_setLongDirectoryName( AtaFile *pAtaFile, char *LongName );
    00274 AtaError ATA_createDirectoryLong(AtaFile *pAtaFile, char *longname);
    00275 /*SUSMIT - new requirements*/
    00276 /*SUSMIT - USB_MSC Requirements*/
    00277 AtaError ATA_readSector(AtaSector PhySector, AtaState* pAtaState, AtaUint16 *Word, int ByteSwap);
    00278 AtaError ATA_writeSector(AtaSector PhySector, AtaState* pAtaState, AtaUint16 *Word, int ByteSwap);
    00279 /*SUSMIT - USB_MSC Requirements*/
    00280 /*SUSMIT - Configurable MFW Requirements*/
    00281 void ATA_enableMFW(AtaState *pAtaState);
    00282 #ifdef ATA_HDD
    00283 void ATA_enableMultiBlock(AtaState *pAtaState);
    00284 #endif /* ATA_HDD */
    00285 /*SUSMIT - Configurable MFW Requirements*/
    00286 /*SUSMIT - Byte Level File Handling Requirements*/
    00287 AtaError ATA_read_b(AtaFile *pAtaFile, AtaUint16 *Data, AtaUint16 bytes);
    00288 AtaError ATA_seek_b(AtaFile *pAtaFile, AtaUint32 ByteOffsetFromStart);
    00289 AtaError ATA_write_b(AtaFile *pAtaFile, AtaUint16 *Data, AtaUint16 bytes);
    00290 AtaError ATA_tell_b(AtaFile *pAtaFile, AtaFileSize *pByteOffsetInFile);
    00291 /*SUSMIT - Byte Level File Handling Requirements*/
    00292 #endif
    00293